Author: keith
Date: Tue Jun  2 23:37:44 2009
New Revision: 37553
URL: http://wso2.org/svn/browse/wso2?view=rev&revision=37553

Log:
Fixing https://wso2.org/jira/browse/CARBON-3931. This was a synapse Bug. Filed 
a JIRA there https://issues.apache.org/jira/browse/SYNAPSE-555. In the process 
of creating a patch for Synapse


Modified:
   
branches/synapse/1.3-wso2v1/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/nhttp/ServerWorker.java
   
branches/synapse/1.3-wso2v1/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/nhttp/util/RESTUtil.java

Modified: 
branches/synapse/1.3-wso2v1/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/nhttp/ServerWorker.java
URL: 
http://wso2.org/svn/browse/wso2/branches/synapse/1.3-wso2v1/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/nhttp/ServerWorker.java?rev=37553&r1=37552&r2=37553&view=diff
==============================================================================
--- 
branches/synapse/1.3-wso2v1/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/nhttp/ServerWorker.java
        (original)
+++ 
branches/synapse/1.3-wso2v1/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/nhttp/ServerWorker.java
        Tue Jun  2 23:37:44 2009
@@ -244,7 +244,7 @@
         } else if ("OPTIONS".equals(method)) {
             processNonEntityEnclosingMethod();
         } else if ("DELETE".equals(method)) {
-            processNonEntityEnclosingMethod();
+            processGetAndDelete("DELETE");
         } else if ("TRACE".equals(method)) {
             processNonEntityEnclosingMethod();
         } else {
@@ -572,19 +572,7 @@
             }
 
         } else {
-            try {
-                RESTUtil.processGETRequest(
-                        msgContext, os, (request.getFirstHeader(SOAPACTION) != 
null ?
-                        request.getFirstHeader(SOAPACTION).getValue() : null),
-                        request.getRequestLine().getUri(), cfgCtx, parameters);
-                // do not let the output stream close (as by default below) 
since
-                // we are serving this GET request through the Synapse engine
-                return;
-                
-            } catch (AxisFault axisFault) {
-                handleException("Error processing GET request for: " +
-                        request.getRequestLine().getUri(), axisFault);
-            }
+            processGetAndDelete("GET");
         }
 
         // make sure that the output stream is flushed and closed properly
@@ -594,6 +582,23 @@
         } catch (IOException ignore) {}
     }
 
