Author: hiranya
Date: Thu Nov 19 08:12:34 2009
New Revision: 882069
URL: http://svn.apache.org/viewvc?rev=882069&view=rev
Log:
Fixing the regression issues caused by my earlier fix to SYNAPSE-587. This
commit will enforce the content type inference logic only when the requests
contain a HTTP entity. Response which do not have an entity are treated as
having no entity body, ie no content type inference.
Modified:
synapse/branches/1.3/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/nhttp/ClientWorker.java
Modified:
synapse/branches/1.3/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/nhttp/ClientWorker.java
URL:
http://svn.apache.org/viewvc/synapse/branches/1.3/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/nhttp/ClientWorker.java?rev=882069&r1=882068&r2=882069&view=diff
==============================================================================
---
synapse/branches/1.3/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/nhttp/ClientWorker.java
(original)
+++
synapse/branches/1.3/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/nhttp/ClientWorker.java
Thu Nov 19 08:12:34 2009
@@ -152,65 +152,72 @@
return;
}
- SOAPEnvelope envelope = null;
try {
- Header cType = response.getFirstHeader(HTTP.CONTENT_TYPE);
- String contentType;
- if (cType != null) {
- // This is the most common case - Most of the time servers
send the Content-Type
- contentType = cType.getValue();
- } else {
- // Server hasn't sent the header - Try to infer the content
type
- contentType = inferContentType();
- }
+ if (response.getEntity() != null && in != null) {
+ Header cType = response.getFirstHeader(HTTP.CONTENT_TYPE);
+ String contentType;
+ if (cType != null) {
+ // This is the most common case - Most of the time servers
send the Content-Type
+ contentType = cType.getValue();
+ } else {
+ // Server hasn't sent the header - Try to infer the
content type
+ contentType = inferContentType();
+ }
- String charSetEnc = BuilderUtil.getCharSetEncoding(contentType);
- if (charSetEnc == null) {
- charSetEnc = MessageContext.DEFAULT_CHAR_SET_ENCODING;
- }
+ String charSetEnc =
BuilderUtil.getCharSetEncoding(contentType);
+ if (charSetEnc == null) {
+ charSetEnc = MessageContext.DEFAULT_CHAR_SET_ENCODING;
+ }
- responseMsgCtx.setProperty(
- Constants.Configuration.CHARACTER_SET_ENCODING,
- contentType.indexOf(HTTP.CHARSET_PARAM) > 0 ?
- charSetEnc : MessageContext.DEFAULT_CHAR_SET_ENCODING);
-
- // workaround for Axis2 TransportUtils.createSOAPMessage() issue,
where a response
- // of content type "text/xml" is thought to be REST if
!MC.isServerSide(). This
- // question is still under debate and due to the timelines, I am
commiting this
- // workaround as Axis2 1.2 is about to be released and Synapse 1.0
- responseMsgCtx.setServerSide(false);
- try {
- envelope = TransportUtils.createSOAPMessage(
- responseMsgCtx,
- HTTPTransportUtils.handleGZip(responseMsgCtx, in),
- contentType);
-
- } catch (OMException e) {
- // handle non SOAP and POX/REST payloads (probably text/html)
- String errorMessage = "Unexpected response received. HTTP
response code : "
- + this.response.getStatusLine().getStatusCode() + " HTTP
status : "
- + this.response.getStatusLine().getReasonPhrase() + "
exception : "
- + e.getMessage();
-
- log.warn(errorMessage);
- if (log.isDebugEnabled()) {
- log.debug(errorMessage, e);
- log.debug("Creating the SOAPFault to be injected...");
+ responseMsgCtx.setProperty(
+ Constants.Configuration.CHARACTER_SET_ENCODING,
+ contentType.indexOf(HTTP.CHARSET_PARAM) > 0 ?
+ charSetEnc : MessageContext.DEFAULT_CHAR_SET_ENCODING);
+
+ // workaround for Axis2 TransportUtils.createSOAPMessage()
issue, where a response
+ // of content type "text/xml" is thought to be REST if
!MC.isServerSide(). This
+ // question is still under debate and due to the timelines, I
am commiting this
+ // workaround as Axis2 1.2 is about to be released and Synapse
1.0
+ responseMsgCtx.setServerSide(false);
+ SOAPEnvelope envelope;
+ try {
+ envelope = TransportUtils.createSOAPMessage(
+ responseMsgCtx,
+ HTTPTransportUtils.handleGZip(responseMsgCtx, in),
+ contentType);
+
+ } catch (OMException e) {
+ // handle non SOAP and POX/REST payloads (probably
text/html)
+ String errorMessage = "Unexpected response received. HTTP
response code : "
+ + this.response.getStatusLine().getStatusCode() + "
HTTP status : "
+ + this.response.getStatusLine().getReasonPhrase() + "
exception : "
+ + e.getMessage();
+
+ log.warn(errorMessage);
+ if (log.isDebugEnabled()) {
+ log.debug(errorMessage, e);
+ log.debug("Creating the SOAPFault to be injected...");
+ }
+ SOAPFactory factory = new SOAP11Factory();
+ envelope = factory.getDefaultFaultEnvelope();
+ SOAPFaultDetail detail = factory.createSOAPFaultDetail();
+ detail.setText(errorMessage);
+ envelope.getBody().getFault().setDetail(detail);
+ SOAPFaultReason reason = factory.createSOAPFaultReason();
+ reason.setText(errorMessage);
+ envelope.getBody().getFault().setReason(reason);
+ SOAPFaultCode code = factory.createSOAPFaultCode();
+
code.setText(Integer.toString(this.response.getStatusLine().getStatusCode()));
+ envelope.getBody().getFault().setCode(code);
}
- SOAPFactory factory = new SOAP11Factory();
- envelope = factory.getDefaultFaultEnvelope();
- SOAPFaultDetail detail = factory.createSOAPFaultDetail();
- detail.setText(errorMessage);
- envelope.getBody().getFault().setDetail(detail);
- SOAPFaultReason reason = factory.createSOAPFaultReason();
- reason.setText(errorMessage);
- envelope.getBody().getFault().setReason(reason);
- SOAPFaultCode code = factory.createSOAPFaultCode();
-
code.setText(Integer.toString(this.response.getStatusLine().getStatusCode()));
- envelope.getBody().getFault().setCode(code);
+ responseMsgCtx.setServerSide(true);
+ responseMsgCtx.setEnvelope(envelope);
+
+ } else {
+ // there is no response entity-body
+ responseMsgCtx.setProperty(NhttpConstants.NO_ENTITY_BODY,
Boolean.TRUE);
+ responseMsgCtx.setEnvelope(new
SOAP11Factory().getDefaultEnvelope());
}
- responseMsgCtx.setServerSide(true);
- responseMsgCtx.setEnvelope(envelope);
// copy the HTTP status code as a message context property with
the key HTTP_SC to be
// used at the sender to set the propper status code when passing
the message