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 sc...@apache.org on 2006/08/08 01:44:14 UTC
svn commit: r429513 - in /webservices/axis2/trunk/java/modules/jaxws: ./
src/org/apache/axis2/jaxws/i18n/
src/org/apache/axis2/jaxws/message/databinding/impl/
src/org/apache/axis2/jaxws/message/impl/ test-resources/xsd/
test/org/apache/axis2/jaxws/ tes...
Author: scheu
Date: Mon Aug 7 16:44:13 2006
New Revision: 429513
URL: http://svn.apache.org/viewvc?rev=429513&view=rev
Log:
AXIS2-977
JAXBSource Dispatch tests + related code changes
Contributor: Nikhil Thaker & Rich Scheuerle
Added:
webservices/axis2/trunk/java/modules/jaxws/test-resources/xsd/jaxbsource.xsd
webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/JAXBSourceDispatch.java
Modified:
webservices/axis2/trunk/java/modules/jaxws/maven.xml
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/i18n/resource.properties
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/SourceBlockImpl.java
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/XMLSpineImpl.java
webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/DispatchTestSuite.java
webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/message/BlockTests.java
webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/provider/source/SourceProvider.java
Modified: webservices/axis2/trunk/java/modules/jaxws/maven.xml
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/maven.xml?rev=429513&r1=429512&r2=429513&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/maven.xml (original)
+++ webservices/axis2/trunk/java/modules/jaxws/maven.xml Mon Aug 7 16:44:13 2006
@@ -64,6 +64,13 @@
<classpath location="${compiled.classes.dir}"/>
<arg line="-d ${schema.generated.src.dir} -p org.test.proxy.doclitwrapped -quiet -wsdl ${wsdl.source.dir}/ProxyDocLitWrapped.wsdl"/>
</java>
+ <ant:echo>Generating java from jaxbsource</ant:echo>
+ <java classname="com.sun.tools.xjc.Driver" fork="true">
+ <jvmarg line="${maven.junit.jvmargs}"/>
+ <classpath refid="maven.dependency.classpath"/>
+ <classpath location="${compiled.classes.dir}"/>
+ <arg line="-d ${schema.generated.src.dir} -p org.test.dispatch.jaxbsource ${schema.source.dir}/jaxbsource.xsd"/>
+ </java>
<!-- Compile the generated classes -->
<ant:echo>Compiling generated schema</ant:echo>
Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/i18n/resource.properties
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/i18n/resource.properties?rev=429513&r1=429512&r2=429513&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/i18n/resource.properties (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/i18n/resource.properties Mon Aug 7 16:44:13 2006
@@ -90,4 +90,5 @@
JAXBWrapperErr3=Internal Assertion Error. Child objects or child names argument to wrap() is null.
JAXBWrapperErr4=Internal Assertion Error. Number of child objects does not match the number of child names in wrap() method.
JAXBWrapperErr5=Internal Assertion Error. Number of child names does not match the number of bean properties in JAXB class {0}.
-JAXBWrapperErr6=Internal Assertion Error. JAXB object {0} does not have a bean property named {1}.
\ No newline at end of file
+JAXBWrapperErr6=Internal Assertion Error. JAXB object {0} does not have a bean property named {1}.
+JAXBSourceNamespaceErr=The DOMSource must be Namespace Aware.
Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/SourceBlockImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/SourceBlockImpl.java?rev=429513&r1=429512&r2=429513&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/SourceBlockImpl.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/SourceBlockImpl.java Mon Aug 7 16:44:13 2006
@@ -16,6 +16,7 @@
*/
package org.apache.axis2.jaxws.message.databinding.impl;
+import java.io.ByteArrayInputStream;
import java.io.StringReader;
import java.lang.reflect.Constructor;
@@ -26,9 +27,14 @@
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.XMLStreamWriter;
+import javax.xml.transform.Result;
import javax.xml.transform.Source;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.sax.SAXSource;
+import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import org.apache.axiom.om.OMElement;
@@ -45,6 +51,8 @@
import org.w3c.dom.Element;
import org.xml.sax.InputSource;
+import com.ibm.jvm.util.ByteArrayOutputStream;
+
/**
* SourceBlock
*
@@ -142,13 +150,39 @@
// We had some problems with testers producing DOMSources w/o Namespaces.
// It's easy to catch this here.
if (element.getLocalName() == null) {
- // TODO NLS
- throw new XMLStreamException(ExceptionFactory.makeMessageException("The DOMSource must be Namespace Aware"));
+ throw new XMLStreamException(ExceptionFactory.makeMessageException(Messages.getMessage("JAXBSourceNamespaceErr")));
}
return new DOMReader((Element) ((DOMSource)busObj).getNode());
}
- return inputFactory.createXMLStreamReader((Source) busObj);
+
+ if(busObj instanceof StreamSource){
+ return inputFactory.createXMLStreamReader((Source) busObj);
+ }
+ //TODO: For GM we need to only use this approach when absolutely necessary.
+ // For example, we don't want to do this if this is a (1.6) StaxSource or if the installed parser provides
+ // a better solution.
+ //TODO: Uncomment this code if woodstock parser handles JAXBSource and SAXSource correctly.
+ //return inputFactory.createXMLStreamReader((Source) busObj);
+ return _slow_getReaderFromSource((Source)busObj);
}
+
+ /**
+ * Creates an XMLStreamReader from a Source using a slow but proven algorithm.
+ */
+ private XMLStreamReader _slow_getReaderFromSource(Source src) throws XMLStreamException {
+ try{
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ Result result = new StreamResult(out);
+ Transformer transformer = TransformerFactory.newInstance().newTransformer();
+ transformer.transform(src, result);
+ XMLInputFactory inputfactory = XMLInputFactory.newInstance();
+ ByteArrayInputStream bytes = new ByteArrayInputStream(out.toByteArray());
+ return inputfactory.createXMLStreamReader(bytes);
+ }catch(TransformerException e){
+ throw new XMLStreamException(e);
+ }
+
+ }
@Override
protected void _outputFromBO(Object busObject, Object busContext, XMLStreamWriter writer) throws XMLStreamException {
Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/XMLSpineImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/XMLSpineImpl.java?rev=429513&r1=429512&r2=429513&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/XMLSpineImpl.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/XMLSpineImpl.java Mon Aug 7 16:44:13 2006
@@ -34,6 +34,7 @@
import org.apache.axiom.soap.SOAPFactory;
import org.apache.axiom.soap.SOAPHeader;
import org.apache.axiom.soap.impl.llom.soap11.SOAP11Factory;
+import org.apache.axiom.soap.impl.llom.soap12.SOAP12Factory;
import org.apache.axis2.jaxws.ExceptionFactory;
import org.apache.axis2.jaxws.i18n.Messages;
import org.apache.axis2.jaxws.message.Block;
@@ -173,7 +174,7 @@
if (protocol == Protocol.soap11) {
soapFactory = new SOAP11Factory();
} else if (protocol == Protocol.soap12) {
- soapFactory = new SOAP11Factory();
+ soapFactory = new SOAP12Factory();
} else {
// TODO REST Support is needed
throw ExceptionFactory.makeMessageInternalException(Messages.getMessage("RESTIsNotSupported"), null);
Added: webservices/axis2/trunk/java/modules/jaxws/test-resources/xsd/jaxbsource.xsd
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test-resources/xsd/jaxbsource.xsd?rev=429513&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test-resources/xsd/jaxbsource.xsd (added)
+++ webservices/axis2/trunk/java/modules/jaxws/test-resources/xsd/jaxbsource.xsd Mon Aug 7 16:44:13 2006
@@ -0,0 +1,22 @@
+<xsd:schema
+ targetNamespace="http://org.test.dispatch.jaxbsource"
+ xmlns:tns="http://org.test.dispatch.jaxbsource"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema">
+
+ <xsd:element name="ReturnType">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="return_str"
+ type="xsd:string" />
+ </xsd:sequence>
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="invoke">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="invoke_str"
+ type="xsd:string" />
+ </xsd:sequence>
+ </xsd:complexType>
+ </xsd:element>
+</xsd:schema>
Modified: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/DispatchTestSuite.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/DispatchTestSuite.java?rev=429513&r1=429512&r2=429513&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/DispatchTestSuite.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/DispatchTestSuite.java Mon Aug 7 16:44:13 2006
@@ -1,41 +1,41 @@
-/*
- * Copyright 2004,2005 The Apache Software Foundation.
- * Copyright 2006 International Business Machines Corp.
- *
- * 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.axis2.jaxws;
-
-import junit.framework.TestSuite;
-
-public class DispatchTestSuite {
-
- public static TestSuite suite() {
- TestSuite suite = new TestSuite();
- suite = addTestSuites(suite);
- return suite;
- }
-
- public static TestSuite addTestSuites(TestSuite suite) {
- suite.addTestSuite(StringDispatch.class);
- suite.addTestSuite(StreamSourceDispatch.class);
- suite.addTestSuite(DOMSourceDispatch.class);
- suite.addTestSuite(SAXSourceDispatch.class);
- // FIXME: Add this test in
-
- suite.addTestSuite(JAXBDispatch.class);
-
- return suite;
- }
-
-}
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * 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.axis2.jaxws;
+
+import junit.framework.TestSuite;
+
+public class DispatchTestSuite {
+
+ public static TestSuite suite() {
+ TestSuite suite = new TestSuite();
+ suite = addTestSuites(suite);
+ return suite;
+ }
+
+ public static TestSuite addTestSuites(TestSuite suite) {
+ suite.addTestSuite(StringDispatch.class);
+ suite.addTestSuite(StreamSourceDispatch.class);
+ suite.addTestSuite(DOMSourceDispatch.class);
+ suite.addTestSuite(SAXSourceDispatch.class);
+ // FIXME: Add this test in
+
+ suite.addTestSuite(JAXBDispatch.class);
+ suite.addTestSuite(JAXBSourceDispatch.class);
+ return suite;
+ }
+
+}
Added: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/JAXBSourceDispatch.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/JAXBSourceDispatch.java?rev=429513&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/JAXBSourceDispatch.java (added)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/JAXBSourceDispatch.java Mon Aug 7 16:44:13 2006
@@ -0,0 +1,91 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * 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.axis2.jaxws;
+
+import java.io.StringWriter;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.util.JAXBSource;
+import javax.xml.namespace.QName;
+import javax.xml.transform.Result;
+import javax.xml.transform.Source;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.ws.Dispatch;
+import javax.xml.ws.Service;
+
+import org.test.dispatch.jaxbsource.Invoke;
+import org.test.dispatch.jaxbsource.ObjectFactory;
+
+import junit.framework.TestCase;
+
+
+/*
+ * This is a test case for Invoking Dispatch with a JAXBSource.
+ * test uses JAXB Objects from org.test.dispatch.jaxbsource package, create a request of JAXBSource type
+ * and invokes the service endpoint and reads the response of type Source. Assert failure if response not received.
+ */
+
+
+public class JAXBSourceDispatch extends TestCase {
+ /**
+ * Invoke a sync Dispatch<JAXBSource> in PAYLOAD mode
+ */
+
+ private String url = "http://localhost:8080/axis2/services/SourceProviderService";
+ private QName serviceName = new QName("http://ws.apache.org/axis2", "SourceProviderService");
+ private QName portName =new QName("http://ws.apache.org/axis2", "SimpleProviderServiceSOAP11port0");
+
+ public void testJAXBSourceSyncPayloadMode() throws Exception {
+ System.out.println("---------------------------------------");
+ System.out.println("test: " + getName());
+ try{
+ // Initialize the JAX-WS client artifacts
+ Service svc = Service.create(serviceName);
+ svc.addPort(portName, null, url);
+ Dispatch<JAXBSource> dispatch = svc.createDispatch(portName,
+ JAXBSource.class, Service.Mode.PAYLOAD);
+
+ //Create JAXBContext and JAXBSource here.
+ ObjectFactory factory = new ObjectFactory();
+ Invoke invokeObj = factory.createInvoke();
+ invokeObj.setInvokeStr("Some Request");
+ JAXBContext ctx = JAXBContext.newInstance("org.test.dispatch.jaxbsource");
+
+ JAXBSource jbSrc = new JAXBSource(ctx.createMarshaller(), invokeObj);
+ // Invoke the Dispatch
+ System.out.println(">> Invoking sync Dispatch");
+ //Invoke Server endpoint and read response
+ Source response = dispatch.invoke(jbSrc);
+
+ assertNotNull("dispatch invoke returned null", response);
+ //Print the response as string.
+ StringWriter writer = new StringWriter();
+ Transformer t = TransformerFactory.newInstance().newTransformer();
+ Result result = new StreamResult(writer);
+ t.transform(response, result);
+
+ System.out.println("Response On Client: \n"+writer.getBuffer().toString());
+ System.out.println("---------------------------------------");
+ }catch(Exception e){
+ e.printStackTrace();
+ }
+
+ }
+
+}
Modified: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/message/BlockTests.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/message/BlockTests.java?rev=429513&r1=429512&r2=429513&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/message/BlockTests.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/message/BlockTests.java Mon Aug 7 16:44:13 2006
@@ -17,12 +17,15 @@
package org.apache.axis2.jaxws.message;
import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
import java.io.StringReader;
import java.io.StringWriter;
import java.util.Map;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBIntrospector;
+import javax.xml.bind.Unmarshaller;
+import javax.xml.bind.util.JAXBSource;
import javax.xml.namespace.QName;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
@@ -30,14 +33,21 @@
import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.XMLStreamWriter;
+import javax.xml.transform.Result;
import javax.xml.transform.Source;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.sax.SAXSource;
+import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMOutputFormat;
import org.apache.axiom.om.impl.builder.StAXOMBuilder;
+import org.apache.axis2.jaxws.message.factory.BlockFactory;
import org.apache.axis2.jaxws.message.factory.JAXBBlockFactory;
+import org.apache.axis2.jaxws.message.factory.MessageFactory;
import org.apache.axis2.jaxws.message.factory.OMBlockFactory;
import org.apache.axis2.jaxws.message.factory.SourceBlockFactory;
import org.apache.axis2.jaxws.message.factory.XMLStringBlockFactory;
@@ -896,7 +906,79 @@
assertTrue(sampleText.equals(newText));
}
-
+ /*
+ * Testing JAXBSource, Creating Source Block using JAXBSource and then
+ * Serializing it.
+ */
+ public void testJAXBSourceInFlow1()throws Exception{
+ // Create a jaxb object
+ try{
+ ObjectFactory factory = new ObjectFactory();
+ EchoString jaxb = factory.createEchoString();
+ jaxb.setInput("Hello World");
+ JAXBContext jbc = JAXBContext.newInstance("test");
+ JAXBSource src = new JAXBSource(jbc.createMarshaller(), jaxb);
+ BlockFactory f = (SourceBlockFactory)
+ FactoryRegistry.getFactory(SourceBlockFactory.class);
+
+ Block block =f.createFrom(src, null, null);
+
+ MessageFactory mf = (MessageFactory) FactoryRegistry.getFactory(MessageFactory.class);
+ Message msg = mf.create(Protocol.soap11);
+ msg.setBodyBlock(0,block);
+ org.apache.axiom.soap.SOAPEnvelope env = (org.apache.axiom.soap.SOAPEnvelope)msg.getAsOMElement();
+ // Serialize the Envelope using the same mechanism as the
+ // HTTP client.
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ env.serializeAndConsume(baos, new OMOutputFormat());
+
+ // To check that the output is correct, get the String contents of the
+ // reader
+ String newText = baos.toString();
+ System.out.println(newText);
+ assertTrue(block.isConsumed());
+ }catch(Exception e){
+ e.printStackTrace();
+ }
+ }
+
+ public void testJAXBSourceOutflow() throws Exception {
+
+ //Sample text for JAXBSource
+ String echoSample = "<echoString xmlns=\"http://test\"><input xmlns=\"http://test\">Hello World</input></echoString>";
+
+ // Get the BlockFactory
+ SourceBlockFactory f = (SourceBlockFactory)
+ FactoryRegistry.getFactory(SourceBlockFactory.class);
+ //Create a JAXBSource
+
+ JAXBContext jbc = JAXBContext.newInstance("test");
+ Unmarshaller u = jbc.createUnmarshaller();
+ ByteArrayInputStream inputStream = new ByteArrayInputStream(echoSample.getBytes());
+ EchoString jaxb = (EchoString)u.unmarshal(inputStream);
+ JAXBSource src = new JAXBSource(jbc.createMarshaller(), jaxb);
+
+ // Create a Block using the sample string as the content. This simulates
+ // what occurs on the outbound JAX-WS dispatch<Source> client
+ Block block = f.createFrom(src, null, null);
+
+ // We didn't pass in a qname, so the following should return false
+ assertTrue(!block.isQNameAvailable());
+
+ // Assuming no handlers are installed, the next thing that will happen
+ // is a XMLStreamReader will be requested...to go to OM. At this point the
+ // block should be consumed.
+ XMLStreamReader reader = block.getXMLStreamReader(true);
+
+ // The block should be consumed
+ assertTrue(block.isConsumed());
+
+ // To check that the output is correct, get the String contents of the
+ // reader
+ Reader2Writer r2w = new Reader2Writer(reader);
+ String newText = r2w.getAsString();
+ assertTrue(echoSample.equals(newText));
+ }
/**
* Create a Block representing a DOMSource instance and simulate an
* outbound flow
Modified: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/provider/source/SourceProvider.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/provider/source/SourceProvider.java?rev=429513&r1=429512&r2=429513&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/provider/source/SourceProvider.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/provider/source/SourceProvider.java Mon Aug 7 16:44:13 2006
@@ -16,14 +16,42 @@
*/
package org.apache.axis2.jaxws.provider.source;
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.io.StringWriter;
+
import javax.xml.ws.Provider;
+import javax.xml.transform.Result;
import javax.xml.transform.Source;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.stream.StreamSource;
+
+import org.apache.axis2.jaxws.DispatchTestConstants;
public class SourceProvider implements Provider<Source> {
-
+ String responseAsString = new String("<ns2:ReturnType xmlns:ns2=\"http://test\"><return_str>some response</return_str></ns2:ReturnType>");
public Source invoke(Source source) {
System.out.println(">> SourceProvider: Request received.\n");
- System.out.println(">> Source toString: \n"+source.toString());
- return source;
+ //System.out.println(">> Source toString: \n"+source.toString());
+
+ try{
+ StringWriter writer = new StringWriter();
+ Transformer t = TransformerFactory.newInstance().newTransformer();
+ Result result = new StreamResult(writer);
+ t.transform(source, result);
+ System.out.println(">> Source Request on Server: \n"+writer.getBuffer().toString());
+
+ byte[] bytes = responseAsString.getBytes();
+ ByteArrayInputStream stream = new ByteArrayInputStream(bytes);
+ Source srcStream = new StreamSource((InputStream) stream);
+ return srcStream;
+ }catch(Exception e){
+ e.printStackTrace();
+ }
+ return null;
}
+
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org