List of usage examples for org.apache.http.protocol HTTP TRANSFER_ENCODING
String TRANSFER_ENCODING
To view the source code for org.apache.http.protocol HTTP TRANSFER_ENCODING.
Click Source Link
From source file:org.apache.synapse.transport.passthru.util.DeferredMessageBuilder.java
public OMElement getDocument(MessageContext msgCtx, InputStream in) throws XMLStreamException, IOException { String contentType = (String) msgCtx.getProperty(Constants.Configuration.CONTENT_TYPE); String _contentType = getContentType(contentType, msgCtx); in = HTTPTransportUtils.handleGZip(msgCtx, in); AxisConfiguration configuration = msgCtx.getConfigurationContext().getAxisConfiguration(); Parameter useFallbackParameter = configuration .getParameter(Constants.Configuration.USE_DEFAULT_FALLBACK_BUILDER); boolean useFallbackBuilder = false; if (useFallbackParameter != null) { useFallbackBuilder = JavaUtils.isTrueExplicitly(useFallbackParameter.getValue(), useFallbackBuilder); }//from w w w .ja v a 2 s . c o m Map transportHeaders = (Map) msgCtx.getProperty(MessageContext.TRANSPORT_HEADERS); if (transportHeaders != null) { String contentLength = (String) transportHeaders.get(HTTP.CONTENT_LEN); String trasferEncoded = (String) transportHeaders.get(HTTP.TRANSFER_ENCODING); if (contentType.equals(PassThroughConstants.DEFAULT_CONTENT_TYPE) && (contentLength == null || Integer.valueOf(contentLength) == 0) && trasferEncoded == null) { msgCtx.setProperty(PassThroughConstants.NO_ENTITY_BODY, true); msgCtx.setProperty(Constants.Configuration.CONTENT_TYPE, ""); msgCtx.setProperty(PassThroughConstants.RELAY_EARLY_BUILD, true); return new SOAP11Factory().getDefaultEnvelope(); } } OMElement element = null; Builder builder; if (contentType != null) { // loading builder from externally.. //builder = configuration.getMessageBuilder(_contentType,useFallbackBuilder); builder = MessageProcessorSelector.getMessageBuilder(_contentType, msgCtx); if (builder != null) { try { /*try { throw new Exception("Building message"); } catch (Exception e) { e.printStackTrace(); }*/ element = builder.processDocument(in, contentType, msgCtx); } catch (AxisFault axisFault) { log.error("Error building message", axisFault); throw axisFault; } } } if (element == null) { if (msgCtx.isDoingREST()) { try { element = BuilderUtil.getPOXBuilder(in, null).getDocumentElement(); } catch (XMLStreamException e) { log.error("Error building message using POX Builder", e); throw e; } } else { // switch to default builder = new SOAPBuilder(); try { element = builder.processDocument(in, contentType, msgCtx); } catch (AxisFault axisFault) { log.error("Error building message using SOAP builder"); throw axisFault; } } } // build the soap headers and body if (element instanceof SOAPEnvelope) { SOAPEnvelope env = (SOAPEnvelope) element; env.hasFault(); } //setting up original contentType (resetting the content type) if (contentType != null && !contentType.isEmpty()) { msgCtx.setProperty(Constants.Configuration.CONTENT_TYPE, contentType); } return element; }
From source file:org.apache.synapse.transport.passthru.util.PassThroughTransportUtils.java
/** * Remove unwanted headers from the given header map. * * @param headers http header map * @param targetConfiguration configurations for the passThrough transporter *//*from ww w .j a v a 2 s .com*/ private static void removeUnwantedHeadersFromHeaderMap(Map headers, TargetConfiguration targetConfiguration) { Iterator iter = headers.keySet().iterator(); while (iter.hasNext()) { String headerName = (String) iter.next(); if (HTTP.CONN_DIRECTIVE.equalsIgnoreCase(headerName) || HTTP.TRANSFER_ENCODING.equalsIgnoreCase(headerName)) { iter.remove(); } if (HTTP.CONN_KEEP_ALIVE.equalsIgnoreCase(headerName) && !targetConfiguration.isPreserveHttpHeader(HTTP.CONN_KEEP_ALIVE)) { iter.remove(); } if (HTTP.CONTENT_LEN.equalsIgnoreCase(headerName) && !targetConfiguration.isPreserveHttpHeader(HTTP.CONTENT_LEN)) { iter.remove(); } if (HTTP.CONTENT_TYPE.equalsIgnoreCase(headerName) && !targetConfiguration.isPreserveHttpHeader(HTTP.CONTENT_TYPE)) { iter.remove(); } if (HTTP.DATE_HEADER.equalsIgnoreCase(headerName) && !targetConfiguration.isPreserveHttpHeader(HTTP.DATE_HEADER)) { iter.remove(); } if (HTTP.SERVER_HEADER.equalsIgnoreCase(headerName) && !targetConfiguration.isPreserveHttpHeader(HTTP.SERVER_HEADER)) { iter.remove(); } if (HTTP.USER_AGENT.equalsIgnoreCase(headerName) && !targetConfiguration.isPreserveHttpHeader(HTTP.USER_AGENT)) { iter.remove(); } } }
From source file:org.apache.synapse.transport.passthru.util.SourceResponseFactory.java
public static SourceResponse create(MessageContext msgContext, SourceRequest sourceRequest, SourceConfiguration sourceConfiguration) { // determine the status code to be sent int statusCode = PassThroughTransportUtils.determineHttpStatusCode(msgContext); SourceResponse sourceResponse;// w w w. j av a 2 s .com String statusLine = PassThroughTransportUtils.determineHttpStatusLine(msgContext); if (msgContext.getProperty(PassThroughConstants.ORIGINAL_HTTP_SC) != null && statusCode == ((Integer) msgContext.getProperty(PassThroughConstants.ORIGINAL_HTTP_SC))) { sourceResponse = new SourceResponse(sourceConfiguration, statusCode, statusLine, sourceRequest); } else { if (msgContext.getProperty(PassThroughConstants.ORIGINAL_HTTP_REASON_PHRASE) != null && (statusLine .equals(msgContext.getProperty(PassThroughConstants.ORIGINAL_HTTP_REASON_PHRASE)))) { sourceResponse = new SourceResponse(sourceConfiguration, statusCode, sourceRequest); } else { sourceResponse = new SourceResponse(sourceConfiguration, statusCode, statusLine, sourceRequest); } } // set any transport headers Map transportHeaders = (Map) msgContext.getProperty(MessageContext.TRANSPORT_HEADERS); boolean forceContentLength = msgContext.isPropertyTrue(NhttpConstants.FORCE_HTTP_CONTENT_LENGTH); boolean forceContentLengthCopy = msgContext .isPropertyTrue(PassThroughConstants.COPY_CONTENT_LENGTH_FROM_INCOMING); if (forceContentLength && forceContentLengthCopy && msgContext.getProperty(PassThroughConstants.ORGINAL_CONTEN_LENGTH) != null) { sourceResponse.addHeader(HTTP.CONTENT_LEN, (String) msgContext.getProperty(PassThroughConstants.ORGINAL_CONTEN_LENGTH)); } // When invoking http HEAD request esb set content length as 0 to response header. Since there is no message // body content length cannot be calculated inside synapse. Hence content length of the backend response is // set to sourceResponse. if (sourceRequest != null && PassThroughConstants.HTTP_HEAD .equalsIgnoreCase(sourceRequest.getRequest().getRequestLine().getMethod()) && msgContext.getProperty(PassThroughConstants.ORGINAL_CONTEN_LENGTH) != null) { sourceResponse.addHeader(PassThroughConstants.ORGINAL_CONTEN_LENGTH, (String) msgContext.getProperty(PassThroughConstants.ORGINAL_CONTEN_LENGTH)); } if (transportHeaders != null && msgContext.getProperty(org.apache.axis2.Constants.Configuration.MESSAGE_TYPE) != null) { if (msgContext.getProperty(org.apache.axis2.Constants.Configuration.CONTENT_TYPE) != null && msgContext.getProperty(org.apache.axis2.Constants.Configuration.CONTENT_TYPE).toString() .contains(PassThroughConstants.CONTENT_TYPE_MULTIPART_RELATED)) { transportHeaders.put(org.apache.axis2.Constants.Configuration.MESSAGE_TYPE, PassThroughConstants.CONTENT_TYPE_MULTIPART_RELATED); } else { Pipe pipe = (Pipe) msgContext.getProperty(PassThroughConstants.PASS_THROUGH_PIPE); if (pipe != null && !Boolean.TRUE .equals(msgContext.getProperty(PassThroughConstants.MESSAGE_BUILDER_INVOKED))) { transportHeaders.put(HTTP.CONTENT_TYPE, msgContext.getProperty(org.apache.axis2.Constants.Configuration.CONTENT_TYPE)); } } } if (transportHeaders != null) { addResponseHeader(sourceResponse, transportHeaders); } else { Boolean noEntityBody = (Boolean) msgContext.getProperty(NhttpConstants.NO_ENTITY_BODY); if (noEntityBody == null || Boolean.FALSE == noEntityBody) { OMOutputFormat format = NhttpUtil.getOMOutputFormat(msgContext); transportHeaders = new HashMap(); MessageFormatter messageFormatter = MessageFormatterDecoratorFactory .createMessageFormatterDecorator(msgContext); if (msgContext.getProperty(org.apache.axis2.Constants.Configuration.MESSAGE_TYPE) == null) { transportHeaders.put(HTTP.CONTENT_TYPE, messageFormatter.getContentType(msgContext, format, msgContext.getSoapAction())); } addResponseHeader(sourceResponse, transportHeaders); } } // Add excess response header. String excessProp = NhttpConstants.EXCESS_TRANSPORT_HEADERS; Map excessHeaders = (Map) msgContext.getProperty(excessProp); if (excessHeaders != null) { for (Iterator iterator = excessHeaders.keySet().iterator(); iterator.hasNext();) { String key = (String) iterator.next(); for (String excessVal : (Collection<String>) excessHeaders.get(key)) { sourceResponse.addHeader(key, (String) excessVal); } } } // keep alive String noKeepAlie = (String) msgContext.getProperty(PassThroughConstants.NO_KEEPALIVE); if ("true".equals(noKeepAlie)) { sourceResponse.setKeepAlive(false); } else { // If the payload is delayed for GET/HEAD/DELETE, http-core-nio will start processing request, without // waiting for the payload. Therefore the delayed payload will be appended to the next request. To avoid // that, disable keep-alive to avoid re-using the existing connection by client for the next request. if (sourceRequest != null) { String requestMethod = sourceRequest.getRequest().getRequestLine().getMethod(); if (requestMethod != null && isPayloadOptionalMethod(requestMethod.toUpperCase()) && (sourceRequest.getHeaders().containsKey(HTTP.CONTENT_LEN) || sourceRequest.getHeaders().containsKey(HTTP.TRANSFER_ENCODING))) { if (log.isDebugEnabled()) { log.debug("Disable keep-alive in the client connection : Content-length/Transfer-encoding" + " headers present for GET/HEAD/DELETE request"); } sourceResponse.setKeepAlive(false); } } } return sourceResponse; }