You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-commits@axis.apache.org by su...@apache.org on 2011/07/29 08:07:56 UTC
svn commit: r1152116 - in /axis/axis2/java/core/trunk/modules:
kernel/src/org/apache/axis2/transport/
transport/http/src/org/apache/axis2/transport/http/
transport/http/src/org/apache/axis2/transport/http/util/
Author: supun
Date: Fri Jul 29 06:07:56 2011
New Revision: 1152116
URL: http://svn.apache.org/viewvc?rev=1152116&view=rev
Log:
adding some utility methods, to process the messages when the builder is explicitly given
Modified:
axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/transport/TransportUtils.java
axis/axis2/java/core/trunk/modules/transport/http/src/org/apache/axis2/transport/http/HTTPTransportUtils.java
axis/axis2/java/core/trunk/modules/transport/http/src/org/apache/axis2/transport/http/util/RESTUtil.java
Modified: axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/transport/TransportUtils.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/transport/TransportUtils.java?rev=1152116&r1=1152115&r2=1152116&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/transport/TransportUtils.java (original)
+++ axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/transport/TransportUtils.java Fri Jul 29 06:07:56 2011
@@ -129,13 +129,13 @@ public class TransportUtils {
* Objective of this method is to capture the SOAPEnvelope creation logic
* and make it a common for all the transports and to in/out flows.
*
- * @param msgContext
- * @param inStream
- * @param contentType
+ * @param msgContext message context
+ * @param inStream input stream
+ * @param contentType content type of the message
* @return the SOAPEnvelope
- * @throws AxisFault
- * @throws OMException
- * @throws XMLStreamException
+ * @throws AxisFault if an error occurs
+ * @throws OMException if the xml is invalid
+ * @throws XMLStreamException if the stream is invalid
* @throws FactoryConfigurationError
*/
public static SOAPEnvelope createSOAPMessage(MessageContext msgContext,
@@ -147,6 +147,30 @@ public class TransportUtils {
return createSOAPEnvelope(documentElement);
}
+ /**
+ * Objective of this method is to capture the SOAPEnvelope creation logic
+ * and make it a common for all the transports and to in/out flows.
+ *
+ * @param msgContext message context
+ * @param inStream input stream
+ * @param contentType content type of the message
+ * @param builder the builder to be used
+ * @return the SOAPEnvelope
+ * @throws AxisFault if an error occurs
+ * @throws OMException if the xml is invalid
+ * @throws XMLStreamException if the stream is invalid
+ * @throws FactoryConfigurationError
+ */
+ public static SOAPEnvelope createSOAPMessage(MessageContext msgContext,
+ InputStream inStream,
+ String contentType,
+ Builder builder)
+ throws AxisFault, OMException, XMLStreamException, FactoryConfigurationError {
+ OMElement documentElement = createDocumentElement(contentType, builder,
+ msgContext, inStream);
+ return createSOAPEnvelope(documentElement);
+ }
+
public static SOAPEnvelope createSOAPEnvelope(OMElement documentElement) {
SOAPEnvelope envelope;
// Check whether we have received a SOAPEnvelope or not
@@ -166,7 +190,8 @@ public class TransportUtils {
public static OMElement createDocumentElement(String contentType,
MessageContext msgContext,
- InputStream inStream) throws AxisFault, XMLStreamException {
+ InputStream inStream)
+ throws AxisFault, XMLStreamException {
OMElement documentElement = null;
String type = null;
if (contentType != null) {
@@ -181,23 +206,53 @@ public class TransportUtils {
}
}
if (documentElement == null) {
- if (msgContext.isDoingREST()) {
- if (log.isDebugEnabled()) {
- log.debug("Could not find a Builder for type (" + type + "). Using REST.");
- }
- OMXMLParserWrapper builder = BuilderUtil.createPOXBuilder(inStream, null);
- documentElement = builder.getDocumentElement();
- } else {
- // FIXME making soap defualt for the moment..might effect the
- // performance
- if (log.isDebugEnabled()) {
- log.debug("Could not find a Builder for type (" + type + "). Using SOAP.");
- }
- String charSetEnc = (String) msgContext
- .getProperty(Constants.Configuration.CHARACTER_SET_ENCODING);
- SOAPModelBuilder builder = BuilderUtil.createSOAPModelBuilder(inStream, charSetEnc);
- documentElement = builder.getDocumentElement();
+ documentElement = createDefaultDocumentElement(msgContext, inStream, type);
+ }
+ return documentElement;
+ }
+
+ private static OMElement createDefaultDocumentElement(MessageContext msgContext,
+ InputStream inStream, String type) {
+ OMElement documentElement;
+ if (msgContext.isDoingREST()) {
+ if (log.isDebugEnabled()) {
+ log.debug("Could not find a Builder for type (" + type + "). Using REST.");
}
+ OMXMLParserWrapper builder = BuilderUtil.createPOXBuilder(inStream, null);
+ documentElement = builder.getDocumentElement();
+ } else {
+ // FIXME making soap defualt for the moment..might effect the
+ // performance
+ if (log.isDebugEnabled()) {
+ log.debug("Could not find a Builder for type (" + type + "). Using SOAP.");
+ }
+ String charSetEnc = (String) msgContext
+ .getProperty(Constants.Configuration.CHARACTER_SET_ENCODING);
+ SOAPModelBuilder builder = BuilderUtil.createSOAPModelBuilder(inStream, charSetEnc);
+ documentElement = builder.getDocumentElement();
+ }
+ return documentElement;
+ }
+
+ public static OMElement createDocumentElement(String contentType, Builder builder,
+ MessageContext msgContext,
+ InputStream inStream)
+ throws AxisFault, XMLStreamException {
+ OMElement documentElement = null;
+ String type = null;
+ if (contentType != null) {
+ type = getContentType(contentType, msgContext);
+ if (builder != null) {
+ if (log.isDebugEnabled()) {
+ log.debug("createSOAPEnvelope using Builder (" +
+ builder.getClass() + ") selected from type (" + type +")");
+ }
+ documentElement = builder.processDocument(inStream, contentType, msgContext);
+ }
+ }
+
+ if (documentElement == null) {
+ documentElement = createDefaultDocumentElement(msgContext, inStream, type);
}
return documentElement;
}
Modified: axis/axis2/java/core/trunk/modules/transport/http/src/org/apache/axis2/transport/http/HTTPTransportUtils.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/transport/http/src/org/apache/axis2/transport/http/HTTPTransportUtils.java?rev=1152116&r1=1152115&r2=1152116&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/transport/http/src/org/apache/axis2/transport/http/HTTPTransportUtils.java (original)
+++ axis/axis2/java/core/trunk/modules/transport/http/src/org/apache/axis2/transport/http/HTTPTransportUtils.java Fri Jul 29 06:07:56 2011
@@ -32,6 +32,7 @@ import org.apache.axiom.soap.SOAPProcess
import org.apache.axis2.AxisFault;
import org.apache.axis2.Constants;
import org.apache.axis2.addressing.EndpointReference;
+import org.apache.axis2.builder.Builder;
import org.apache.axis2.builder.BuilderUtil;
import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.context.MessageContext;
@@ -63,7 +64,12 @@ public class HTTPTransportUtils {
private static final Log log = LogFactory.getLog(HTTPTransportUtils.class);
/**
+ * @param requestUrl the request url
+ * @param map the map of url parameters
+ * @param configCtx axis ConfigurationContext
* @deprecated This was used only by the now deprecated processHTTPGetRequest() method.
+ * @return the SOAPEnvelope object
+ * @throws org.apache.axis2.AxisFault if an error occurs
*/
public static SOAPEnvelope createEnvelopeFromGetRequest(String requestUrl,
Map map, ConfigurationContext configCtx)
@@ -189,6 +195,45 @@ public class HTTPTransportUtils {
}
}
+ public static InvocationResponse processHTTPPostRequest(MessageContext msgContext,
+ InputStream in,
+ OutputStream out,
+ String contentType,
+ Builder builder,
+ String soapActionHeader,
+ String requestURI)
+ throws AxisFault {
+ int soapVersion = VERSION_UNKNOWN;
+ try {
+ soapVersion = initializeMessageContext(msgContext, soapActionHeader,
+ requestURI, contentType);
+ msgContext.setProperty(MessageContext.TRANSPORT_OUT, out);
+
+ msgContext.setEnvelope(
+ TransportUtils.createSOAPMessage(
+ msgContext,
+ handleGZip(msgContext, in),
+ contentType, builder));
+ return AxisEngine.receive(msgContext);
+ } catch (SOAPProcessingException e) {
+ throw AxisFault.makeFault(e);
+ } catch (AxisFault e) {
+ throw e;
+ } catch (IOException e) {
+ throw AxisFault.makeFault(e);
+ } catch (OMException e) {
+ throw AxisFault.makeFault(e);
+ } catch (XMLStreamException e) {
+ throw AxisFault.makeFault(e);
+ } catch (FactoryConfigurationError e) {
+ throw AxisFault.makeFault(e);
+ } finally {
+ if ((msgContext.getEnvelope() == null) && soapVersion != VERSION_SOAP11) {
+ msgContext.setEnvelope(OMAbstractFactory.getSOAP12Factory().getDefaultEnvelope());
+ }
+ }
+ }
+
public static int initializeMessageContext(MessageContext msgContext,
String soapActionHeader,
String requestURI,
Modified: axis/axis2/java/core/trunk/modules/transport/http/src/org/apache/axis2/transport/http/util/RESTUtil.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/transport/http/src/org/apache/axis2/transport/http/util/RESTUtil.java?rev=1152116&r1=1152115&r2=1152116&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/transport/http/src/org/apache/axis2/transport/http/util/RESTUtil.java (original)
+++ axis/axis2/java/core/trunk/modules/transport/http/src/org/apache/axis2/transport/http/util/RESTUtil.java Fri Jul 29 06:07:56 2011
@@ -22,6 +22,7 @@ package org.apache.axis2.transport.http.
import org.apache.axiom.soap.SOAPEnvelope;
import org.apache.axis2.AxisFault;
import org.apache.axis2.Constants;
+import org.apache.axis2.builder.Builder;
import org.apache.axis2.builder.BuilderUtil;
import org.apache.axis2.context.MessageContext;
import org.apache.axis2.description.AxisBindingOperation;
@@ -89,6 +90,49 @@ public class RESTUtil {
return invokeAxisEngine(msgContext);
}
+ public static Handler.InvocationResponse processXMLRequest(MessageContext msgContext,
+ InputStream in,
+ OutputStream out, String contentType,
+ Builder builder)
+ throws AxisFault {
+ try {
+ msgContext.setDoingREST(true);
+ String charSetEncoding = BuilderUtil.getCharSetEncoding(contentType);
+ msgContext.setProperty(Constants.Configuration.CHARACTER_SET_ENCODING, charSetEncoding);
+ dispatchAndVerify(msgContext);
+ in = HTTPTransportUtils.handleGZip(msgContext, in);
+ SOAPEnvelope soapEnvelope;
+ if (msgContext.getAxisService() == null) {
+ soapEnvelope = TransportUtils.createSOAPEnvelope(null);
+ } else {
+ soapEnvelope = TransportUtils.createSOAPMessage(msgContext, in,
+ contentType, builder);
+ }
+
+ msgContext.setEnvelope(soapEnvelope);
+ msgContext.setProperty(Constants.Configuration.CONTENT_TYPE,
+ contentType);
+
+ msgContext.setProperty(MessageContext.TRANSPORT_OUT, out);
+
+ } catch (AxisFault axisFault) {
+ throw axisFault;
+ } catch (XMLStreamException e) {
+ throw AxisFault.makeFault(e);
+ } catch (IOException e) {
+ throw AxisFault.makeFault(e);
+ } finally {
+ String messageType =
+ (String) msgContext.getProperty(Constants.Configuration.MESSAGE_TYPE);
+ if (HTTPConstants.MEDIA_TYPE_X_WWW_FORM.equals(messageType) ||
+ HTTPConstants.MEDIA_TYPE_MULTIPART_FORM_DATA.equals(messageType)) {
+ msgContext.setProperty(Constants.Configuration.MESSAGE_TYPE,
+ HTTPConstants.MEDIA_TYPE_APPLICATION_XML);
+ }
+ }
+ return invokeAxisEngine(msgContext);
+ }
+
public static Handler.InvocationResponse processURLRequest(MessageContext msgContext,
OutputStream out, String contentType)
throws AxisFault {
@@ -110,7 +154,8 @@ public class RESTUtil {
SOAPEnvelope soapEnvelope;
if (msgContext.getAxisService() == null) {
soapEnvelope = TransportUtils.createSOAPEnvelope(null);
- msgContext.setProperty(Constants.Configuration.MESSAGE_TYPE, TransportUtils.getContentType(contentType, msgContext));
+ msgContext.setProperty(Constants.Configuration.MESSAGE_TYPE,
+ TransportUtils.getContentType(contentType, msgContext));
} else {
try {
soapEnvelope = TransportUtils.createSOAPMessage(msgContext, null, contentType);
@@ -139,6 +184,59 @@ public class RESTUtil {
return invokeAxisEngine(msgContext);
}
+ public static Handler.InvocationResponse processURLRequest(MessageContext msgContext,
+ OutputStream out,
+ String contentType, Builder builder)
+ throws AxisFault {
+ // here, only the parameters in the URI are supported. Others will be discarded.
+ try {
+
+ if (contentType == null || "".equals(contentType)) {
+ contentType = HTTPConstants.MEDIA_TYPE_X_WWW_FORM;
+ }
+
+ // set the required properties so that even if there is an error during the dispatch
+ // phase the response message will be passed to the client well.
+ msgContext.setDoingREST(true);
+ msgContext.setProperty(MessageContext.TRANSPORT_OUT, out);
+ String charSetEncoding = BuilderUtil.getCharSetEncoding(contentType);
+ msgContext.setProperty(Constants.Configuration.CHARACTER_SET_ENCODING, charSetEncoding);
+ // 1. First dispatchAndVerify and find out the service and the operation.
+ dispatchAndVerify(msgContext);
+ SOAPEnvelope soapEnvelope;
+ if (msgContext.getAxisService() == null) {
+ soapEnvelope = TransportUtils.createSOAPEnvelope(null);
+ msgContext.setProperty(Constants.Configuration.MESSAGE_TYPE,
+ TransportUtils.getContentType(contentType, msgContext));
+ } else {
+ try {
+ soapEnvelope = TransportUtils.createSOAPMessage(msgContext, null,
+ contentType, builder);
+ } catch (XMLStreamException e) {
+ throw AxisFault.makeFault(e);
+ }
+ }
+
+ msgContext.setEnvelope(soapEnvelope);
+
+
+ } catch (AxisFault axisFault) {
+ throw axisFault;
+ }
+ catch (IOException e) {
+ throw AxisFault.makeFault(e);
+ } finally {
+ String messageType =
+ (String) msgContext.getProperty(Constants.Configuration.MESSAGE_TYPE);
+ if (HTTPConstants.MEDIA_TYPE_X_WWW_FORM.equals(messageType) ||
+ HTTPConstants.MEDIA_TYPE_MULTIPART_FORM_DATA.equals(messageType)) {
+ msgContext.setProperty(Constants.Configuration.MESSAGE_TYPE,
+ HTTPConstants.MEDIA_TYPE_APPLICATION_XML);
+ }
+ }
+ return invokeAxisEngine(msgContext);
+ }
+
private static Handler.InvocationResponse invokeAxisEngine(MessageContext messageContext)
throws AxisFault {
return AxisEngine.receive(messageContext);