Author: supun
Date: Thu Oct  7 05:55:01 2010
New Revision: 1005332

URL: http://svn.apache.org/viewvc?rev=1005332&view=rev
Log:
adding capability to disable rest dispatching

Modified:
    
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/nhttp/HttpCoreNIOListener.java
    
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/nhttp/NhttpConstants.java
    
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/nhttp/ServerHandler.java
    
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/nhttp/ServerWorker.java
    
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/nhttp/util/RESTUtil.java

Modified: 
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/nhttp/HttpCoreNIOListener.java
URL: 
http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/nhttp/HttpCoreNIOListener.java?rev=1005332&r1=1005331&r2=1005332&view=diff
==============================================================================
--- 
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/nhttp/HttpCoreNIOListener.java
 (original)
+++ 
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/nhttp/HttpCoreNIOListener.java
 Thu Oct  7 05:55:01 2010
@@ -116,6 +116,8 @@ public class HttpCoreNIOListener impleme
     private PriorityExecutor executor = null;
     /** parser for calculating the priority of incoming messages */
     private Parser parser = null;
+    /** if falses we won't dispatch to axis2 service in case of rest scenarios 
*/
+    private boolean restDispatching = true;
 
     protected IOEventDispatch getEventDispatch(
         NHttpServiceHandler handler, SSLContext sslContext, 
@@ -207,18 +209,30 @@ public class HttpCoreNIOListener impleme
         if (param != null && param.getValue() != null) {
             createPriorityConfiguration(param.getValue().toString());
         }
+
+        param = 
transprtIn.getParameter(NhttpConstants.DISABLE_REST_SERVICE_DISPATCHING);
+        if (param != null && param.getValue() != null) {
+            if (param.getValue().equals("true")) {
+                restDispatching = false;
+            }
+        }
     }
 
     public int getActiveConnectionsSize() {
         return handler.getActiveConnectionsSize();
     }
 
+    /**
+     * Create a priority executor from the given file 
+     *
+     * @param fileName file name of the executor configuration
+     * @throws AxisFault if an error occurs
+     */
     private void createPriorityConfiguration(String fileName) throws AxisFault 
{
         OMElement definitions = null;
         try {
             FileInputStream fis = new FileInputStream(fileName);
             definitions = new StAXOMBuilder(fis).getDocumentElement();
-            assert definitions != null;
             definitions.build();
         } catch (FileNotFoundException e) {
             handleException("Priority configuration file cannot be found : " + 
fileName, e);
@@ -226,6 +240,7 @@ public class HttpCoreNIOListener impleme
             handleException("Error parsing priority configuration xml file " + 
fileName, e);
         }
 
+        assert definitions != null;
         OMElement executorElem = definitions.getFirstChildWithName(
                 new QName(ExecutorConstants.PRIORITY_EXECUTOR));
 
@@ -352,7 +367,8 @@ public class HttpCoreNIOListener impleme
             addToServiceURIMap((AxisService) obj);
         }
         
-        handler = new ServerHandler(cfgCtx, params, sslContext != null, 
metrics, parser, executor);
+        handler = new ServerHandler(cfgCtx, params, sslContext != null
+                , metrics, parser, executor, restDispatching);
         final IOEventDispatch ioEventDispatch = getEventDispatch(handler,
                 sslContext, sslIOSessionHandler, params);
         state = BaseConstants.STARTED;
@@ -614,7 +630,7 @@ public class HttpCoreNIOListener impleme
         public void removeParameter(Parameter param) throws AxisFault {}
         public void deserializeParameters(OMElement parameterElement) throws 
AxisFault {}
         public Parameter getParameter(String name) { return null; }
-        public ArrayList getParameters() { return null; }
+        public ArrayList<Parameter> getParameters() { return null; }
         public boolean isParameterLocked(String parameterName) { return false; 
}
         public void serviceGroupUpdate(AxisEvent event, AxisServiceGroup 
serviceGroup) {}
     }

