public void start()

in modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/TargetRequest.java [120:250]


    public void start(NHttpClientConnection conn) throws IOException, HttpException {
        if (pipe != null) {
            TargetContext.get(conn).setWriter(pipe);
        }

        String path = fullUrl ? url.toString() :
                ("".equals(url.getPath()) ? "/" : url.getPath()) +
                    (url.getQuery() != null ? "?" + url.getQuery() : "");

        long contentLength = -1;
        String contentLengthHeader = null;
        
		if (headers.get(HTTP.CONTENT_LEN) != null && headers.get(HTTP.CONTENT_LEN).size() > 0) {
			contentLengthHeader = headers.get(HTTP.CONTENT_LEN).first();
		}

		if (contentLengthHeader != null) {
			contentLength = Integer.parseInt(contentLengthHeader);
			headers.remove(HTTP.CONTENT_LEN);
		}
  
        
        MessageContext requestMsgCtx = TargetContext.get(conn).getRequestMsgCtx();
        Long lengthValue = (Long) requestMsgCtx.getProperty(
                PassThroughConstants.PASS_THROUGH_MESSAGE_LENGTH);
        if (lengthValue != null){
        	contentLength = lengthValue;
        }

        //fix for  POST_TO_URI
        if (requestMsgCtx.isPropertyTrue(NhttpConstants.POST_TO_URI)){
        	path = url.toString();
        }

        Object o = requestMsgCtx.getProperty(MessageContext.TRANSPORT_HEADERS);
        if (o != null && o instanceof Map) {
            Map _headers = (Map) o;
            String trpContentType = (String) _headers.get(HTTP.CONTENT_TYPE);
            if (trpContentType != null && !trpContentType.equals("")) {
                if (trpContentType.contains(PassThroughConstants.CONTENT_TYPE_MULTIPART_RELATED) &&
                    !requestMsgCtx.isPropertyTrue(PassThroughConstants.MESSAGE_BUILDER_INVOKED)) {
                    // If the message is multipart/related but it hasn't been built
                    // we can copy the content-type header of the request
                	addHeader(HTTP.CONTENT_TYPE, trpContentType);
                }
            }
        }
                                                            
        if (hasEntityBody) {
            request = new BasicHttpEntityEnclosingRequest(method, path,
                    version != null ? version : HttpVersion.HTTP_1_1);

            BasicHttpEntity entity = new BasicHttpEntity();

            if (requestMsgCtx.isPropertyTrue(NhttpConstants.FORCE_HTTP_CONTENT_LENGTH)) {
                entity.setChunked(false);
                if (requestMsgCtx.isPropertyTrue(PassThroughConstants.COPY_CONTENT_LENGTH_FROM_INCOMING)
                        && contentLength > 0) {
                    entity.setContentLength(contentLength);
                }
            } else {
                if (contentLength != -1) {
                    entity.setChunked(false);
                    entity.setContentLength(contentLength);
                } else {
                    entity.setChunked(chunk);
                }
            }
            ((BasicHttpEntityEnclosingRequest) request).setEntity(entity);
           
        } else {
            request = new BasicHttpRequest(method, path,
                    version != null ? version : HttpVersion.HTTP_1_1);
        }

        
		Set<Map.Entry<String, TreeSet<String>>> entries = headers.entrySet();
		for (Map.Entry<String, TreeSet<String>> entry : entries) {
			if (entry.getKey() != null) {
				Iterator<String> i = entry.getValue().iterator();
				while (i.hasNext()) {
					request.addHeader(entry.getKey(), i.next());
				}
			}
		}
        
        //setup wsa action..
        if (request != null){
        	
    		String soapAction = requestMsgCtx.getSoapAction();
            if (soapAction == null) {
                soapAction = requestMsgCtx.getWSAAction();
            }
            if (soapAction == null) {
            	requestMsgCtx.getAxisOperation().getInputAction();
            }

            if (requestMsgCtx.isSOAP11() && soapAction != null && soapAction.length() > 0) {
                Header existingHeader = request.getFirstHeader(HTTPConstants.HEADER_SOAP_ACTION);
                if (existingHeader != null) {
                	request.removeHeader(existingHeader);
                }
                MessageFormatter messageFormatter =
                    MessageFormatterDecoratorFactory.createMessageFormatterDecorator(requestMsgCtx);
                request.setHeader(HTTPConstants.HEADER_SOAP_ACTION,
                        messageFormatter.formatSOAPAction(requestMsgCtx, null, soapAction));
            }
    	}

        this.processChunking(conn, requestMsgCtx);

        if (!keepAlive) {
            request.setHeader(HTTP.CONN_DIRECTIVE, HTTP.CONN_CLOSE);
        }

        // Pre-process HTTP request
        HttpContext context = conn.getContext();
        context.setAttribute(HttpCoreContext.HTTP_CONNECTION, conn);
        context.setAttribute(HttpCoreContext.HTTP_TARGET_HOST, new HttpHost(url.getHost(), port));
        context.setAttribute(HttpCoreContext.HTTP_REQUEST, request);

        // start the request
        targetConfiguration.getHttpProcessor().process(request, context);
        conn.submitRequest(request);

        if (hasEntityBody) {
            TargetContext.updateState(conn, ProtocolState.REQUEST_HEAD);
        } else {
            TargetContext.updateState(conn, ProtocolState.REQUEST_DONE);
        }
    }