You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@synapse.apache.org by as...@apache.org on 2007/05/03 14:31:45 UTC

svn commit: r534821 - in /webservices/synapse/trunk/java/modules: core/src/main/java/org/apache/synapse/core/axis2/ nhttp/src/org/apache/axis2/transport/nhttp/

Author: asankha
Date: Thu May  3 05:31:44 2007
New Revision: 534821

URL: http://svn.apache.org/viewvc?view=rev&rev=534821
Log:
fix SYNAPSE-93 for http/s 202 Accepted with the non-blocking transport

The fix involves creating a dummy message context with an empty SOAP envelope and passing it back to Synapse as the response received. Synapse needs to now <send/> this message back to the client, in order to write a 202 Accepted back to its client. If the client <-> synapse transport is anything other than http/s, this dummy message would be dropped - e.g. for JMS

Added:
    webservices/synapse/trunk/java/modules/nhttp/src/org/apache/axis2/transport/nhttp/NhttpConstants.java
Modified:
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/SynapseCallbackReceiver.java
    webservices/synapse/trunk/java/modules/nhttp/src/org/apache/axis2/transport/nhttp/ClientHandler.java
    webservices/synapse/trunk/java/modules/nhttp/src/org/apache/axis2/transport/nhttp/HttpCoreNIOSender.java

Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/SynapseCallbackReceiver.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/SynapseCallbackReceiver.java?view=diff&rev=534821&r1=534820&r2=534821
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/SynapseCallbackReceiver.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/SynapseCallbackReceiver.java Thu May  3 05:31:44 2007
@@ -23,6 +23,7 @@
 import org.apache.axis2.client.async.Callback;
 import org.apache.axis2.context.MessageContext;
 import org.apache.axis2.AxisFault;