Modified: 
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/nhttp/NhttpConstants.java
URL: 
http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/nhttp/NhttpConstants.java?rev=1005332&r1=1005331&r2=1005332&view=diff
==============================================================================
--- 
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/nhttp/NhttpConstants.java
 (original)
+++ 
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/nhttp/NhttpConstants.java
 Thu Oct  7 05:55:01 2010
@@ -114,4 +114,15 @@ public class NhttpConstants {
     public static final String REQ_DEPARTURE_TIME = "REQ_DEPARTURE_TIME";
     public static final String RES_ARRIVAL_TIME = "RES_ARRIVAL_TIME";
     public static final String RES_DEPARTURE_TIME = "RES_DEPARTURE_TIME";
+
+    /**
+     * This is a name of a parameter in transportReceiver. If set it will 
disable service
+     * dispatching inside the transport for rest messages
+     * */
+    public static final String DISABLE_REST_SERVICE_DISPATCHING = 
"disableRestServiceDispatching";
+
+    /** Input stream of the message is set to this message context property */
+    public static final String NHTTP_INPUT_STREAM = "nhttp.input.stream";
+    /** Output stram of the message is set to this message context property */
+    public static final String NHTTP_OUTPUT_STREAM = "nhttp.output.stream";
 }

Modified: 
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/nhttp/ServerHandler.java
URL: 
http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/nhttp/ServerHandler.java?rev=1005332&r1=1005331&r2=1005332&view=diff
==============================================================================
--- 
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/nhttp/ServerHandler.java
 (original)
+++ 
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/nhttp/ServerHandler.java
 Thu Oct  7 05:55:01 2010
@@ -96,10 +96,20 @@ public class ServerHandler implements NH
     /** keeps track of the connection that are alive in the system */
     private volatile List<NHttpServerConnection> activeConnections = null;
 
+    /**
+     * This parset is used by the priority executor to parse a given HTTP 
message and
+     * determine the priority of the message
+     */
     private Parser parser = null;
 
+    /**
+     * An executor capable of exucuting the Server Worker according the 
priority assigned
+     * to a particular message
+     */
     private PriorityExecutor executor = null;
 
+    private boolean restDispatching = true;
+    
     private LatencyView latencyView = null;
     private ThreadingView threadingView = null;
 
