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 12:38:48 UTC
svn commit: r202343 - in /webservices/axis/trunk/java/modules:
core/src/org/apache/axis/transport/ core/src/org/apache/axis/transport/http/
samples/test/org/apache/axis/engine/ xml/src/org/apache/axis/om/impl/llom/
Author: thilina
Date: Wed Jun 29 03:38:44 2005
New Revision: 202343
URL: http://svn.apache.org/viewcvs?rev=202343&view=rev
Log:
Changes to MTOM test
Modified:
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/samples/test/org/apache/axis/engine/EchoRawMTOMTest.java
webservices/axis/trunk/java/modules/xml/src/org/apache/axis/om/impl/llom/OMTextImpl.java
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=202343&r1=202342&r2=202343&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 03:38:44 2005
@@ -32,6 +32,7 @@
import org.apache.axis.om.OMElement;
import org.apache.axis.om.OMOutput;
import org.apache.axis.soap.SOAPEnvelope;
+import org.apache.axis.transport.http.HTTPTransportUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -140,6 +141,10 @@
doMTOM = ((Boolean) msgContext
.getProperty(Constants.Configuration.DO_MTOM))
.booleanValue();
+ }
+ else
+ {
+ doMTOM = HTTPTransportUtils.doWriteMTOM(msgContext);
}
try {
if (doMTOM) {
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=202343&r1=202342&r2=202343&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 03:38:44 2005
@@ -57,14 +57,8 @@
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));
+
+ boolean doMTOM = HTTPTransportUtils.doWriteMTOM(msgContext);
StringBuffer buf = new StringBuffer();
buf.append(HTTPConstants.HEADER_POST).append(" ");
buf.append(url.getFile()).append(" ").append(httpVersion).append("\n");
@@ -224,11 +218,7 @@
OutputStream out)
throws AxisFault {
try {
- Object value = msgContext.getProperty(Constants.Configuration.DO_MTOM);
- if(Constants.VALUE_TRUE.equals(value)){
- doMTOM = true;
- }
-
+
if (chuncked) {
TransportSenderInfo transportInfo =
(TransportSenderInfo) msgContext.getProperty(
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=202343&r1=202342&r2=202343&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 03:38:44 2005
@@ -1,19 +1,19 @@
/*
* 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
- *
+ *
+ * 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
+ * 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;
@@ -58,175 +58,184 @@
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;
- }
-
-}
+ 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;
+ }
+
+ public static boolean doWriteMTOM(MessageContext msgContext) {
+ 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));
+ return doMTOM;
+ }
+}
\ No newline at end of file
Modified: webservices/axis/trunk/java/modules/samples/test/org/apache/axis/engine/EchoRawMTOMTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/samples/test/org/apache/axis/engine/EchoRawMTOMTest.java?rev=202343&r1=202342&r2=202343&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/samples/test/org/apache/axis/engine/EchoRawMTOMTest.java (original)
+++ webservices/axis/trunk/java/modules/samples/test/org/apache/axis/engine/EchoRawMTOMTest.java Wed Jun 29 03:38:44 2005
@@ -47,8 +47,8 @@
public class EchoRawMTOMTest extends TestCase {
private EndpointReference targetEPR =
new EndpointReference(AddressingConstants.WSA_TO,
- "http://127.0.0.1:"
- + (UtilServer.TESTING_PORT)
+ "http://127.0.0.1:5556"
+ // + (UtilServer.TESTING_PORT)
+ "/axis/services/EchoXMLService/echoMTOMtoBase64");
private Log log = LogFactory.getLog(getClass());
private QName serviceName = new QName("EchoXMLService");
@@ -96,7 +96,7 @@
byte[] byteArray = new byte[] { 13, 56, 65, 32, 12, 12, 7, -3, -2, -1,
98 };
DataHandler dataHandler = new DataHandler(new ByteArrayDataSource(byteArray));
- OMTextImpl textData = new OMTextImpl(dataHandler, false);
+ OMTextImpl textData = new OMTextImpl(dataHandler, true);
data.addChild(textData);
return data;
}
@@ -110,6 +110,7 @@
org.apache.axis.clientapi.Call call = new org.apache.axis.clientapi.Call();
call.setTo(targetEPR);
+ call.set(Constants.Configuration.ENABLE_MTOM,Constants.VALUE_TRUE);
call.setTransportInfo(Constants.TRANSPORT_HTTP, Constants.TRANSPORT_HTTP, false);
OMElement result =
Modified: webservices/axis/trunk/java/modules/xml/src/org/apache/axis/om/impl/llom/OMTextImpl.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/xml/src/org/apache/axis/om/impl/llom/OMTextImpl.java?rev=202343&r1=202342&r2=202343&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/xml/src/org/apache/axis/om/impl/llom/OMTextImpl.java (original)
+++ webservices/axis/trunk/java/modules/xml/src/org/apache/axis/om/impl/llom/OMTextImpl.java Wed Jun 29 03:38:44 2005
@@ -323,7 +323,7 @@
public void serialize(OMOutput omOutput) throws XMLStreamException {
boolean firstElement = false;
- if (!this.optimize) {
+ if (!this.isBinary) {
serializeWithCache(omOutput);
} else {
if (omOutput.doOptimise()) {