You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@synapse.apache.org by as...@apache.org on 2009/03/21 06:24:43 UTC
svn commit: r756878 - in /synapse/trunk/java/modules:
extensions/src/main/java/org/apache/synapse/format/hessian/
transports/src/main/java/org/apache/synapse/transport/nhttp/
Author: asankha
Date: Sat Mar 21 05:24:43 2009
New Revision: 756878
URL: http://svn.apache.org/viewvc?rev=756878&view=rev
Log:
commit fix for SYNAPSE-521 from Eric Hubert
Modified:
synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/format/hessian/HessianMessageBuilder.java
synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/HttpCoreNIOSender.java
synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/NhttpConstants.java
Modified: synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/format/hessian/HessianMessageBuilder.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/format/hessian/HessianMessageBuilder.java?rev=756878&r1=756877&r2=756878&view=diff
==============================================================================
--- synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/format/hessian/HessianMessageBuilder.java (original)
+++ synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/format/hessian/HessianMessageBuilder.java Sat Mar 21 05:24:43 2009
@@ -33,6 +33,7 @@
import org.apache.commons.logging.LogFactory;
import org.apache.synapse.SynapseConstants;
import org.apache.synapse.core.SynapseEnvironment;
+import org.apache.synapse.transport.nhttp.NhttpConstants;
import org.apache.synapse.util.SynapseBinaryDataSource;
import javax.activation.DataHandler;
@@ -94,6 +95,9 @@
}
OMText textData = factory.createOMText(dataHandler, true);
element.addChild(textData);
+
+ // indicate that message faults shall be handled as http 200
+ messageContext.setProperty(NhttpConstants.FAULTS_AS_HTTP_200, NhttpConstants.TRUE);
} catch (IOException e) {
String msg = "Unable to create the HessianDataSource";
Modified: synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/HttpCoreNIOSender.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/HttpCoreNIOSender.java?rev=756878&r1=756877&r2=756878&view=diff
==============================================================================
--- synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/HttpCoreNIOSender.java (original)
+++ synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/HttpCoreNIOSender.java Sat Mar 21 05:24:43 2009
@@ -431,27 +431,7 @@
HTTP.CONTENT_TYPE,
messageFormatter.getContentType(msgContext, format, msgContext.getSoapAction()));
- // return http 500 when a SOAP fault is returned
- if (msgContext.getEnvelope().getBody().hasFault() || msgContext.isProcessingFault()) {
- response.setStatusCode(HttpStatus.SC_INTERNAL_SERVER_ERROR);
- }
-
- // if this is a dummy message to handle http 202 case with non-blocking IO
- // set the status code to 202 and the message body to an empty byte array (see below)
- if (msgContext.isPropertyTrue(NhttpConstants.SC_ACCEPTED)) {
- response.setStatusCode(HttpStatus.SC_ACCEPTED);
- } else {
- Object statusCode = msgContext.getProperty(NhttpConstants.HTTP_SC);
- if (statusCode != null) {
- try {
- response.setStatusCode(Integer.parseInt(
- msgContext.getProperty(NhttpConstants.HTTP_SC).toString()));
- } catch (NumberFormatException e) {
- log.warn("Unable to set the HTTP Status Code from " +
- "the property HHTP_SC with value : " + statusCode);
- }
- }
- }
+ response.setStatusCode(determineHttpStatusCode(msgContext, response));
// set any transport headers
Map transportHeaders = (Map) msgContext.getProperty(MessageContext.TRANSPORT_HEADERS);
@@ -472,8 +452,11 @@
lstMetrics.reportResponseCode(response.getStatusLine().getStatusCode());
OutputStream out = worker.getOutputStream();
+ /*
+ * if this is a dummy message to handle http 202 case with non-blocking IO
+ * write an empty byte array as body
+ */
if (msgContext.isPropertyTrue(NhttpConstants.SC_ACCEPTED)) {
- // see comment above on the reasoning
out.write(new byte[0]);
} else {
messageFormatter.writeTo(msgContext, format, out, false);
@@ -521,6 +504,67 @@
}
}
+ /**
+ * Determine the HttpStatusCodedepending on the message type processed <br>
+ * (normal response versus fault response) as well as Axis2 message context properties set
+ * via Synapse configuration or MessageBuilders.
+ *
+ * @see NhttpConstants.FAULTS_AS_HTTP_200
+ * @see NhttpConstants.HTTP_SC
+ *
+ * @param msgContext the Axis2 message context
+ * @param response the HTTP response object
+ *
+ * @return the HTTP status code to set in the HTTP response object
+ */
+ private int determineHttpStatusCode(MessageContext msgContext, HttpResponse response) {
+
+ int httpStatus = HttpStatus.SC_OK;
+
+ // retrieve original status code (if present)
+ if (response.getStatusLine() != null) {
+ httpStatus = response.getStatusLine().getStatusCode();
+ }
+
+ // if this is a dummy message to handle http 202 case with non-blocking IO
+ // set the status code to 202
+ if (msgContext.isPropertyTrue(NhttpConstants.SC_ACCEPTED)) {
+ httpStatus = HttpStatus.SC_ACCEPTED;
+ } else {
+
+ // is this a fault message
+ boolean handleFault =
+ msgContext.getEnvelope().getBody().hasFault() || msgContext.isProcessingFault();
+
+ // shall faults be transmitted with HTTP 200
+ boolean faultsAsHttp200 =
+ NhttpConstants.TRUE.equals(
+ msgContext.getProperty(NhttpConstants.FAULTS_AS_HTTP_200));
+
+ // Set HTTP status code to 500 if this is a fault case and we shall not use HTTP 200
+ if (handleFault && !faultsAsHttp200) {
+ httpStatus = HttpStatus.SC_INTERNAL_SERVER_ERROR;
+ }
+
+ /*
+ * Any status code previously set shall be overwritten with the value of the following
+ * message context property if it is set.
+ */
+ Object statusCode = msgContext.getProperty(NhttpConstants.HTTP_SC);
+ if (statusCode != null) {
+ try {
+ httpStatus = Integer.parseInt(
+ msgContext.getProperty(NhttpConstants.HTTP_SC).toString());
+ } catch (NumberFormatException e) {
+ log.warn("Unable to set the HTTP status code from the property "
+ + NhttpConstants.HTTP_SC + " with value: " + statusCode);
+ }
+ }
+ }
+
+ return httpStatus;
+ }
+
private void sendUsingOutputStream(MessageContext msgContext) throws AxisFault {
OMOutputFormat format = NhttpUtil.getOMOutputFormat(msgContext);
Modified: synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/NhttpConstants.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/NhttpConstants.java?rev=756878&r1=756877&r2=756878&view=diff
==============================================================================
--- synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/NhttpConstants.java (original)
+++ synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/NhttpConstants.java Sat Mar 21 05:24:43 2009
@@ -26,6 +26,7 @@
* has information that the current message is a fault (e.g. SOAP faults, non-HTTP 2xx, etc)
*/
public static final String FAULT_MESSAGE = "FAULT_MESSAGE"; // corresponds with BaseConstants
+ public static final String FAULTS_AS_HTTP_200 = "FAULTS_AS_HTTP_200";
public static final String SC_ACCEPTED = "SC_ACCEPTED";
public static final String HTTP_SC = "HTTP_SC";
public static final String FORCE_HTTP_1_0 = "FORCE_HTTP_1.0";