You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@synapse.apache.org by ru...@apache.org on 2009/06/14 18:05:16 UTC
svn commit: r784578 - in
/synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/nhttp:
HttpCoreNIOSender.java ServerWorker.java util/RESTUtil.java
Author: ruwan
Date: Sun Jun 14 16:05:16 2009
New Revision: 784578
URL: http://svn.apache.org/viewvc?rev=784578&view=rev
Log:
Commiting keith's patch with some modifications to fix the REST support in synapse
Modified:
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/nhttp/HttpCoreNIOSender.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/HttpCoreNIOSender.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/nhttp/HttpCoreNIOSender.java?rev=784578&r1=784577&r2=784578&view=diff
==============================================================================
--- synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/nhttp/HttpCoreNIOSender.java (original)
+++ synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/nhttp/HttpCoreNIOSender.java Sun Jun 14 16:05:16 2009
@@ -454,10 +454,10 @@
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)
|| Boolean.TRUE == noEntityBody) {
out.write(new byte[0]);
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=784578&r1=784577&r2=784578&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 Sun Jun 14 16:05:16 2009
@@ -246,7 +246,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,8 @@
}
} 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");
+ return;
}
// make sure that the output stream is flushed and closed properly
@@ -594,6 +583,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: 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=784578&r1=784577&r2=784578&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 Sun Jun 14 16:05:16 2009
@@ -35,6 +35,7 @@
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;
@@ -120,31 +121,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
- * @return boolean indication whether the operation was succesfull
+ * @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 {
+ public static void processGETRequest(MessageContext msgContext, OutputStream out,
+ String requestURI, Header contentTypeHeader)
+ throws AxisFault {
- if ((soapAction != null) && soapAction.startsWith("\"") && soapAction.endsWith("\"")) {
- soapAction = soapAction.substring(1, soapAction.length() - 1);
- }
-
- 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));
}
/**
@@ -177,57 +168,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;
}
}