@@ -110,7 +120,7 @@ public class ServerHandler implements NH
 
     public ServerHandler(final ConfigurationContext cfgCtx, final HttpParams 
params,
         final boolean isHttps, final NhttpMetricsCollector metrics,
-        Parser parser, PriorityExecutor executor) {
+        Parser parser, PriorityExecutor executor, boolean restDispatching) {
         super();
         this.cfgCtx = cfgCtx;
         this.params = params;
@@ -123,6 +133,7 @@ public class ServerHandler implements NH
         this.activeConnections = new ArrayList<NHttpServerConnection>();
         this.latencyView = new LatencyView(isHttps);
         this.threadingView = new ThreadingView("HttpServerWorker", true, 50);
+        this.restDispatching = restDispatching;
 
         this.cfg = NHttpConfiguration.getInstance();
         if (executor == null)  {
@@ -190,7 +201,7 @@ public class ServerHandler implements NH
 
             // hand off processing of the request to a thread off the pool
             ServerWorker worker = new ServerWorker(cfgCtx, conn, isHttps, 
metrics, this,
-                        request, is, response, os);
+                        request, is, response, os, restDispatching);
 
             if (workerPool != null) {
                 workerPool.execute(worker);

Modified: 
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/nhttp/ServerWorker.java
URL: 
http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/nhttp/ServerWorker.java?rev=1005332&r1=1005331&r2=1005332&view=diff
==============================================================================
--- 
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/nhttp/ServerWorker.java
 (original)
+++ 
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/nhttp/ServerWorker.java
 Thu Oct  7 05:55:01 2010
@@ -82,6 +82,8 @@ public class ServerWorker implements Run
     private OutputStream os = null;
     /** the metrics collector */
     private MetricsCollector metrics = null;
+    /** Weather we should do rest dispatching or not */
+    private boolean isRestDispatching = true;
     
     private static final String SOAPACTION   = "SOAPAction";
     private static final String LOCATION     = "Location";
@@ -108,13 +110,15 @@ public class ServerWorker implements Run
      * @param is the stream input stream to read the request body
      * @param response the response to be populated if applicable
      * @param os the output stream to write the response body if one is 
applicable
+     * @param isRestDispatching weather we should dispatch in case of rest
      */
     public ServerWorker(final ConfigurationContext cfgCtx, final 
NHttpServerConnection conn,
         final boolean isHttps,
         final MetricsCollector metrics,
         final ServerHandler serverHandler,
         final HttpRequest request, final InputStream is,
-        final HttpResponse response, final OutputStream os) {
+        final HttpResponse response, final OutputStream os,
+        final boolean isRestDispatching) {
 
         this.cfgCtx = cfgCtx;
         this.conn = conn;
@@ -126,6 +130,7 @@ public class ServerWorker implements Run
         this.is = is;
         this.os = os;
         this.msgContext = createMessageContext(request);
+        this.isRestDispatching = isRestDispatching;
     }
 
     /**
@@ -193,7 +198,10 @@ public class ServerWorker implements Run
 
         msgContext.setProperty(ServerHandler.SERVER_CONNECTION_DEBUG,
             
conn.getContext().getAttribute(ServerHandler.SERVER_CONNECTION_DEBUG));
-        
+
+        msgContext.setProperty(NhttpConstants.NHTTP_INPUT_STREAM, is);
+        msgContext.setProperty(NhttpConstants.NHTTP_OUTPUT_STREAM, os);
+
         return msgContext;
     }
 
@@ -401,7 +409,7 @@ public class ServerWorker implements Run
 
             if (HTTPTransportUtils.isRESTRequest(contentTypeStr)) {
                 RESTUtil.processPOSTRequest(msgContext, is, os,
-                        request.getRequestLine().getUri(), contentType);
+                        request.getRequestLine().getUri(), contentType, 
isRestDispatching);
             } else {
 
                 Header soapAction  = request.getFirstHeader(SOAPACTION);
@@ -676,7 +684,7 @@ public class ServerWorker implements Run
         try {
             RESTUtil.processGetAndDeleteRequest(
                     msgContext, os, request.getRequestLine().getUri(),
-                    request.getFirstHeader(HTTP.CONTENT_TYPE),method);
+                    request.getFirstHeader(HTTP.CONTENT_TYPE), method, 
isRestDispatching);
             // do not let the output stream close (as by default below) since
             // we are serving this GET/DELETE request through the Synapse 
engine
         } catch (AxisFault axisFault) {

Modified: 
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/nhttp/util/RESTUtil.java
URL: 
http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/nhttp/util/RESTUtil.java?rev=1005332&r1=1005331&r2=1005332&view=diff
==============================================================================
--- 
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/nhttp/util/RESTUtil.java
 (original)
+++ 
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/nhttp/util/RESTUtil.java
 Thu Oct  7 05:55:01 2010
@@ -22,7 +22,6 @@ package org.apache.synapse.transport.nht
 import org.apache.axiom.om.OMElement;
 import org.apache.axiom.soap.impl.llom.soap11.SOAP11Factory;
 import org.apache.axis2.AxisFault;
-import org.apache.axis2.Constants;
 import org.apache.axis2.addressing.EndpointReference;
 import org.apache.axis2.context.MessageContext;
 import org.apache.axis2.description.AxisService;
@@ -123,15 +122,17 @@ public class RESTUtil {
      * @param requestURI        The URL that the request came to
      * @param contentTypeHeader The contentType header of the request
      * @param httpMethod        The http method of the request
+     * @param dispatching   Weather we should do service dispatching
      * @throws AxisFault - Thrown in case a fault occurs
      */
     public static void processGetAndDeleteRequest(MessageContext msgContext, 
OutputStream out,
                                                   String requestURI, Header 
contentTypeHeader,
-                                                  String httpMethod) throws 
AxisFault {
+                                                  String httpMethod, boolean 
dispatching)
+            throws AxisFault {
 
         String contentType = contentTypeHeader != null ? 
contentTypeHeader.getValue() : null;
 
-        prepareMessageContext(msgContext, requestURI, httpMethod, out, 
contentType);
+        prepareMessageContext(msgContext, requestURI, httpMethod, out, 
contentType, dispatching);
 
         msgContext.setProperty(NhttpConstants.NO_ENTITY_BODY, Boolean.TRUE);
 
@@ -173,15 +174,17 @@ public class RESTUtil {
      * @param os                The output stream of the response
      * @param requestURI        The URL that the request came to
      * @param contentTypeHeader The contentType header of the request
+     * @param dispatching  Weather we should do dispatching
      * @throws AxisFault - Thrown in case a fault occurs
      */
     public static void processPOSTRequest(MessageContext msgContext, 
InputStream is,
                                           OutputStream os, String requestURI,
-                                          Header contentTypeHeader) throws 
AxisFault {
+                                          Header contentTypeHeader,
+                                          boolean dispatching) throws 
AxisFault {
 
         String contentType = contentTypeHeader != null ? 
contentTypeHeader.getValue() : null;
         prepareMessageContext(msgContext, requestURI, 
HTTPConstants.HTTP_METHOD_POST,
-                os, contentType);
+                os, contentType, dispatching);
         
org.apache.axis2.transport.http.util.RESTUtil.processXMLRequest(msgContext, is, 
os,
                 contentType);
     }
@@ -194,13 +197,15 @@ public class RESTUtil {
      * @param httpMethod  The http method of the request
      * @param out         The output stream of the response
      * @param contentType The content type of the request
+     * @param dispatching weather we should do dispatching
      * @throws AxisFault Thrown in case a fault occurs
      */
     private static void prepareMessageContext(MessageContext msgContext,
                                               String requestURI,
                                               String httpMethod,
                                               OutputStream out,
-                                              String contentType) throws 
AxisFault {
+                                              String contentType,
+                                              boolean dispatching) throws 
AxisFault {
 
         msgContext.setTo(new EndpointReference(requestURI));
         msgContext.setProperty(HTTPConstants.HTTP_METHOD, httpMethod);
@@ -217,14 +222,16 @@ public class RESTUtil {
         //  2) request is to be injected into  the main sequence  .i.e. 
http://localhost:8280
         // This method does not cause any performance issue ...
         // Proper fix should be refractoring axis2 RestUtil in a proper way
-        RequestURIBasedDispatcher requestDispatcher = new 
RequestURIBasedDispatcher();
-        AxisService axisService = requestDispatcher.findService(msgContext);
-        if (axisService == null) {
-            String defaultSvcName = 
NHttpConfiguration.getInstance().getStringValue(
-                    "nhttp.default.service", "__SynapseService");              
   
-            axisService = msgContext.getConfigurationContext()
-                    .getAxisConfiguration().getService(defaultSvcName);
+        if (dispatching) {
+            RequestURIBasedDispatcher requestDispatcher = new 
RequestURIBasedDispatcher();
+            AxisService axisService = 
requestDispatcher.findService(msgContext);
+            if (axisService == null) {
+                String defaultSvcName = 
NHttpConfiguration.getInstance().getStringValue(
+                        "nhttp.default.service", "__SynapseService");
+                axisService = msgContext.getConfigurationContext()
+                        .getAxisConfiguration().getService(defaultSvcName);
+            }
+            msgContext.setAxisService(axisService);
         }
-        msgContext.setAxisService(axisService);
     }
 }


Reply via email to