You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by sc...@apache.org on 2009/11/02 23:07:31 UTC
svn commit: r832133 - in /webservices/axis2/trunk/java/modules:
jaxws-integration/test/org/apache/axis2/jaxws/dispatch/
jaxws/src/org/apache/axis2/jaxws/context/listener/
jaxws/src/org/apache/axis2/jaxws/message/factory/
jaxws/src/org/apache/axis2/jaxw...
Author: scheu
Date: Mon Nov 2 22:07:29 2009
New Revision: 832133
URL: http://svn.apache.org/viewvc?rev=832133&view=rev
Log:
AXIS2-4509
Contributor: Davanum Srinivas, Rich Scheuerle
Enables optimization on Dispatch<OMElement> return path.
Added a verification test.
Modified:
webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/dispatch/OMElementDispatchTest.java
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/context/listener/ParserInputStreamCustomBuilder.java
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/factory/ParsedEntityReaderFactory.java
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/spi/ServiceDelegate.java
Modified: webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/dispatch/OMElementDispatchTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/dispatch/OMElementDispatchTest.java?rev=832133&r1=832132&r2=832133&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/dispatch/OMElementDispatchTest.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/dispatch/OMElementDispatchTest.java Mon Nov 2 22:07:29 2009
@@ -21,6 +21,7 @@
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
import java.io.StringReader;
import javax.xml.namespace.QName;
@@ -40,10 +41,15 @@
import junit.framework.TestSuite;
import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMSourcedElement;
import org.apache.axiom.om.impl.builder.StAXOMBuilder;
+import org.apache.axiom.soap.SOAPBody;
import org.apache.axiom.soap.SOAPEnvelope;
import org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder;
import org.apache.axis2.jaxws.framework.AbstractTestCase;
+import org.apache.axis2.jaxws.message.databinding.ParsedEntityReader;
+import org.apache.axis2.jaxws.message.factory.ParsedEntityReaderFactory;
+import org.apache.axis2.jaxws.registry.FactoryRegistry;
/**
* This class uses the JAX-WS Dispatch API to test sending and receiving
@@ -61,6 +67,10 @@
"<test:echoOMElement xmlns:test=\"http://org/apache/axis2/jaxws/test/OMELEMENT\">" +
"<test:input>SAMPLE REQUEST MESSAGE</test:input>" +
"</test:echoOMElement>";
+ private static final String testResponse =
+ "<test:echoOMElement xmlns:test=\"http://org/apache/axis2/jaxws/test/OMELEMENT\">" +
+ "<test:output>TEST RESPONSE MESSAGE</test:output>" +
+ "</test:echoOMElement>";
private static final String sampleEnvelopeHead =
"<soapenv:Envelope xmlns:soapenv=\"http://www.w3.org/2003/05/soap-envelope\">" +
"<soapenv:Header /><soapenv:Body>";
@@ -318,4 +328,79 @@
assertTrue(!responseText.contains("http://schemas.xmlsoap.org/soap/envelope"));
}
+ /**
+ * Test sending a SOAP 1.2 request in MESSAGE mode with
+ * a Parser that can provide the InputStream for the payload
+ */
+ public void testOMElementDispatchWithParsedEntityReader() throws Exception {
+
+ // Subsitute a ParsedEntityReader that will provide the
+ // payload InputStream. This simulates parsers that provide this
+ // feature.
+ ParsedEntityReaderFactory factory = (ParsedEntityReaderFactory)
+ FactoryRegistry.getFactory(ParsedEntityReaderFactory.class);
+ ParsedEntityReader per = new ParsedEntityReaderTest();
+ factory.setParsetEntityReader(per);
+
+ try {
+ // Create the JAX-WS client needed to send the request
+ Service service = Service.create(QNAME_SERVICE);
+ service.addPort(QNAME_PORT, SOAPBinding.SOAP12HTTP_BINDING, URL_ENDPOINT);
+ Dispatch<OMElement> dispatch = service.createDispatch(
+ QNAME_PORT, OMElement.class, Mode.MESSAGE);
+
+ // Create the OMElement object with the payload contents. Since
+ // we're in PAYLOAD mode, we don't have to worry about the envelope.
+ StringReader sr = new StringReader(sampleEnvelope);
+ XMLStreamReader inputReader = inputFactory.createXMLStreamReader(sr);
+ StAXSOAPModelBuilder builder = new StAXSOAPModelBuilder(inputReader, null);
+ SOAPEnvelope soap12Envelope = (SOAPEnvelope) builder.getDocumentElement();
+
+
+ // Invoke
+ OMElement response = dispatch.invoke(soap12Envelope);
+
+
+ SOAPEnvelope responseEnv = (SOAPEnvelope) response;
+ SOAPBody responseBody = responseEnv.getBody();
+ OMElement payload = responseBody.getFirstElement();
+
+ // At this point, the payload should be an OMSourcedElement
+ // that was created from the ParsedEntityReader's stream
+ assertTrue(payload instanceof OMSourcedElement);
+
+
+ // Check to make sure the contents of the message are correct
+ String responseText = payload.toStringWithConsume();
+ assertTrue(responseText.contains("TEST RESPONSE"));
+ } finally {
+
+ // Uninstall the Test ParsedEntityReader
+ factory.setParsetEntityReader(null);
+ }
+ }
+
+ /**
+ * The purpose of a ParsedEntityReader is to get the
+ * InputStream from the parser if it is available.
+ * Woodstox and other parsers don't provide that feature.
+ * To simulate this feature, this ParserEntityReaderTest is
+ * inserted to simulate getting a response from the Parser.
+ */
+ public class ParsedEntityReaderTest implements ParsedEntityReader {
+ int count =0;
+ public boolean isParsedEntityStreamAvailable() {
+ return true;
+ }
+
+ public InputStream readParsedEntityStream(XMLStreamReader reader) {
+ count++;
+ if (count == 2) {
+ return new ByteArrayInputStream(testResponse.getBytes());
+ } else {
+ return null;
+ }
+ }
+
+ }
}
Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/context/listener/ParserInputStreamCustomBuilder.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/context/listener/ParserInputStreamCustomBuilder.java?rev=832133&r1=832132&r2=832133&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/context/listener/ParserInputStreamCustomBuilder.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/context/listener/ParserInputStreamCustomBuilder.java Mon Nov 2 22:07:29 2009
@@ -81,14 +81,23 @@
try{
ParsedEntityReaderFactory perf = (ParsedEntityReaderFactory)FactoryRegistry.getFactory(ParsedEntityReaderFactory.class);
ParsedEntityReader entityReader = perf.getParsedEntityReader();
+ if (log.isDebugEnabled()) {
+ log.debug("ParsedEntityReader = " + entityReader);
+ }
//Do not user custom builder if Parser does not have ability to read sub content.
if(!entityReader.isParsedEntityStreamAvailable()){
+ if (log.isDebugEnabled()) {
+ log.debug("Stream not available");
+ }
return null;
}
// Create an OMSourcedElement backed by the ParsedData
InputStream parsedStream = getPayloadContent(reader, entityReader);
if(parsedStream == null){
//cant read content from EntityReader, returning null.
+ if (log.isDebugEnabled()) {
+ log.debug("No content available");
+ }
return null;
}
//read the payload. Lets move the parser forward.
Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/factory/ParsedEntityReaderFactory.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/factory/ParsedEntityReaderFactory.java?rev=832133&r1=832132&r2=832133&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/factory/ParsedEntityReaderFactory.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/factory/ParsedEntityReaderFactory.java Mon Nov 2 22:07:29 2009
@@ -39,7 +39,7 @@
}
public void setParsetEntityReader(ParsedEntityReader per){
- if(this.per == null){
+ if(this.per == null || this.per != per){
this.per = per;
}
}
Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/spi/ServiceDelegate.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/spi/ServiceDelegate.java?rev=832133&r1=832132&r2=832133&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/spi/ServiceDelegate.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/spi/ServiceDelegate.java Mon Nov 2 22:07:29 2009
@@ -53,6 +53,7 @@
import org.apache.axis2.jaxws.client.dispatch.JAXBDispatch;
import org.apache.axis2.jaxws.client.dispatch.XMLDispatch;
import org.apache.axis2.jaxws.client.proxy.JAXWSProxyHandler;
+import org.apache.axis2.jaxws.context.listener.ProviderOMContextListener;
import org.apache.axis2.jaxws.description.DescriptionFactory;
import org.apache.axis2.jaxws.description.EndpointDescription;
import org.apache.axis2.jaxws.description.ServiceDescription;
@@ -275,6 +276,10 @@
@Override
public <T> Dispatch<T> createDispatch(EndpointReference jaxwsEPR, Class<T> type, Mode mode, WebServiceFeature... features) {
+ if (log.isDebugEnabled()) {
+ log.debug("Create Dispatch with epr: " + jaxwsEPR);
+ }
+
verifyServiceDescriptionActive();
if (jaxwsEPR == null) {
throw ExceptionFactory
@@ -325,6 +330,13 @@
if (serviceClient == null)
serviceClient = getServiceClient(endpointDesc.getPortQName());
+
+ if(type == OMElement.class) {
+ if (log.isDebugEnabled()) {
+ log.debug("This a Dispatch<OMElement>. The custom builder is installed.");
+ }
+ ProviderOMContextListener.create(serviceClient.getServiceContext());
+ }
dispatch.setServiceClient(serviceClient);
dispatch.setType(type);
@@ -333,6 +345,9 @@
@Override
public Dispatch<Object> createDispatch(EndpointReference jaxwsEPR, JAXBContext context, Mode mode, WebServiceFeature... features) {
+ if (log.isDebugEnabled()) {
+ log.debug("Create Dispatch with epr 2: " + jaxwsEPR);
+ }
verifyServiceDescriptionActive();
if (jaxwsEPR == null) {
throw ExceptionFactory
@@ -382,6 +397,10 @@
@Override
public <T> Dispatch<T> createDispatch(QName portName, Class<T> type, Mode mode, WebServiceFeature... features) {
+
+ if (log.isDebugEnabled()) {
+ log.debug("Create Dispatch with portName: " + portName);
+ }
verifyServiceDescriptionActive();
if (portName == null) {
throw ExceptionFactory
@@ -421,6 +440,12 @@
if (serviceClient == null)
serviceClient = getServiceClient(portName);
+ if(type == OMElement.class) {
+ if (log.isDebugEnabled()) {
+ log.debug("This a Dispatch<OMElement>. The custom builder is installed.");
+ }
+ ProviderOMContextListener.create(serviceClient.getServiceContext());
+ }
dispatch.setServiceClient(serviceClient);
dispatch.setType(type);
return dispatch;
@@ -428,6 +453,10 @@
@Override
public Dispatch<Object> createDispatch(QName portName, JAXBContext context, Mode mode, WebServiceFeature... features) {
+ if (log.isDebugEnabled()) {
+ log.debug("Create Dispatch with jaxbcontext and portName: " + portName);
+ }
+
verifyServiceDescriptionActive();
if (portName == null) {
throw ExceptionFactory