protected AhcWebSocketWrappedOutputStream( Message message, boolean possibleRetransmit, boolean isChunking, int chunkThreshold, String conduitName, URI url) { super(message, possibleRetransmit, isChunking, chunkThreshold, conduitName, url); entity = message.get(AhcWebSocketConduitRequest.class); // REVISIT how we prepare the request String requri = (String) message.getContextualProperty("org.apache.cxf.request.uri"); if (requri != null) { // jaxrs speicfies a sub-path using prop org.apache.cxf.request.uri if (requri.startsWith("ws")) { entity.setPath(requri.substring(requri.indexOf('/', 3 + requri.indexOf(':')))); } else { entity.setPath(url.getPath() + requri); } } else { // jaxws entity.setPath(url.getPath()); } entity.setId(UUID.randomUUID().toString()); uncorrelatedRequests.put(entity.getId(), new RequestResponse(entity)); }
private EndpointReferenceType getReplyTo(Message message, EndpointReferenceType originalReplyTo) { Exchange exchange = message.getExchange(); Endpoint info = exchange.getEndpoint(); if (info == null) { return originalReplyTo; } synchronized (info) { EndpointInfo ei = info.getEndpointInfo(); Destination dest = ei.getProperty(DECOUPLED_DESTINATION, Destination.class); if (dest == null) { dest = createDecoupledDestination(message); if (dest != null) { info.getEndpointInfo().setProperty(DECOUPLED_DESTINATION, dest); } } if (dest != null) { // if the decoupled endpoint context prop is set and the address is relative, return the // absolute url. final String replyTo = dest.getAddress().getAddress().getValue(); if (replyTo.startsWith("/")) { String debase = (String) message.getContextualProperty(WSAContextUtils.DECOUPLED_ENDPOINT_BASE_PROPERTY); if (debase != null) { return EndpointReferenceUtils.getEndpointReference(debase + replyTo); } } return dest.getAddress(); } } return originalReplyTo; }
protected void handle(Message message) throws SequenceFault, RMException { LOG.entering(getClass().getName(), "handleMessage"); // This message capturing mechanism will need to be changed at some point. // Until then, we keep this interceptor here and utilize the robust // option to avoid the unnecessary message capturing/caching. if (!MessageUtils.isTrue(message.getContextualProperty(Message.ROBUST_ONEWAY))) { InputStream is = message.getContent(InputStream.class); if (is != null) { CachedOutputStream saved = new CachedOutputStream(); try { IOUtils.copy(is, saved); saved.flush(); is.close(); saved.lockOutputStream(); LOG.fine("Capturing the original RM message"); RewindableInputStream ris = RewindableInputStream.makeRewindable(saved.getInputStream()); message.setContent(InputStream.class, ris); message.put(RMMessageConstants.SAVED_CONTENT, ris); } catch (Exception e) { throw new Fault(e); } } } }
private Destination createDecoupledDestination(Message message) { String replyToAddress = (String) message.getContextualProperty(WSAContextUtils.REPLYTO_PROPERTY); if (replyToAddress != null) { return setUpDecoupledDestination(message.getExchange().getBus(), replyToAddress, message); } return null; }
public UriInfoImpl(Message m, MultivaluedMap<String, String> templateParams) { this.message = m; this.templateParams = templateParams; if (m != null) { this.stack = m.get(OperationResourceInfoStack.class); this.caseInsensitiveQueries = MessageUtils.isTrue(m.getContextualProperty(CASE_INSENSITIVE_QUERIES)); } }
public static final void disableMTOMResponse(WebServiceContext wsContext) { MessageContext msgCtx = wsContext.getMessageContext(); WrappedMessageContext wmc = (WrappedMessageContext) msgCtx; Exchange ex = wmc.getWrappedMessage().getExchange(); Message out = ex.getOutMessage(); if (out != null) { int i = 0; for (; MessageUtils.isTrue(out.getContextualProperty(Message.MTOM_ENABLED)) && i < 10; i++) { out.setContextualProperty(Message.MTOM_ENABLED, false); log.debug( "###### disableMTOM! enabled:{}", out.getContextualProperty(Message.MTOM_ENABLED)); } if (i > 1) log.warn( "###### disable MTOM needs " + i + " tries! enabled:{}", out.getContextualProperty(Message.MTOM_ENABLED)); } log.debug("###### MTOM enabled? {}:", out.getContextualProperty(Message.MTOM_ENABLED)); }
protected AhcWebSocketWrappedOutputStream( Message message, boolean possibleRetransmit, boolean isChunking, int chunkThreshold, String conduitName, URI url) { super(message, possibleRetransmit, isChunking, chunkThreshold, conduitName, url); entity = message.get(AhcWebSocketConduitRequest.class); // REVISIT how we prepare the request entity.setPath( url.getPath() + (String) message.getContextualProperty("org.apache.cxf.request.uri")); entity.setId(UUID.randomUUID().toString()); uncorrelatedRequests.put(entity.getId(), new RequestResponse(entity)); }
private boolean checkBufferingMode(Message m, List<WriterInterceptor> writers, boolean firstTry) { if (!firstTry) { return false; } WriterInterceptor last = writers.get(writers.size() - 1); MessageBodyWriter<Object> w = ((WriterInterceptorMBW) last).getMBW(); Object outBuf = m.getContextualProperty(OUT_BUFFERING); boolean enabled = MessageUtils.isTrue(outBuf); boolean configurableProvider = w instanceof AbstractConfigurableProvider; if (!enabled && outBuf == null && configurableProvider) { enabled = ((AbstractConfigurableProvider) w).getEnableBuffering(); } if (enabled) { boolean streamingOn = configurableProvider ? ((AbstractConfigurableProvider) w).getEnableStreaming() : false; if (streamingOn) { m.setContent(XMLStreamWriter.class, new CachingXmlEventWriter()); } else { m.setContent(OutputStream.class, new CachedOutputStream()); } } return enabled; }
private static TokenStore getTokenStore(Message message) { EndpointInfo info = message.getExchange().get(Endpoint.class).getEndpointInfo(); synchronized (info) { TokenStore tokenStore = (TokenStore) message.getContextualProperty( org.apache.cxf.ws.security.SecurityConstants.TOKEN_STORE_CACHE_INSTANCE); if (tokenStore == null) { tokenStore = (TokenStore) info.getProperty( org.apache.cxf.ws.security.SecurityConstants.TOKEN_STORE_CACHE_INSTANCE); } if (tokenStore == null) { TokenStoreFactory tokenStoreFactory = TokenStoreFactory.newInstance(); tokenStore = tokenStoreFactory.newTokenStore( org.apache.cxf.ws.security.SecurityConstants.TOKEN_STORE_CACHE_INSTANCE, message); info.setProperty( org.apache.cxf.ws.security.SecurityConstants.TOKEN_STORE_CACHE_INSTANCE, tokenStore); } return tokenStore; } }
protected void handle(Message msg) { if (MessageUtils.isRequestor(msg)) { LOG.fine("Is a requestor."); return; } Exchange exchange = msg.getExchange(); assert null != exchange; BindingOperationInfo boi = exchange.get(BindingOperationInfo.class); if (null == boi) { LOG.fine("No binding operation info."); return; } Endpoint e = exchange.get(Endpoint.class); if (null == e) { LOG.fine("No endpoint."); return; } EndpointInfo ei = e.getEndpointInfo(); Bus bus = exchange.get(Bus.class); PolicyEngine pe = bus.getExtension(PolicyEngine.class); if (null == pe) { return; } Destination destination = exchange.getDestination(); Exception ex = exchange.get(Exception.class); List<Interceptor<? extends Message>> faultInterceptors = new ArrayList<Interceptor<? extends Message>>(); Collection<Assertion> assertions = new ArrayList<Assertion>(); // 1. Check overridden policy Policy p = (Policy) msg.getContextualProperty(PolicyConstants.POLICY_OVERRIDE); if (p != null) { EndpointPolicyImpl endpi = new EndpointPolicyImpl(p); EffectivePolicyImpl effectivePolicy = new EffectivePolicyImpl(); effectivePolicy.initialise(endpi, (PolicyEngineImpl) pe, false, true); PolicyUtils.logPolicy( LOG, Level.FINEST, "Using effective policy: ", effectivePolicy.getPolicy()); faultInterceptors.addAll(effectivePolicy.getInterceptors()); assertions.addAll(effectivePolicy.getChosenAlternative()); } else { // 2. Process effective server policy BindingFaultInfo bfi = getBindingFaultInfo(msg, ex, boi); if (bfi == null && msg.get(FaultMode.class) != FaultMode.UNCHECKED_APPLICATION_FAULT && msg.get(FaultMode.class) != FaultMode.CHECKED_APPLICATION_FAULT) { return; } EffectivePolicy effectivePolicy = pe.getEffectiveServerFaultPolicy(ei, boi, bfi, destination); if (effectivePolicy != null) { faultInterceptors.addAll(effectivePolicy.getInterceptors()); assertions.addAll(effectivePolicy.getChosenAlternative()); } } // add interceptors into message chain for (Interceptor<? extends Message> oi : faultInterceptors) { msg.getInterceptorChain().add(oi); LOG.log(Level.FINE, "Added interceptor of type {0}", oi.getClass().getSimpleName()); } // insert assertions of the chosen alternative into the message if (null != assertions && !assertions.isEmpty()) { msg.put(AssertionInfoMap.class, new AssertionInfoMap(assertions)); } }
public SourceSequence getSequence(Identifier inSeqId, Message message, AddressingProperties maps) throws RMException { Source source = getSource(message); SourceSequence seq = source.getCurrent(inSeqId); RMConfiguration config = getEffectiveConfiguration(message); if (null == seq || seq.isExpired()) { // TODO: better error handling EndpointReferenceType to = null; boolean isServer = RMContextUtils.isServerSide(message); EndpointReferenceType acksTo = null; RelatesToType relatesTo = null; if (isServer) { AddressingProperties inMaps = RMContextUtils.retrieveMAPs(message, false, false); inMaps.exposeAs(config.getAddressingNamespace()); acksTo = RMUtils.createReference(inMaps.getTo().getValue()); to = inMaps.getReplyTo(); source.getReliableEndpoint().getServant().setUnattachedIdentifier(inSeqId); relatesTo = (new org.apache.cxf.ws.addressing.ObjectFactory()).createRelatesToType(); Destination destination = getDestination(message); DestinationSequence inSeq = inSeqId == null ? null : destination.getSequence(inSeqId); relatesTo.setValue(inSeq != null ? inSeq.getCorrelationID() : null); } else { to = RMUtils.createReference(maps.getTo().getValue()); acksTo = maps.getReplyTo(); if (RMUtils.getAddressingConstants().getNoneURI().equals(acksTo.getAddress().getValue())) { Endpoint ei = message.getExchange().getEndpoint(); org.apache.cxf.transport.Destination dest = ei == null ? null : ei.getEndpointInfo() .getProperty( MAPAggregator.DECOUPLED_DESTINATION, org.apache.cxf.transport.Destination.class); if (null == dest) { acksTo = RMUtils.createAnonymousReference(); } else { acksTo = dest.getAddress(); } } } if (ContextUtils.isGenericAddress(to)) { org.apache.cxf.common.i18n.Message msg = new org.apache.cxf.common.i18n.Message( "CREATE_SEQ_ANON_TARGET", LOG, to != null && to.getAddress() != null ? to.getAddress().getValue() : null); LOG.log(Level.INFO, msg.toString()); throw new RMException(msg); } Proxy proxy = source.getReliableEndpoint().getProxy(); ProtocolVariation protocol = config.getProtocolVariation(); Exchange exchange = new ExchangeImpl(); Map<String, Object> context = new HashMap<String, Object>(16); for (String key : message.getContextualPropertyKeys()) { // copy other properties? if (key.startsWith("ws-security")) { context.put(key, message.getContextualProperty(key)); } } CreateSequenceResponseType createResponse = proxy.createSequence(acksTo, relatesTo, isServer, protocol, exchange, context); if (!isServer) { Servant servant = source.getReliableEndpoint().getServant(); servant.createSequenceResponse(createResponse, protocol); // propagate security properties to application endpoint, in case we're using // WS-SecureConversation Exchange appex = message.getExchange(); if (appex.get(SecurityConstants.TOKEN) == null) { appex.put(SecurityConstants.TOKEN, exchange.get(SecurityConstants.TOKEN)); appex.put(SecurityConstants.TOKEN_ID, exchange.get(SecurityConstants.TOKEN_ID)); } } seq = source.awaitCurrent(inSeqId); seq.setTarget(to); } return seq; }
public RMEndpoint getReliableEndpoint(Message message) throws RMException { Endpoint endpoint = message.getExchange().getEndpoint(); QName name = endpoint.getEndpointInfo().getName(); if (LOG.isLoggable(Level.FINE)) { LOG.fine("Getting RMEndpoint for endpoint with info: " + name); } if (name.equals(RM10Constants.PORT_NAME) || name.equals(RM11Constants.PORT_NAME)) { WrappedEndpoint wrappedEndpoint = (WrappedEndpoint) endpoint; endpoint = wrappedEndpoint.getWrappedEndpoint(); } String rmUri = (String) message.getContextualProperty(WSRM_VERSION_PROPERTY); if (rmUri == null) { RMProperties rmps = RMContextUtils.retrieveRMProperties(message, false); if (rmps != null) { rmUri = rmps.getNamespaceURI(); } } String addrUri = (String) message.getContextualProperty(WSRM_WSA_VERSION_PROPERTY); if (addrUri == null) { AddressingProperties maps = ContextUtils.retrieveMAPs(message, false, false, false); if (maps != null) { addrUri = maps.getNamespaceURI(); } } RMConfiguration config = getConfiguration(); if (rmUri != null) { config.setRMNamespace(rmUri); ProtocolVariation protocol = ProtocolVariation.findVariant(rmUri, addrUri); if (protocol == null) { org.apache.cxf.common.i18n.Message msg = new org.apache.cxf.common.i18n.Message("UNSUPPORTED_NAMESPACE", LOG, addrUri, rmUri); LOG.log(Level.INFO, msg.toString()); throw new RMException(msg); } } if (addrUri != null) { config.setRM10AddressingNamespace(addrUri); } Long timeout = (Long) message.getContextualProperty(WSRM_INACTIVITY_TIMEOUT_PROPERTY); if (timeout != null) { config.setInactivityTimeout(timeout); } Long interval = (Long) message.getContextualProperty(WSRM_RETRANSMISSION_INTERVAL_PROPERTY); if (interval != null) { config.setBaseRetransmissionInterval(interval); } Boolean exponential = (Boolean) message.getContextualProperty(WSRM_EXPONENTIAL_BACKOFF_PROPERTY); if (exponential != null) { config.setExponentialBackoff(exponential); } interval = (Long) message.getContextualProperty(WSRM_ACKNOWLEDGEMENT_INTERVAL_PROPERTY); if (interval != null) { config.setAcknowledgementInterval(interval); } RMEndpoint rme = reliableEndpoints.get(endpoint); if (null == rme) { synchronized (endpoint) { rme = reliableEndpoints.get(endpoint); if (rme != null) { return rme; } rme = createReliableEndpoint(endpoint); org.apache.cxf.transport.Destination destination = message.getExchange().getDestination(); EndpointReferenceType replyTo = null; if (null != destination) { AddressingProperties maps = RMContextUtils.retrieveMAPs(message, false, false); replyTo = maps.getReplyTo(); } Endpoint ei = message.getExchange().getEndpoint(); org.apache.cxf.transport.Destination dest = ei == null ? null : ei.getEndpointInfo() .getProperty( MAPAggregator.DECOUPLED_DESTINATION, org.apache.cxf.transport.Destination.class); config = RMPolicyUtilities.getRMConfiguration(config, message); rme.initialise(config, message.getExchange().getConduit(message), replyTo, dest, message); reliableEndpoints.put(endpoint, rme); LOG.fine("Created new RMEndpoint."); } } return rme; }
// CHECKSTYLE:OFF - spec requires a bunch of params public W3CEndpointReference createW3CEndpointReference( String address, QName interfaceName, QName serviceName, QName portName, List<Element> metadata, String wsdlDocumentLocation, List<Element> referenceParameters, List<Element> elements, Map<QName, String> attributes) { // CHECKSTYLE:ON if (serviceName != null && portName != null && wsdlDocumentLocation != null && interfaceName == null) { Bus bus = BusFactory.getThreadDefaultBus(); WSDLManager wsdlManager = bus.getExtension(WSDLManager.class); try { Definition def = wsdlManager.getDefinition(wsdlDocumentLocation); interfaceName = def.getService(serviceName) .getPort(portName.getLocalPart()) .getBinding() .getPortType() .getQName(); } catch (Exception e) { // do nothing } } if (serviceName == null && portName == null && address == null) { throw new IllegalStateException( "Address in an EPR cannot be null, " + " when serviceName or portName is null"); } try { W3CDOMStreamWriter writer = new W3CDOMStreamWriter(); writer.setPrefix(JAXWSAConstants.WSA_PREFIX, JAXWSAConstants.NS_WSA); writer.writeStartElement( JAXWSAConstants.WSA_PREFIX, JAXWSAConstants.WSA_ERF_NAME, JAXWSAConstants.NS_WSA); writer.writeNamespace(JAXWSAConstants.WSA_PREFIX, JAXWSAConstants.NS_WSA); writer.writeStartElement( JAXWSAConstants.WSA_PREFIX, JAXWSAConstants.WSA_ADDRESS_NAME, JAXWSAConstants.NS_WSA); address = address == null ? "" : address; writer.writeCharacters(address); writer.writeEndElement(); if (referenceParameters != null) { writer.writeStartElement( JAXWSAConstants.WSA_PREFIX, JAXWSAConstants.WSA_REFERENCEPARAMETERS_NAME, JAXWSAConstants.NS_WSA); for (Element ele : referenceParameters) { StaxUtils.writeElement(ele, writer, true); } writer.writeEndElement(); } if (wsdlDocumentLocation != null || interfaceName != null || serviceName != null || (metadata != null && metadata.size() > 0)) { writer.writeStartElement( JAXWSAConstants.WSA_PREFIX, JAXWSAConstants.WSA_METADATA_NAME, JAXWSAConstants.NS_WSA); writer.writeNamespace(JAXWSAConstants.WSAW_PREFIX, JAXWSAConstants.NS_WSAW); writer.writeNamespace(JAXWSAConstants.WSAM_PREFIX, JAXWSAConstants.NS_WSAM); if (wsdlDocumentLocation != null) { boolean includeLocationOnly = false; org.apache.cxf.message.Message message = PhaseInterceptorChain.getCurrentMessage(); if (message != null) { includeLocationOnly = MessageUtils.isTrue( message.getContextualProperty("org.apache.cxf.wsa.metadata.wsdlLocationOnly")); } String attrubuteValue = serviceName != null && !includeLocationOnly ? serviceName.getNamespaceURI() + " " + wsdlDocumentLocation : wsdlDocumentLocation; writer.writeNamespace(JAXWSAConstants.WSDLI_PFX, JAXWSAConstants.NS_WSDLI); writer.writeAttribute( JAXWSAConstants.WSDLI_PFX, JAXWSAConstants.NS_WSDLI, JAXWSAConstants.WSDLI_WSDLLOCATION, attrubuteValue); } if (interfaceName != null) { writer.writeStartElement( JAXWSAConstants.WSAM_PREFIX, JAXWSAConstants.WSAM_INTERFACE_NAME, JAXWSAConstants.NS_WSAM); String portTypePrefix = interfaceName.getPrefix(); if (portTypePrefix == null || portTypePrefix.equals("")) { portTypePrefix = "ns1"; } writer.writeNamespace(portTypePrefix, interfaceName.getNamespaceURI()); writer.writeCharacters(portTypePrefix + ":" + interfaceName.getLocalPart()); writer.writeEndElement(); } String serviceNamePrefix = null; if (serviceName != null) { serviceNamePrefix = (serviceName.getPrefix() == null || serviceName.getPrefix().length() == 0) ? "ns2" : serviceName.getPrefix(); writer.writeStartElement( JAXWSAConstants.WSAM_PREFIX, JAXWSAConstants.WSAM_SERVICENAME_NAME, JAXWSAConstants.NS_WSAM); if (portName != null) { writer.writeAttribute(JAXWSAConstants.WSAM_ENDPOINT_NAME, portName.getLocalPart()); } writer.writeNamespace(serviceNamePrefix, serviceName.getNamespaceURI()); writer.writeCharacters(serviceNamePrefix + ":" + serviceName.getLocalPart()); writer.writeEndElement(); } if (wsdlDocumentLocation != null) { writer.writeStartElement( WSDLConstants.WSDL_PREFIX, WSDLConstants.QNAME_DEFINITIONS.getLocalPart(), WSDLConstants.NS_WSDL11); writer.writeNamespace(WSDLConstants.WSDL_PREFIX, WSDLConstants.NS_WSDL11); writer.writeStartElement( WSDLConstants.WSDL_PREFIX, WSDLConstants.QNAME_IMPORT.getLocalPart(), WSDLConstants.QNAME_IMPORT.getNamespaceURI()); if (serviceName != null) { writer.writeAttribute(WSDLConstants.ATTR_NAMESPACE, serviceName.getNamespaceURI()); } writer.writeAttribute(WSDLConstants.ATTR_LOCATION, wsdlDocumentLocation); writer.writeEndElement(); writer.writeEndElement(); } if (metadata != null) { for (Element e : metadata) { StaxUtils.writeElement(e, writer, true); } } writer.writeEndElement(); } if (elements != null) { for (Element e : elements) { StaxUtils.writeElement(e, writer, true); } } writer.writeEndElement(); writer.flush(); Unmarshaller unmarshaller = getJAXBContext().createUnmarshaller(); return (W3CEndpointReference) unmarshaller.unmarshal(writer.getDocument()); } catch (Exception e) { throw new WebServiceException( new Message("ERROR_UNMARSHAL_ENDPOINTREFERENCE", LOG).toString(), e); } }
@Override protected void writeParts( Message message, Exchange exchange, BindingOperationInfo operation, MessageContentsList objs, List<MessagePartInfo> parts) { // TODO Auto-generated method stub OutputStream out = message.getContent(OutputStream.class); XMLStreamWriter origXmlWriter = message.getContent(XMLStreamWriter.class); Service service = exchange.getService(); XMLStreamWriter xmlWriter = origXmlWriter; CachingXmlEventWriter cache = null; Object en = message.getContextualProperty(OUT_BUFFERING); boolean allowBuffer = true; boolean buffer = false; if (en != null) { buffer = Boolean.TRUE.equals(en) || "true".equals(en); allowBuffer = !(Boolean.FALSE.equals(en) || "false".equals(en)); } // need to cache the events in case validation fails or buffering is enabled if (buffer || (allowBuffer && shouldValidate(message) && !isRequestor(message))) { cache = new CachingXmlEventWriter(); try { cache.setNamespaceContext(origXmlWriter.getNamespaceContext()); } catch (XMLStreamException e) { // ignorable, will just get extra namespace decls } xmlWriter = cache; out = null; } if (out != null && writeToOutputStream(message, operation.getBinding(), service) && !MessageUtils.isTrue(message.getContextualProperty(DISABLE_OUTPUTSTREAM_OPTIMIZATION))) { if (xmlWriter != null) { try { xmlWriter.writeCharacters(""); xmlWriter.flush(); } catch (XMLStreamException e) { throw new Fault(e); } } DataWriter<OutputStream> osWriter = getDataWriter(message, service, OutputStream.class); for (MessagePartInfo part : parts) { if (objs.hasValue(part)) { Object o = objs.get(part); osWriter.write(o, part, out); } } } else { DataWriter<XMLStreamWriter> dataWriter = new CustomDataWriter(prismContext); for (MessagePartInfo part : parts) { if (objs.hasValue(part)) { Object o = objs.get(part); dataWriter.write(o, part, xmlWriter); } } } if (cache != null) { try { for (XMLEvent event : cache.getEvents()) { StaxUtils.writeEvent(event, origXmlWriter); } } catch (XMLStreamException e) { throw new Fault(e); } } }
protected boolean responseStreamCanBeClosed(Message outMessage, Class<?> cls) { return cls != InputStream.class && MessageUtils.isTrue(outMessage.getContextualProperty("response.stream.auto.close")); }
protected ResponseBuilder setResponseBuilder(Message outMessage, Exchange exchange) throws Exception { Response response = exchange.get(Response.class); if (response != null) { outMessage .getExchange() .getInMessage() .put(Message.PROTOCOL_HEADERS, response.getStringHeaders()); return JAXRSUtils.fromResponse(JAXRSUtils.copyResponseIfNeeded(response)); } Integer status = getResponseCode(exchange); ResponseBuilder currentResponseBuilder = JAXRSUtils.toResponseBuilder(status); Message responseMessage = exchange.getInMessage() != null ? exchange.getInMessage() : exchange.getInFaultMessage(); // if there is no response message, we just send the response back directly if (responseMessage == null) { return currentResponseBuilder; } Map<String, List<Object>> protocolHeaders = CastUtils.cast((Map<?, ?>) responseMessage.get(Message.PROTOCOL_HEADERS)); boolean splitHeaders = MessageUtils.isTrue(outMessage.getContextualProperty(HEADER_SPLIT_PROPERTY)); for (Map.Entry<String, List<Object>> entry : protocolHeaders.entrySet()) { if (null == entry.getKey()) { continue; } if (entry.getValue().size() > 0) { if (HttpUtils.isDateRelatedHeader(entry.getKey())) { currentResponseBuilder.header(entry.getKey(), entry.getValue().get(0)); continue; } for (Object valObject : entry.getValue()) { if (splitHeaders && valObject instanceof String) { String val = (String) valObject; String[] values; if (val == null || val.length() == 0) { values = new String[] {""}; } else if (val.charAt(0) == '"' && val.charAt(val.length() - 1) == '"') { // if the value starts with a quote and ends with a quote, we do a best // effort attempt to determine what the individual values are. values = parseQuotedHeaderValue(val); } else { boolean splitPossible = !(HttpHeaders.SET_COOKIE.equalsIgnoreCase(entry.getKey()) && val.toUpperCase().contains(HttpHeaders.EXPIRES.toUpperCase())); values = splitPossible ? val.split(",") : new String[] {val}; } for (String s : values) { String theValue = s.trim(); if (theValue.length() > 0) { currentResponseBuilder.header(entry.getKey(), theValue); } } } else { currentResponseBuilder.header(entry.getKey(), valObject); } } } } String ct = (String) responseMessage.get(Message.CONTENT_TYPE); if (ct != null) { currentResponseBuilder.type(ct); } InputStream mStream = responseMessage.getContent(InputStream.class); currentResponseBuilder.entity(mStream); return currentResponseBuilder; }