+    /**
+     * Calls the RESTUtil to process GET and DELETE Request
+     */
+    private void processGetAndDelete(String method) {
+        try {
+            RESTUtil.processGETRequest(
+                    msgContext, os, request.getRequestLine().getUri(),
+                    request.getFirstHeader(HTTP.CONTENT_TYPE));
+            // 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) {
+            handleException("Error processing " + method + " request for: " +
+                    request.getRequestLine().getUri(), axisFault);
+        }
+
+    }
+
     private void handleBrowserException(String msg, Exception e) {
 
         if (e == null) {

Modified: 
branches/synapse/1.3-wso2v1/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/nhttp/util/RESTUtil.java
URL: 
http://wso2.org/svn/browse/wso2/branches/synapse/1.3-wso2v1/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/nhttp/util/RESTUtil.java?rev=37553&r1=37552&r2=37553&view=diff
==============================================================================
--- 
branches/synapse/1.3-wso2v1/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/nhttp/util/RESTUtil.java
       (original)
+++ 
branches/synapse/1.3-wso2v1/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/nhttp/util/RESTUtil.java
       Tue Jun  2 23:37:44 2009
@@ -20,26 +20,20 @@
 package org.apache.synapse.transport.nhttp.util;
 
 import org.apache.axiom.om.OMElement;
-import org.apache.axiom.om.OMNamespace;
-import org.apache.axiom.soap.SOAPEnvelope;
-import org.apache.axiom.soap.SOAPFactory;
 import org.apache.axiom.soap.impl.llom.soap11.SOAP11Factory;
 import org.apache.axis2.AxisFault;
 import org.apache.axis2.addressing.EndpointReference;
-import org.apache.axis2.context.ConfigurationContext;
 import org.apache.axis2.context.MessageContext;
-import org.apache.axis2.description.AxisService;
 import org.apache.axis2.description.WSDL20DefaultValueHolder;
 import org.apache.axis2.description.WSDL2Constants;
 import org.apache.axis2.engine.AxisEngine;
 import org.apache.axis2.transport.http.util.URIEncoderDecoder;
-import org.apache.axis2.util.Utils;
 import org.apache.synapse.transport.nhttp.NhttpConstants;
+import org.apache.http.Header;
 
 import java.io.OutputStream;
 import java.io.UnsupportedEncodingException;
 import java.util.Iterator;
-import java.util.Map;
 
 /**
  * This class provides a set of utility methods to manage the REST invocation 
calls
@@ -120,30 +114,21 @@
      *
      * @param msgContext The MessageContext of the Request Message
      * @param out The output stream of the response
-     * @param soapAction SoapAction of the request
      * @param requestURI The URL that the request came to
-     * @param configurationContext The Axis Configuration Context
-     * @param requestParameters The parameters of the request message
+     * @param contentTypeHeader The contentType header of the request
      * @throws AxisFault - Thrown in case a fault occurs
      */
-    public static void processGETRequest(MessageContext msgContext, 
OutputStream out,
-                                            String soapAction, String 
requestURI,
-                                            ConfigurationContext 
configurationContext,
-                                            Map requestParameters) throws 
AxisFault {
-
-        if ((soapAction != null) && soapAction.startsWith("\"") && 
soapAction.endsWith("\"")) {
-            soapAction = soapAction.substring(1, soapAction.length() - 1);
-        }
+    public static void processGETRequest(MessageContext msgContext, 
OutputStream out, 
+                                         String requestURI, Header 
contentTypeHeader)
+            throws AxisFault {
 
-        msgContext.setSoapAction(soapAction);
         msgContext.setTo(new EndpointReference(requestURI));
         msgContext.setProperty(MessageContext.TRANSPORT_OUT, out);
         msgContext.setServerSide(true);
         msgContext.setDoingREST(true);
-        msgContext.setEnvelope(createEnvelopeFromGetRequest(
-                requestURI, requestParameters, configurationContext));
         msgContext.setProperty(NhttpConstants.NO_ENTITY_BODY, Boolean.TRUE);
-        AxisEngine.receive(msgContext);
+        
org.apache.axis2.transport.http.util.RESTUtil.processURLRequest(msgContext, out,
+                getContentType(contentTypeHeader));
     }
 
     /**
@@ -172,57 +157,16 @@
     }
 
     /**
-     * Creates the {...@link SOAPEnvelope} from the GET URL request. REST 
message building inside
-     * synapse will be handled in this manner
-     *
-     * @param requestUrl GET URL of the request
-     * @param map query parameters of the GET request
-     * @param configCtx axis configuration context
-     * @return created SOAPEnvelope or null if cannot be processed
-     * @throws AxisFault if the service represented by the GET request URL 
cannot be found
+     * Given the contentType HTTP header it extracts the content-type of the 
request
      */
-    private static SOAPEnvelope createEnvelopeFromGetRequest(String 
requestUrl, Map map,
-                                                            
ConfigurationContext configCtx) throws AxisFault {
-
-        String[] values = Utils.parseRequestURLForServiceAndOperation(
-                requestUrl, configCtx.getServiceContextPath());
-
-        if (values == null) {
-            return new SOAP11Factory().getDefaultEnvelope();
-        }
-
-        if ((values[1] != null) && (values[0] != null)) {
-            String srvice = values[0];
-            AxisService service = 
configCtx.getAxisConfiguration().getService(srvice);
-            if (service == null) {
-                throw new AxisFault("service not found: " + srvice);
-            }
-            String operation = values[1];
-            SOAPFactory soapFactory = new SOAP11Factory();
-            SOAPEnvelope envelope = soapFactory.getDefaultEnvelope();
-            OMNamespace omNs = 
soapFactory.createOMNamespace(service.getSchemaTargetNamespace(),
-                    service.getSchemaTargetNamespacePrefix());
-            soapFactory.createOMNamespace(service.getSchemaTargetNamespace(),
-                    service.getSchemaTargetNamespacePrefix());
-            OMElement opElement;
-            if (operation.length() == 0) {
-                opElement = envelope.getBody();
-            } else {
-                opElement = soapFactory.createOMElement(operation, omNs);
-                envelope.getBody().addChild(opElement);
+    private static String getContentType(Header contentTypeHeader) {
+        String contentTypeStr = contentTypeHeader != null ? 
contentTypeHeader.getValue() : null;
+        if (contentTypeStr != null) {
+            int index = contentTypeStr.indexOf(';');
+            if (index > 0) {
+                contentTypeStr = contentTypeStr.substring(0, index);
             }
-
-            for (Object o : map.keySet()) {
-                String name = (String) o;
-                String value = (String) map.get(name);
-                OMElement omEle = soapFactory.createOMElement(name, omNs);
-
-                omEle.setText(value);
-                opElement.addChild(omEle);
-            }
-            return envelope;
-        } else {
-            return null;
         }
+        return contentTypeStr;
     }
 }

_______________________________________________
Esb-java-dev mailing list
[email protected]
https://wso2.org/cgi-bin/mailman/listinfo/esb-java-dev

Reply via email to