Author: ruwan
Date: Mon Aug 4 02:17:02 2008
New Revision: 682301
URL: http://svn.apache.org/viewvc?rev=682301&view=rev
Log:
committing for Saliya, SYNAPSE-412 with minor documentation changes
Modified:
synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/ServerWorker.java
synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/util/RESTUtil.java
Modified:
synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/ServerWorker.java
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/ServerWorker.java?rev=682301&r1=682300&r2=682301&view=diff
==============================================================================
---
synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/ServerWorker.java
(original)
+++
synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/ServerWorker.java
Mon Aug 4 02:17:02 2008
@@ -400,6 +400,25 @@
}
}
+ }
+ else if (serviceName != null && parameters.containsKey("info")) {
+ AxisService service = (AxisService) cfgCtx.getAxisConfiguration().
+ getServices().get(serviceName);
+ if (service != null) {
+ try {
+ response.addHeader(CONTENT_TYPE, TEXT_HTML);
+ serverHandler.commitResponse(conn, response);
+ os.write(HTTPTransportReceiver.printServiceHTML(
+ serviceName, cfgCtx).getBytes());
+
+ } catch (IOException e) {
+ handleException("Error writing service HTML to client", e);
+ return;
+ }
+ } else {
+ handleException("Invalid service : " + serviceName, null);
+ return;
+ }
} else if (serviceName == null || serviceName.length() == 0) {
try {
@@ -412,43 +431,19 @@
}
} else {
-
- if (parameters.isEmpty() && operation == null) {
- AxisService service = (AxisService)
cfgCtx.getAxisConfiguration().
- getServices().get(serviceName);
- if (service != null) {
- try {
- response.addHeader(CONTENT_TYPE, TEXT_HTML);
- serverHandler.commitResponse(conn, response);
- os.write(HTTPTransportReceiver.printServiceHTML(
- serviceName, cfgCtx).getBytes());
-
- } catch (IOException e) {
- handleException("Error writing service HTML to
client", e);
- return;
- }
- } else {
- handleException("Invalid service : " + serviceName, null);
- return;
- }
-
- } else {
- try {
-
- RESTUtil.processURLRequest(
- 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;
+ try {
+ RESTUtil.processURLRequest(
+ 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);
- }
+ } catch (AxisFault axisFault) {
+ handleException("Error processing GET request for: " +
+ request.getRequestLine().getUri(), axisFault);
}
-
}
// make sure that the output stream is flushed and closed properly
Modified:
synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/util/RESTUtil.java
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/util/RESTUtil.java?rev=682301&r1=682300&r2=682301&view=diff
==============================================================================
---
synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/util/RESTUtil.java
(original)
+++
synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/util/RESTUtil.java
Mon Aug 4 02:17:02 2008
@@ -82,36 +82,33 @@
firstElement =
messageContext.getEnvelope().getBody().getFirstElement();
String params = "";
-
if (firstElement != null) {
-
// first element corresponds to the operation name
address = address + "/" + firstElement.getLocalName();
+ } else {
+ firstElement = messageContext.getEnvelope().getBody();
+ }
- Iterator iter = firstElement.getChildElements();
+ Iterator iter = firstElement.getChildElements();
- String legalCharacters = WSDL2Constants
-
.LEGAL_CHARACTERS_IN_QUERY.replaceAll(queryParameterSeparator, "");
- StringBuffer buff = new StringBuffer(params);
-
- // iterate through the child elements and find the request
parameters
- while (iter.hasNext()) {
- OMElement element = (OMElement) iter.next();
- try {
-
buff.append(URIEncoderDecoder.quoteIllegal(element.getLocalName(),
-
legalCharacters)).append("=").append(URIEncoderDecoder.quoteIllegal(element.getText(),
- legalCharacters)).append(queryParameterSeparator);
- } catch (UnsupportedEncodingException e) {
- throw new AxisFault("URI Encoding error : " +
element.getLocalName()
- + "=" + element.getText(), e);
- }
+ String legalCharacters = WSDL2Constants
+ .LEGAL_CHARACTERS_IN_QUERY.replaceAll(queryParameterSeparator,
"");
+ StringBuffer buff = new StringBuffer(params);
+
+ // iterate through the child elements and find the request parameters
+ while (iter.hasNext()) {
+ OMElement element = (OMElement) iter.next();
+ try {
+
buff.append(URIEncoderDecoder.quoteIllegal(element.getLocalName(),
+
legalCharacters)).append("=").append(URIEncoderDecoder.quoteIllegal(element.getText(),
+ legalCharacters)).append(queryParameterSeparator);
+ } catch (UnsupportedEncodingException e) {
+ throw new AxisFault("URI Encoding error : " +
element.getLocalName()
+ + "=" + element.getText(), e);
}
-
- params = buff.toString();
- } else {
- throw new AxisFault("Cannot convert SOAP infoset to a GET
URL-encoded format");
}
+ params = buff.toString();
if (params.trim().length() != 0) {
int index = address.indexOf("?");
if (index == -1) {
@@ -130,7 +127,7 @@
/**
* Processes the HTTP GET request and builds the SOAP info-set of the REST
message
- *
+ *
* @param msgContext The MessageContext of the Request Message
* @param out The output stream of the response
* @param soapAction SoapAction of the request
@@ -141,9 +138,9 @@
* @throws AxisFault - Thrown in case a fault occurs
*/
public static boolean processURLRequest(MessageContext msgContext,
OutputStream out,
- String soapAction, String requestURI, ConfigurationContext
configurationContext,
- Map requestParameters) throws AxisFault {
-
+ String soapAction, String
requestURI, ConfigurationContext configurationContext,
+ Map requestParameters) throws
AxisFault {
+
if ((soapAction != null) && soapAction.startsWith("\"") &&
soapAction.endsWith("\"")) {
soapAction = soapAction.substring(1, soapAction.length() - 1);
}
@@ -168,7 +165,7 @@
/**
* Creates the [EMAIL PROTECTED] 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
@@ -176,7 +173,7 @@
* @throws AxisFault if the service represented by the GET request URL
cannot be found
*/
public static SOAPEnvelope createEnvelopeFromGetRequest(String requestUrl,
Map map,
- ConfigurationContext configCtx) throws AxisFault {
+
ConfigurationContext configCtx) throws AxisFault {
String[] values = Utils.parseRequestURLForServiceAndOperation(
requestUrl, configCtx.getServiceContextPath());
@@ -198,7 +195,13 @@
service.getSchemaTargetNamespacePrefix());
soapFactory.createOMNamespace(service.getSchemaTargetNamespace(),
service.getSchemaTargetNamespacePrefix());
- OMElement opElement = soapFactory.createOMElement(operation, omNs);
+ OMElement opElement;
+ if (operation.length() == 0) {
+ opElement = envelope.getBody();
+ } else {
+ opElement = soapFactory.createOMElement(operation, omNs);
+ envelope.getBody().addChild(opElement);
+ }
for (Object o : map.keySet()) {
String name = (String) o;
@@ -208,9 +211,6 @@
omEle.setText(value);
opElement.addChild(omEle);
}
-
- envelope.getBody().addChild(opElement);
-
return envelope;
} else {
return null;