You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by th...@apache.org on 2005/06/29 10:53:44 UTC
svn commit: r202338 - in /webservices/axis/trunk/java/modules:
core/src/org/apache/axis/ core/src/org/apache/axis/transport/
core/src/org/apache/axis/transport/http/ xml/src/org/apache/axis/om/
Author: thilina
Date: Wed Jun 29 01:53:42 2005
New Revision: 202338
URL: http://svn.apache.org/viewcvs?rev=202338&view=rev
Log:
Integrating MTOM for transport sender
Modified:
webservices/axis/trunk/java/modules/core/src/org/apache/axis/Constants.java
webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/AbstractTransportSender.java
webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/http/HTTPTransportSender.java
webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/http/HTTPTransportUtils.java
webservices/axis/trunk/java/modules/xml/src/org/apache/axis/om/OMOutput.java
Modified: webservices/axis/trunk/java/modules/core/src/org/apache/axis/Constants.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/core/src/org/apache/axis/Constants.java?rev=202338&r1=202337&r2=202338&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/core/src/org/apache/axis/Constants.java (original)
+++ webservices/axis/trunk/java/modules/core/src/org/apache/axis/Constants.java Wed Jun 29 01:53:42 2005
@@ -170,10 +170,12 @@
public static final String MTOM_CONTENT_TYPE = "multipart/related";
}
- public static interface Configuration {
+ public static interface Configuration {
public static final String DO_REST = "doREST";
- public static final String ENABLE_REST = "eanbleREST";
- public static final String ENABLE_MTOM = "eanbleMTOM";
+ public static final String ENABLE_REST = "enableREST";
+ // globally enable MTOM
+ public static final String ENABLE_MTOM = "enableMTOM";
+ //set after checking the Envelope & ENABLE_MTOM
public static final String DO_MTOM = "doMTOM";
}
public static final String VALUE_TRUE = "true";
Modified: webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/AbstractTransportSender.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/AbstractTransportSender.java?rev=202338&r1=202337&r2=202338&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/AbstractTransportSender.java (original)
+++ webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/AbstractTransportSender.java Wed Jun 29 01:53:42 2005
@@ -1,18 +1,18 @@
/*
-* Copyright 2004,2005 The Apache Software Foundation.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package org.apache.axis.transport;
import java.io.OutputStream;
@@ -36,118 +36,143 @@
import org.apache.commons.logging.LogFactory;
/**
- * By the time this Class is invoked either the To EPR on the MessageContext should be set or
- * TRANSPORT_WRITER property set in the message Context with a Writer. This Class would write the
- * SOAPMessage using either of the methods in the order To then Writer.
+ * By the time this Class is invoked either the To EPR on the MessageContext
+ * should be set or TRANSPORT_WRITER property set in the message Context with a
+ * Writer. This Class would write the SOAPMessage using either of the methods in
+ * the order To then Writer.
*/
-public abstract class AbstractTransportSender extends AbstractHandler implements TransportSender {
- /**
- * Field log
- */
- private Log log = LogFactory.getLog(getClass());
- protected boolean doREST = false;
-
- /**
- * Field NAME
- */
- public static final QName NAME = new QName("http://axis.ws.apache.org", "TransportSender");
-
- /**
- * Constructor AbstractTransportSender
- */
- public AbstractTransportSender() {
- init(new HandlerDescription(NAME));
- }
-
- public void init(ConfigurationContext confContext,TransportOutDescription transportOut)throws AxisFault{
-
- }
-
- /**
- * Method invoke
- *
- * @param msgContext
- * @throws AxisFault
- */
- public void invoke(MessageContext msgContext) throws AxisFault {
- //Check for the REST behaviour, if you desire rest beahaviour
- //put a <parameter name="doREST" value="true"/> at the axis2.xml
- Object doREST = msgContext.getProperty(Constants.Configuration.DO_REST);
- if (doREST != null && Constants.VALUE_TRUE.equals(doREST)) {
- this.doREST = true;
- }
-
- OutputStream out = null;
-
- EndpointReference epr = null;
-
- if (msgContext.getTo() != null
- && !AddressingConstants.Submission.WSA_ANONYMOUS_URL.equals(msgContext.getTo().getAddress())
- && !AddressingConstants.Final.WSA_ANONYMOUS_URL.equals(msgContext.getTo().getAddress())) {
- epr = msgContext.getTo();
- }
-
- if (epr != null) {
- out = openTheConnection(epr,msgContext);
- OutputStream newOut = startSendWithToAddress(msgContext, out);
- if(newOut != null){
- out = newOut;
- }
- writeMessage(msgContext, out);
- finalizeSendWithToAddress(msgContext,out);
- } else {
- out = (OutputStream) msgContext.getProperty(MessageContext.TRANSPORT_OUT);
- if (out != null) {
- startSendWithOutputStreamFromIncomingConnection(msgContext, out);
- writeMessage(msgContext, out);
- finalizeSendWithOutputStreamFromIncomingConnection(msgContext,out);
- } else {
- throw new AxisFault("Both the TO and Property MessageContext.TRANSPORT_WRITER is Null, No where to send");
- }
- }
- //TODO fix this, we do not set the value if the operation context is not avalible
- if(msgContext.getOperationContext()!= null){
- msgContext.getOperationContext().setProperty(Constants.RESPONSE_WRITTEN, Constants.VALUE_TRUE);
- }
- }
-
- public void writeMessage(MessageContext msgContext, OutputStream out) throws AxisFault {
- SOAPEnvelope envelope = msgContext.getEnvelope();
- OMElement outputMessage = envelope;
-
- if (envelope != null && this.doREST) {
- outputMessage = envelope.getBody().getFirstElement();
- }
-
- if (outputMessage != null) {
- OMOutput omOutput = null;
- try {
- omOutput = new OMOutput(XMLOutputFactory.newInstance().createXMLStreamWriter(out));
- outputMessage.serialize(omOutput);
- omOutput.flush();
- out.flush();
- } catch (Exception e) {
- throw new AxisFault("Stream error", e);
- }
- } else {
- throw new AxisFault("the OUTPUT message is Null, nothing to write");
- }
- }
-
- public abstract OutputStream startSendWithToAddress(MessageContext msgContext, OutputStream out)
- throws AxisFault;
-
- public abstract void finalizeSendWithToAddress(MessageContext msgContext,OutputStream out)
- throws AxisFault;
-
-
- public abstract OutputStream startSendWithOutputStreamFromIncomingConnection(MessageContext msgContext,
- OutputStream out)
- throws AxisFault;
-
- public abstract void finalizeSendWithOutputStreamFromIncomingConnection(MessageContext msgContext,OutputStream out)
- throws AxisFault;
-
-
- protected abstract OutputStream openTheConnection(EndpointReference epr,MessageContext msgctx) throws AxisFault;
-}
+public abstract class AbstractTransportSender extends AbstractHandler implements
+ TransportSender {
+ /**
+ * Field log
+ */
+ private Log log = LogFactory.getLog(getClass());
+
+ protected boolean doREST = false;
+
+ /**
+ * Field NAME
+ */
+ public static final QName NAME = new QName("http://axis.ws.apache.org",
+ "TransportSender");
+
+ /**
+ * Constructor AbstractTransportSender
+ */
+ public AbstractTransportSender() {
+ init(new HandlerDescription(NAME));
+ }
+
+ public void init(ConfigurationContext confContext,
+ TransportOutDescription transportOut) throws AxisFault {
+
+ }
+
+ /**
+ * Method invoke
+ *
+ * @param msgContext
+ * @throws AxisFault
+ */
+ public void invoke(MessageContext msgContext) throws AxisFault {
+ //Check for the REST behaviour, if you desire rest beahaviour
+ //put a <parameter name="doREST" value="true"/> at the axis2.xml
+ Object doREST = msgContext.getProperty(Constants.Configuration.DO_REST);
+ if (doREST != null && Constants.VALUE_TRUE.equals(doREST)) {
+ this.doREST = true;
+ }
+
+ OutputStream out = null;
+
+ EndpointReference epr = null;
+
+ if (msgContext.getTo() != null
+ && !AddressingConstants.Submission.WSA_ANONYMOUS_URL
+ .equals(msgContext.getTo().getAddress())
+ && !AddressingConstants.Final.WSA_ANONYMOUS_URL
+ .equals(msgContext.getTo().getAddress())) {
+ epr = msgContext.getTo();
+ }
+
+ if (epr != null) {
+ out = openTheConnection(epr, msgContext);
+ OutputStream newOut = startSendWithToAddress(msgContext, out);
+ if (newOut != null) {
+ out = newOut;
+ }
+ writeMessage(msgContext, out);
+ finalizeSendWithToAddress(msgContext, out);
+ } else {
+ out = (OutputStream) msgContext
+ .getProperty(MessageContext.TRANSPORT_OUT);
+ if (out != null) {
+ startSendWithOutputStreamFromIncomingConnection(msgContext, out);
+ writeMessage(msgContext, out);
+ finalizeSendWithOutputStreamFromIncomingConnection(msgContext,
+ out);
+ } else {
+ throw new AxisFault(
+ "Both the TO and Property MessageContext.TRANSPORT_WRITER is Null, No where to send");
+ }
+ }
+ //TODO fix this, we do not set the value if the operation context is
+ // not avalible
+ if (msgContext.getOperationContext() != null) {
+ msgContext.getOperationContext().setProperty(
+ Constants.RESPONSE_WRITTEN, Constants.VALUE_TRUE);
+ }
+ }
+
+ public void writeMessage(MessageContext msgContext, OutputStream out)
+ throws AxisFault {
+ SOAPEnvelope envelope = msgContext.getEnvelope();
+ OMElement outputMessage = envelope;
+
+ if (envelope != null && this.doREST) {
+ outputMessage = envelope.getBody().getFirstElement();
+ }
+
+ if (outputMessage != null) {
+ OMOutput omOutput = null;
+
+ boolean doMTOM = false;
+ if (msgContext.getProperty(Constants.Configuration.DO_MTOM)!=null) {
+ doMTOM = ((Boolean) msgContext
+ .getProperty(Constants.Configuration.DO_MTOM))
+ .booleanValue();
+ }
+ try {
+ if (doMTOM) {
+ omOutput = new OMOutput(out, true);
+ outputMessage.serialize(omOutput);
+ omOutput.flush();
+ out.flush();
+ } else {
+ omOutput = new OMOutput(out, false);
+ outputMessage.serialize(omOutput);
+ omOutput.flush();
+ out.flush();
+ }
+ } catch (Exception e) {
+ throw new AxisFault("Stream error", e);
+ }
+ } else {
+ throw new AxisFault("the OUTPUT message is Null, nothing to write");
+ }
+ }
+
+ public abstract OutputStream startSendWithToAddress(
+ MessageContext msgContext, OutputStream out) throws AxisFault;
+
+ public abstract void finalizeSendWithToAddress(MessageContext msgContext,
+ OutputStream out) throws AxisFault;
+
+ public abstract OutputStream startSendWithOutputStreamFromIncomingConnection(
+ MessageContext msgContext, OutputStream out) throws AxisFault;
+
+ public abstract void finalizeSendWithOutputStreamFromIncomingConnection(
+ MessageContext msgContext, OutputStream out) throws AxisFault;
+
+ protected abstract OutputStream openTheConnection(EndpointReference epr,
+ MessageContext msgctx) throws AxisFault;
+}
\ No newline at end of file
Modified: webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/http/HTTPTransportSender.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/http/HTTPTransportSender.java?rev=202338&r1=202337&r2=202338&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/http/HTTPTransportSender.java (original)
+++ webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/http/HTTPTransportSender.java Wed Jun 29 01:53:42 2005
@@ -26,6 +26,8 @@
import java.net.URL;
import java.util.Map;
+import javax.servlet.http.HttpUtils;
+
import org.apache.axis.Constants;
import org.apache.axis.addressing.EndpointReference;
import org.apache.axis.context.ConfigurationContext;
@@ -33,6 +35,7 @@
import org.apache.axis.description.Parameter;
import org.apache.axis.description.TransportOutDescription;
import org.apache.axis.engine.AxisFault;
+import org.apache.axis.om.OMOutput;
import org.apache.axis.transport.AbstractTransportSender;
/**
@@ -51,15 +54,22 @@
int contentLength)
throws AxisFault {
try {
- String soapAction = msgContext.getSoapAction();
- soapAction = (soapAction!= null)?soapAction:msgContext.getWSAAction();
- soapAction = (soapAction == null)? "" : soapAction.toString();
+ Object soapAction = msgContext.getWSAAction();
+ String soapActionString =
+ soapAction == null ? "" : soapAction.toString();
+ boolean enableMTOM = false;
+ if (msgContext.getProperty(Constants.Configuration.ENABLE_MTOM)!=null)
+ {
+ enableMTOM = Constants.VALUE_TRUE.equals(msgContext.getProperty(Constants.Configuration.ENABLE_MTOM));
+ }
+ boolean envelopeContainsOptimise = HTTPTransportUtils.checkEnvelopeForOptimise(msgContext.getEnvelope());
+ boolean doMTOM = enableMTOM && envelopeContainsOptimise;
+ msgContext.setProperty(Constants.Configuration.DO_MTOM,new Boolean(doMTOM));
StringBuffer buf = new StringBuffer();
buf.append(HTTPConstants.HEADER_POST).append(" ");
buf.append(url.getFile()).append(" ").append(httpVersion).append("\n");
if(doMTOM){
- //TODO fix this for MTOM
- buf.append(HTTPConstants.HEADER_CONTENT_TYPE).append(": ").append("multipart/related").append("\n");
+ buf.append(HTTPConstants.HEADER_CONTENT_TYPE).append(": ").append(OMOutput.getContentType(true)).append("\n");
}else{
buf.append(HTTPConstants.HEADER_CONTENT_TYPE).append(": text/xml; charset=utf-8\n");
}
@@ -78,7 +88,7 @@
buf.append(HTTPConstants.HEADER_CONTENT_LENGTH).append(": " + contentLength + "\n");
}
if (!this.doREST) {
- buf.append("SOAPAction: \"" + soapAction + "\"\n");
+ buf.append("SOAPAction: \"" + soapActionString + "\"\n");
}
buf.append("\n");
out.write(buf.toString().getBytes());
@@ -251,7 +261,13 @@
}
- public void init(ConfigurationContext confContext,TransportOutDescription transportOut) throws AxisFault {
+ /* (non-Javadoc)
+ * @see org.apache.axis.transport.TransportSender#init(org.apache.axis.context.ConfigurationContext, org.apache.axis.description.TransportOutDescription)
+ */
+ public void init(
+ ConfigurationContext confContext,
+ TransportOutDescription transportOut)
+ throws AxisFault {
//<parameter name="PROTOCOL" locked="xsd:false">HTTP/1.0</parameter> or
//<parameter name="PROTOCOL" locked="xsd:false">HTTP/1.1</parameter> is checked
Parameter version =
Modified: webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/http/HTTPTransportUtils.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/http/HTTPTransportUtils.java?rev=202338&r1=202337&r2=202338&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/http/HTTPTransportUtils.java (original)
+++ webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/http/HTTPTransportUtils.java Wed Jun 29 01:53:42 2005
@@ -1,230 +1,232 @@
-/*
- * Copyright 2004,2005 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * Runtime state of the engine
- */
-package org.apache.axis.transport.http;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.OutputStream;
-import java.io.Reader;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.StringTokenizer;
-
-import javax.xml.parsers.FactoryConfigurationError;
-import javax.xml.stream.XMLInputFactory;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamReader;
-
-import org.apache.axis.Constants;
-import org.apache.axis.addressing.AddressingConstants;
-import org.apache.axis.addressing.EndpointReference;
-import org.apache.axis.attachments.MIMEHelper;
-import org.apache.axis.context.ConfigurationContext;
-import org.apache.axis.context.MessageContext;
-import org.apache.axis.engine.AxisEngine;
-import org.apache.axis.engine.AxisFault;
-import org.apache.axis.om.OMElement;
-import org.apache.axis.om.OMException;
-import org.apache.axis.om.OMNamespace;
-import org.apache.axis.om.OMNode;
-import org.apache.axis.om.OMText;
-import org.apache.axis.om.impl.llom.OMNamespaceImpl;
-import org.apache.axis.om.impl.llom.builder.StAXBuilder;
-import org.apache.axis.om.impl.llom.builder.StAXOMBuilder;
-import org.apache.axis.om.impl.llom.mtom.MTOMStAXSOAPModelBuilder;
-import org.apache.axis.soap.SOAPEnvelope;
-import org.apache.axis.soap.SOAPFactory;
-import org.apache.axis.soap.impl.llom.SOAPProcessingException;
-import org.apache.axis.soap.impl.llom.builder.StAXSOAPModelBuilder;
-import org.apache.axis.soap.impl.llom.soap11.SOAP11Factory;
-import org.apache.axis.util.Utils;
-
-public class HTTPTransportUtils {
-
- public static void processHTTPPostRequest(
- MessageContext msgContext,
- InputStream in,
- OutputStream out,
- String contentType,
- String soapAction,
- String requestURI,
- ConfigurationContext configurationContext)
- throws AxisFault {
-
- try {
- msgContext.setWSAAction(soapAction);
- msgContext.setSoapAction(soapAction);
- msgContext.setTo(new EndpointReference(AddressingConstants.WSA_TO, requestURI));
- msgContext.setProperty(MessageContext.TRANSPORT_OUT, out);
- msgContext.setServerSide(true);
-
- SOAPEnvelope envelope = null;
- StAXBuilder builder = null;
- Reader reader = new InputStreamReader(in);
- XMLStreamReader xmlreader =
- XMLInputFactory.newInstance().createXMLStreamReader(reader);
-
-
- StringTokenizer st = new StringTokenizer(contentType);
-
- String mimetype = null;
- if (st.hasMoreTokens()){
- mimetype = st.nextToken();
- }
-
- if (HTTPConstants.HEADER_ACCEPT_MULTIPART_RELATED.equalsIgnoreCase(mimetype)) {
- builder = selectBuilderForMIME(msgContext,in,contentType);
- envelope = (SOAPEnvelope) builder.getDocumentElement();
- } else if (
- contentType != null && contentType.indexOf(Constants.SOAP.SOAP_11_CONTENT_TYPE) > -1) {
- if ((soapAction == null || soapAction.length() == 0)
- && Constants.VALUE_TRUE.equals(
- msgContext.getProperty(Constants.Configuration.ENABLE_REST))) {
- msgContext.setProperty(Constants.Configuration.DO_REST, Constants.VALUE_TRUE);
- SOAPFactory soapFactory = new SOAP11Factory();
- builder = new StAXOMBuilder(xmlreader);
- builder.setOmbuilderFactory(soapFactory);
- envelope = soapFactory.getDefaultEnvelope();
- envelope.getBody().addChild(builder.getDocumentElement());
- }
- }
-
- if(envelope == null){
- builder = new StAXSOAPModelBuilder(xmlreader);
- envelope = (SOAPEnvelope) builder.getDocumentElement();
- }
-
- msgContext.setEnvelope(envelope);
- AxisEngine engine = new AxisEngine(configurationContext);
- engine.receive(msgContext);
- } catch (SOAPProcessingException e) {
- throw new AxisFault(e);
- } catch (OMException e) {
- throw new AxisFault(e);
- } catch (XMLStreamException e) {
- throw new AxisFault(e);
- }
- }
-
- public static boolean processHTTPGetRequest(
- MessageContext msgContext,
- InputStream in,
- OutputStream out,
- String contentType,
- String soapAction,
- String requestURI,
- ConfigurationContext configurationContext,Map requestParameters) throws AxisFault {
- msgContext.setWSAAction(soapAction);
- msgContext.setSoapAction(soapAction);
- msgContext.setTo(new EndpointReference(AddressingConstants.WSA_TO, requestURI));
- msgContext.setProperty(MessageContext.TRANSPORT_OUT, out);
- msgContext.setServerSide(true);
- try {
- SOAPEnvelope envelope =
- HTTPTransportUtils.createEnvelopeFromGetRequest(
- requestURI,
- requestParameters);
- if (envelope == null) {
- return false;
- } else {
- msgContext.setProperty(Constants.Configuration.DO_REST, Constants.VALUE_TRUE);
- msgContext.setEnvelope(envelope);
- AxisEngine engine = new AxisEngine(configurationContext);
- engine.receive(msgContext);
- return true;
- }
- }catch (IOException e) {
- throw new AxisFault(e);
- }
- }
- public static final SOAPEnvelope createEnvelopeFromGetRequest(String requestUrl, Map map) {
- String[] values = Utils.parseRequestURLForServiceAndOperation(requestUrl);
-
- if (values[1] != null && values[0] != null) {
- String operation = values[1];
- SOAPFactory soapFactory = new SOAP11Factory();
- SOAPEnvelope envelope = soapFactory.getDefaultEnvelope();
-
- OMNamespace omNs = soapFactory.createOMNamespace(values[0], "services");
- OMNamespace defualtNs = new OMNamespaceImpl("", null);
-
- OMElement opElement = soapFactory.createOMElement(operation, omNs);
-
- Iterator it = map.keySet().iterator();
- while (it.hasNext()) {
- String name = (String) it.next();
- String value = (String) map.get(name);
- OMElement omEle = soapFactory.createOMElement(name, defualtNs);
- omEle.setText(value);
- opElement.addChild(omEle);
- }
-
- envelope.getBody().addChild(opElement);
- return envelope;
- } else {
- return null;
- }
- }
- public static StAXBuilder selectBuilderForMIME(MessageContext msgContext, InputStream inStream,String contentTypeString) throws OMException, XMLStreamException, FactoryConfigurationError
- {
- StAXBuilder builder = null;
- MIMEHelper mimeHelper = new MIMEHelper(inStream, contentTypeString);
- XMLStreamReader reader = XMLInputFactory
- .newInstance()
- .createXMLStreamReader(
- new BufferedReader(
- new InputStreamReader(mimeHelper
- .getSOAPPartInputStream())));
- /*
- * put a reference to Attachments in to the message context
- */
- msgContext.setProperty("Attachments", mimeHelper);
- if (mimeHelper.getAttachmentSpecType().equals(
- MIMEHelper.MTOM_TYPE)) {
- /*
- * Creates the MTOM specific MTOMStAXSOAPModelBuilder
- */
- builder = new MTOMStAXSOAPModelBuilder(reader,
- mimeHelper);
- } else if (mimeHelper.getAttachmentSpecType().equals(
- MIMEHelper.SWA_TYPE)) {
- builder = new StAXSOAPModelBuilder(reader);
- }
- return builder;
- }
-
- public boolean checkEnvelopeForOptimise(SOAPEnvelope envelope)
- {
- return isOptimised(envelope);
- }
-
- private boolean isOptimised(OMElement element) {
- Iterator childrenIter = element.getChildren();
- while(childrenIter.hasNext()){
- OMNode node = (OMNode) childrenIter.next();
- if( OMNode.TEXT_NODE == node.getType() && ((OMText)node).isOptimized()){
- return true;
- }else if (OMNode.ELEMENT_NODE == node.getType()) {
- return isOptimised((OMElement) node);
- }
- }
- return false;
- }
-}
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Runtime state of the engine
+ */
+package org.apache.axis.transport.http;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.io.Reader;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.StringTokenizer;
+
+import javax.xml.parsers.FactoryConfigurationError;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.axis.Constants;
+import org.apache.axis.addressing.AddressingConstants;
+import org.apache.axis.addressing.EndpointReference;
+import org.apache.axis.attachments.MIMEHelper;
+import org.apache.axis.context.ConfigurationContext;
+import org.apache.axis.context.MessageContext;
+import org.apache.axis.engine.AxisEngine;
+import org.apache.axis.engine.AxisFault;
+import org.apache.axis.om.OMElement;
+import org.apache.axis.om.OMException;
+import org.apache.axis.om.OMNamespace;
+import org.apache.axis.om.OMNode;
+import org.apache.axis.om.OMText;
+import org.apache.axis.om.impl.llom.OMNamespaceImpl;
+import org.apache.axis.om.impl.llom.builder.StAXBuilder;
+import org.apache.axis.om.impl.llom.builder.StAXOMBuilder;
+import org.apache.axis.om.impl.llom.mtom.MTOMStAXSOAPModelBuilder;
+import org.apache.axis.soap.SOAPEnvelope;
+import org.apache.axis.soap.SOAPFactory;
+import org.apache.axis.soap.impl.llom.SOAPProcessingException;
+import org.apache.axis.soap.impl.llom.builder.StAXSOAPModelBuilder;
+import org.apache.axis.soap.impl.llom.soap11.SOAP11Factory;
+import org.apache.axis.util.Utils;
+
+public class HTTPTransportUtils {
+
+ public static void processHTTPPostRequest(
+ MessageContext msgContext,
+ InputStream in,
+ OutputStream out,
+ String contentType,
+ String soapAction,
+ String requestURI,
+ ConfigurationContext configurationContext)
+ throws AxisFault {
+
+ try {
+ msgContext.setWSAAction(soapAction);
+ msgContext.setSoapAction(soapAction);
+ msgContext.setTo(new EndpointReference(AddressingConstants.WSA_TO, requestURI));
+ msgContext.setProperty(MessageContext.TRANSPORT_OUT, out);
+ msgContext.setServerSide(true);
+
+ SOAPEnvelope envelope = null;
+ StAXBuilder builder = null;
+ Reader reader = new InputStreamReader(in);
+ XMLStreamReader xmlreader =
+ XMLInputFactory.newInstance().createXMLStreamReader(reader);
+
+
+ StringTokenizer st = new StringTokenizer(contentType);
+
+ String mimetype = null;
+ if (st.hasMoreTokens()){
+ mimetype = st.nextToken();
+ }
+
+ if (HTTPConstants.HEADER_ACCEPT_MULTIPART_RELATED.equalsIgnoreCase(mimetype)) {
+ builder = selectBuilderForMIME(msgContext,in,contentType);
+ envelope = (SOAPEnvelope) builder.getDocumentElement();
+ } else if (
+ contentType != null && contentType.indexOf(Constants.SOAP.SOAP_11_CONTENT_TYPE) > -1) {
+ if ((soapAction == null || soapAction.length() == 0)
+ && Constants.VALUE_TRUE.equals(
+ msgContext.getProperty(Constants.Configuration.ENABLE_REST))) {
+ msgContext.setProperty(Constants.Configuration.DO_REST, Constants.VALUE_TRUE);
+ SOAPFactory soapFactory = new SOAP11Factory();
+ builder = new StAXOMBuilder(xmlreader);
+ builder.setOmbuilderFactory(soapFactory);
+ envelope = soapFactory.getDefaultEnvelope();
+ envelope.getBody().addChild(builder.getDocumentElement());
+ }
+ }
+
+ if(envelope == null){
+ builder = new StAXSOAPModelBuilder(xmlreader);
+ envelope = (SOAPEnvelope) builder.getDocumentElement();
+ }
+
+ msgContext.setEnvelope(envelope);
+ AxisEngine engine = new AxisEngine(configurationContext);
+ engine.receive(msgContext);
+ } catch (SOAPProcessingException e) {
+ throw new AxisFault(e);
+ } catch (OMException e) {
+ throw new AxisFault(e);
+ } catch (XMLStreamException e) {
+ throw new AxisFault(e);
+ }
+ }
+
+ public static boolean processHTTPGetRequest(
+ MessageContext msgContext,
+ InputStream in,
+ OutputStream out,
+ String contentType,
+ String soapAction,
+ String requestURI,
+ ConfigurationContext configurationContext,Map requestParameters) throws AxisFault {
+ msgContext.setWSAAction(soapAction);
+ msgContext.setSoapAction(soapAction);
+ msgContext.setTo(new EndpointReference(AddressingConstants.WSA_TO, requestURI));
+ msgContext.setProperty(MessageContext.TRANSPORT_OUT, out);
+ msgContext.setServerSide(true);
+ try {
+ SOAPEnvelope envelope =
+ HTTPTransportUtils.createEnvelopeFromGetRequest(
+ requestURI,
+ requestParameters);
+ if (envelope == null) {
+ return false;
+ } else {
+ msgContext.setProperty(Constants.Configuration.DO_REST, Constants.VALUE_TRUE);
+ msgContext.setEnvelope(envelope);
+ AxisEngine engine = new AxisEngine(configurationContext);
+ engine.receive(msgContext);
+ return true;
+ }
+ }catch (IOException e) {
+ throw new AxisFault(e);
+ }
+ }
+ public static final SOAPEnvelope createEnvelopeFromGetRequest(String requestUrl, Map map) {
+ String[] values = Utils.parseRequestURLForServiceAndOperation(requestUrl);
+
+ if (values[1] != null && values[0] != null) {
+ String operation = values[1];
+ SOAPFactory soapFactory = new SOAP11Factory();
+ SOAPEnvelope envelope = soapFactory.getDefaultEnvelope();
+
+ OMNamespace omNs = soapFactory.createOMNamespace(values[0], "services");
+ OMNamespace defualtNs = new OMNamespaceImpl("", null);
+
+ OMElement opElement = soapFactory.createOMElement(operation, omNs);
+
+ Iterator it = map.keySet().iterator();
+ while (it.hasNext()) {
+ String name = (String) it.next();
+ String value = (String) map.get(name);
+ OMElement omEle = soapFactory.createOMElement(name, defualtNs);
+ omEle.setText(value);
+ opElement.addChild(omEle);
+ }
+
+ envelope.getBody().addChild(opElement);
+ return envelope;
+ } else {
+ return null;
+ }
+ }
+ public static StAXBuilder selectBuilderForMIME(MessageContext msgContext, InputStream inStream,String contentTypeString) throws OMException, XMLStreamException, FactoryConfigurationError
+ {
+ StAXBuilder builder = null;
+ MIMEHelper mimeHelper = new MIMEHelper(inStream, contentTypeString);
+ XMLStreamReader reader = XMLInputFactory
+ .newInstance()
+ .createXMLStreamReader(
+ new BufferedReader(
+ new InputStreamReader(mimeHelper
+ .getSOAPPartInputStream())));
+ /*
+ * put a reference to Attachments in to the message context
+ */
+ msgContext.setProperty("Attachments", mimeHelper);
+ if (mimeHelper.getAttachmentSpecType().equals(
+ MIMEHelper.MTOM_TYPE)) {
+ /*
+ * Creates the MTOM specific MTOMStAXSOAPModelBuilder
+ */
+ builder = new MTOMStAXSOAPModelBuilder(reader,
+ mimeHelper);
+ } else if (mimeHelper.getAttachmentSpecType().equals(
+ MIMEHelper.SWA_TYPE)) {
+ builder = new StAXSOAPModelBuilder(reader);
+ }
+ return builder;
+ }
+
+
+ public static boolean checkEnvelopeForOptimise(SOAPEnvelope envelope)
+ {
+ return isOptimised(envelope);
+ }
+
+ private static boolean isOptimised(OMElement element) {
+ Iterator childrenIter = element.getChildren();
+ while(childrenIter.hasNext()){
+ OMNode node = (OMNode) childrenIter.next();
+ if( OMNode.TEXT_NODE == node.getType() && ((OMText)node).isOptimized()){
+ return true;
+ }else if (OMNode.ELEMENT_NODE == node.getType()) {
+ return isOptimised((OMElement) node);
+ }
+ }
+ return false;
+ }
+
+}
Modified: webservices/axis/trunk/java/modules/xml/src/org/apache/axis/om/OMOutput.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/xml/src/org/apache/axis/om/OMOutput.java?rev=202338&r1=202337&r2=202338&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/xml/src/org/apache/axis/om/OMOutput.java (original)
+++ webservices/axis/trunk/java/modules/xml/src/org/apache/axis/om/OMOutput.java Wed Jun 29 01:53:42 2005
@@ -45,9 +45,9 @@
private ByteArrayOutputStream bufferedSoapOutStream;
- private String mimeBoundary = null;
+ private static String mimeBoundary = "----=_AxIs2_Def_boundary_=42214532";
- private String contentType = null;
+ //private String contentType = null;
/**
* @param xmlWriter
@@ -105,11 +105,12 @@
return doOptimise;
}
- public String getContentType() {
- if (contentType == null && doOptimise) {
- MIMEOutputUtils.getContentTypeForMime(getMimeBoundary());
+ public static String getContentType(boolean doOptimize) {
+ if (doOptimize) {
+ return MIMEOutputUtils.getContentTypeForMime(mimeBoundary);
}
- return contentType.toString();
+ //TODO have to check whether SOAP1.1 & SOAP 1.2
+ return null;
}
public void writeOptimised(OMText node) {
@@ -120,16 +121,16 @@
if (doOptimise) {
xmlWriter.flush();
MIMEOutputUtils.complete(outStream, bufferedSoapOutStream,
- binaryNodeList, getMimeBoundary());
+ binaryNodeList, mimeBoundary);
}
}
- private String getMimeBoundary() {
+ /*private String getMimeBoundary() {
//TODO have to dynamically generate.
if (mimeBoundary == null) {
mimeBoundary = "----=_AxIs2_Def_boundary_=42214532";
}
return mimeBoundary;
- }
+ }*/
}