+import org.apache.axis2.transport.nhttp.NhttpConstants;
 import org.apache.axis2.addressing.RelatesTo;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -97,7 +98,7 @@
     private void handleMessage(MessageContext response,
                                org.apache.synapse.MessageContext synapseOutMsgCtx) {
 
-        Object o = response.getProperty("sending_fault");
+        Object o = response.getProperty(NhttpConstants.SENDING_FAULT);
         if (o != null && Boolean.TRUE.equals(o)) {
 
             // there is a sending fault. propagate the fault to fault handlers.

Modified: webservices/synapse/trunk/java/modules/nhttp/src/org/apache/axis2/transport/nhttp/ClientHandler.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/nhttp/src/org/apache/axis2/transport/nhttp/ClientHandler.java?view=diff&rev=534821&r1=534820&r2=534821
==============================================================================
--- webservices/synapse/trunk/java/modules/nhttp/src/org/apache/axis2/transport/nhttp/ClientHandler.java (original)
+++ webservices/synapse/trunk/java/modules/nhttp/src/org/apache/axis2/transport/nhttp/ClientHandler.java Thu May  3 05:31:44 2007
@@ -33,10 +33,15 @@
 import org.apache.axis2.transport.nhttp.util.NativeWorkerPool;
 import org.apache.axis2.transport.nhttp.util.WorkerPool;
 import org.apache.axis2.transport.nhttp.util.WorkerPoolFactory;
+import org.apache.axis2.description.WSDL2Constants;
+import org.apache.axis2.engine.MessageReceiver;
+import org.apache.axis2.wsdl.WSDLConstants;
+import org.apache.axis2.addressing.AddressingConstants;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.axiom.soap.SOAP11Constants;
 import org.apache.axiom.soap.SOAP12Constants;
+import org.apache.axiom.soap.SOAPFactory;
 
 import java.nio.ByteBuffer;
 import java.nio.channels.Channels;
@@ -271,6 +276,43 @@
         switch (response.getStatusLine().getStatusCode()) {
             case HttpStatus.SC_ACCEPTED : {
                 log.debug("Received a 202 Accepted response");
+
+                // create a dummy message with an empty SOAP envelope and a property
+                // NhttpConstants.SC_ACCEPTED set to Boolean.TRUE to indicate this is a
+                // placeholder message for the transport to send a HTTP 202 to the
+                // client. Should / would be ignored by any transport other than
+                // nhttp. For example, JMS would not send a reply message for one-way
+                // operations.
+                MessageContext outMsgCtx =
+                    (MessageContext) context.getAttribute(OUTGOING_MESSAGE_CONTEXT);
+                MessageReceiver mr = outMsgCtx.getAxisOperation().getMessageReceiver();
+
+                try {
+                    MessageContext responseMsgCtx = outMsgCtx.getOperationContext().
+                        getMessageContext(WSDL2Constants.MESSAGE_LABEL_IN);
+                    responseMsgCtx.setServerSide(true);
+                    responseMsgCtx.setDoingREST(outMsgCtx.isDoingREST());
+                    responseMsgCtx.setProperty(MessageContext.TRANSPORT_IN,
+                        outMsgCtx.getProperty(MessageContext.TRANSPORT_IN));
+                    responseMsgCtx.setTransportIn(outMsgCtx.getTransportIn());
+                    responseMsgCtx.setTransportOut(outMsgCtx.getTransportOut());
+
+                    responseMsgCtx.setAxisMessage(outMsgCtx.getAxisOperation().
+                        getMessage(WSDLConstants.MESSAGE_LABEL_IN_VALUE));
+                    responseMsgCtx.setOperationContext(outMsgCtx.getOperationContext());
+                    responseMsgCtx.setConfigurationContext(outMsgCtx.getConfigurationContext());
+                    responseMsgCtx.setTo(null);
+
+                    responseMsgCtx.setEnvelope(
+                        ((SOAPFactory)outMsgCtx.getEnvelope().getOMFactory()).getDefaultEnvelope());
+                    responseMsgCtx.setProperty(AddressingConstants.DISABLE_ADDRESSING_FOR_OUT_MESSAGES, Boolean.TRUE);
+                    responseMsgCtx.setProperty(NhttpConstants.SC_ACCEPTED, Boolean.TRUE);
+                    mr.receive(responseMsgCtx);
+
+                } catch (org.apache.axis2.AxisFault af) {
+                    log.error("Unable to report back 202 Accepted state to the message receiver", af);
+                }
+
                 return;
             }
             case HttpStatus.SC_INTERNAL_SERVER_ERROR : {

Modified: webservices/synapse/trunk/java/modules/nhttp/src/org/apache/axis2/transport/nhttp/HttpCoreNIOSender.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/nhttp/src/org/apache/axis2/transport/nhttp/HttpCoreNIOSender.java?view=diff&rev=534821&r1=534820&r2=534821
==============================================================================
--- webservices/synapse/trunk/java/modules/nhttp/src/org/apache/axis2/transport/nhttp/HttpCoreNIOSender.java (original)
+++ webservices/synapse/trunk/java/modules/nhttp/src/org/apache/axis2/transport/nhttp/HttpCoreNIOSender.java Thu May  3 05:31:44 2007
@@ -50,6 +50,7 @@
 import org.apache.commons.logging.LogFactory;
 import org.apache.http.HttpHost;
 import org.apache.http.HttpResponse;
+import org.apache.http.HttpStatus;
 import org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor;
 import org.apache.http.impl.nio.reactor.SSLIOSessionHandler;
 import org.apache.http.nio.NHttpClientConnection;
@@ -308,6 +309,12 @@
             HTTP.CONTENT_TYPE,
             messageFormatter.getContentType(msgContext, format, msgContext.getSoapAction()));
 
+        // 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 (Boolean.TRUE.equals(msgContext.getProperty(NhttpConstants.SC_ACCEPTED))) {
+            response.setStatusCode(HttpStatus.SC_ACCEPTED);
+        }
+
         // set any transport headers
         Map transportHeaders = (Map) msgContext.getProperty(MessageContext.TRANSPORT_HEADERS);
         if (transportHeaders != null && !transportHeaders.values().isEmpty()) {
@@ -324,7 +331,12 @@
 
         OutputStream out = worker.getOutputStream();
         try {
-            messageFormatter.writeTo(msgContext, format, out, true);
+            if (!Boolean.TRUE.equals(msgContext.getProperty(NhttpConstants.SC_ACCEPTED))) {
+                messageFormatter.writeTo(msgContext, format, out, true);
+            } else {
+                // see comment above on the reasoning
+                out.write(new byte[0]);
+            }
             out.close();
         } catch (IOException e) {
             handleException("IO Error sending response message", e);
@@ -417,7 +429,7 @@
                             MessageContextBuilder.createFaultMessageContext(
                                 /** this is not a mistake I do NOT want getMessage()*/
                                 mc, new AxisFault(exception.toString(), exception));
-                        nioFaultMessageContext.setProperty("sending_fault", Boolean.TRUE);
+                        nioFaultMessageContext.setProperty(NhttpConstants.SENDING_FAULT, Boolean.TRUE);
                         mr.receive(nioFaultMessageContext);
                         
                     } catch (AxisFault af) {

Added: webservices/synapse/trunk/java/modules/nhttp/src/org/apache/axis2/transport/nhttp/NhttpConstants.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/nhttp/src/org/apache/axis2/transport/nhttp/NhttpConstants.java?view=auto&rev=534821
==============================================================================
--- webservices/synapse/trunk/java/modules/nhttp/src/org/apache/axis2/transport/nhttp/NhttpConstants.java (added)
+++ webservices/synapse/trunk/java/modules/nhttp/src/org/apache/axis2/transport/nhttp/NhttpConstants.java Thu May  3 05:31:44 2007
@@ -0,0 +1,25 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.apache.axis2.transport.nhttp;
+
+public class NhttpConstants {
+    public static final String SC_ACCEPTED = "SC_ACCEPTED";
+    public static final String SENDING_FAULT = "sending_fault";
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: synapse-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: synapse-dev-help@ws.apache.org