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 2007/02/03 00:48:00 UTC
svn commit: r502800 - in /webservices/axis2/trunk/java/modules/jaxws:
src/org/apache/axis2/jaxws/message/
src/org/apache/axis2/jaxws/message/databinding/impl/
src/org/apache/axis2/jaxws/message/factory/
src/org/apache/axis2/jaxws/message/impl/ test/org...
Author: scheu
Date: Fri Feb 2 15:47:58 2007
New Revision: 502800
URL: http://svn.apache.org/viewvc?view=rev&rev=502800
Log:
AXIS2-2093
Contributor:Rich Scheuerle
JAX-WS Dispatch/Provider corner case tests
Modified:
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/Block.java
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/JAXBBlockFactoryImpl.java
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/JAXBBlockImpl.java
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/OMBlockFactoryImpl.java
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/OMBlockImpl.java
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/SOAPEnvelopeBlockFactoryImpl.java
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/SOAPEnvelopeBlockImpl.java
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/SourceBlockFactoryImpl.java
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/databinding/impl/XMLStringBlockFactoryImpl.java
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/XMLStringBlockImpl.java
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/factory/BlockFactory.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/provider/SourceMessageProviderTests.java
webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/provider/SourceProviderTests.java
webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/provider/StringProviderTests.java
webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/provider/source/SourceProvider.java
webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/provider/string/StringProvider.java
Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/Block.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/Block.java?view=diff&rev=502800&r1=502799&r2=502800
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/Block.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/Block.java Fri Feb 2 15:47:58 2007
@@ -141,4 +141,9 @@
* @param parent
*/
public void setParent(Message parent);
+
+ /**
+ * @return true if data is always an element; false if possibly mixed content or multiple elements
+ */
+ public boolean isElementData();
}
Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/JAXBBlockFactoryImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/JAXBBlockFactoryImpl.java?view=diff&rev=502800&r1=502799&r2=502800
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/JAXBBlockFactoryImpl.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/JAXBBlockFactoryImpl.java Fri Feb 2 15:47:58 2007
@@ -97,4 +97,8 @@
}
}
+ public boolean isElement() {
+ return true;
+ }
+
}
Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/JAXBBlockImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/JAXBBlockImpl.java?view=diff&rev=502800&r1=502799&r2=502800
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/JAXBBlockImpl.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/JAXBBlockImpl.java Fri Feb 2 15:47:58 2007
@@ -378,4 +378,8 @@
// </xsd:simpleType>
return (t.isArray() || List.class.isAssignableFrom(t));
}
+
+ public boolean isElementData() {
+ return true;
+ }
}
Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/OMBlockFactoryImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/OMBlockFactoryImpl.java?view=diff&rev=502800&r1=502799&r2=502800
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/OMBlockFactoryImpl.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/OMBlockFactoryImpl.java Fri Feb 2 15:47:58 2007
@@ -52,4 +52,8 @@
return new OMBlockImpl((OMElement) businessObject, this);
}
+ public boolean isElement() {
+ return true;
+ }
+
}
Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/OMBlockImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/OMBlockImpl.java?view=diff&rev=502800&r1=502799&r2=502800
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/OMBlockImpl.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/OMBlockImpl.java Fri Feb 2 15:47:58 2007
@@ -62,4 +62,8 @@
OMElement om = (OMElement) busObject;
om.serialize(writer);
}
+
+ public boolean isElementData() {
+ return true;
+ }
}
Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/SOAPEnvelopeBlockFactoryImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/SOAPEnvelopeBlockFactoryImpl.java?view=diff&rev=502800&r1=502799&r2=502800
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/SOAPEnvelopeBlockFactoryImpl.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/SOAPEnvelopeBlockFactoryImpl.java Fri Feb 2 15:47:58 2007
@@ -42,4 +42,8 @@
return new SOAPEnvelopeBlockImpl((SOAPEnvelope) businessObject, null, qName, this);
}
+ public boolean isElement() {
+ return true;
+ }
+
}
Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/SOAPEnvelopeBlockImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/SOAPEnvelopeBlockImpl.java?view=diff&rev=502800&r1=502799&r2=502800
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/SOAPEnvelopeBlockImpl.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/SOAPEnvelopeBlockImpl.java Fri Feb 2 15:47:58 2007
@@ -96,4 +96,8 @@
private static QName getQName(SOAPEnvelope env) {
return new QName(env.getNamespaceURI(), env.getLocalName(),env.getPrefix());
}
+
+ public boolean isElementData() {
+ return true;
+ }
}
Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/SourceBlockFactoryImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/SourceBlockFactoryImpl.java?view=diff&rev=502800&r1=502799&r2=502800
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/SourceBlockFactoryImpl.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/SourceBlockFactoryImpl.java Fri Feb 2 15:47:58 2007
@@ -55,4 +55,8 @@
return new SourceBlockImpl(omElement, qName, this);
}
+ public boolean isElement() {
+ return false;
+ }
+
}
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?view=diff&rev=502800&r1=502799&r2=502800
==============================================================================
--- 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 Fri Feb 2 15:47:58 2007
@@ -215,6 +215,11 @@
throw ExceptionFactory.makeWebServiceException(Messages.getMessage("SourceMissingSupport", busObject.getClass().getName()));
}
}
+
+
+ public boolean isElementData() {
+ return false; // The source could be a text or element etc.
+ }
}
Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/XMLStringBlockFactoryImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/XMLStringBlockFactoryImpl.java?view=diff&rev=502800&r1=502799&r2=502800
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/XMLStringBlockFactoryImpl.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/XMLStringBlockFactoryImpl.java Fri Feb 2 15:47:58 2007
@@ -53,4 +53,8 @@
return new XMLStringBlockImpl(omElement, qName, this);
}
+ public boolean isElement() {
+ return false;
+ }
+
}
Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/XMLStringBlockImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/XMLStringBlockImpl.java?view=diff&rev=502800&r1=502799&r2=502800
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/XMLStringBlockImpl.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/XMLStringBlockImpl.java Fri Feb 2 15:47:58 2007
@@ -80,4 +80,9 @@
XMLStreamReader reader = _getReaderFromBO(busObject, busContext);
_outputFromReader(reader, writer);
}
+
+
+ public boolean isElementData() {
+ return false; // The text could be element or text or something else
+ }
}
Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/factory/BlockFactory.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/factory/BlockFactory.java?view=diff&rev=502800&r1=502799&r2=502800
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/factory/BlockFactory.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/factory/BlockFactory.java Fri Feb 2 15:47:58 2007
@@ -82,4 +82,11 @@
* @throws WebServiceException
*/
public Block createFrom(Object businessObject, Object context, QName qName) throws WebServiceException;
+
+ /**
+ * @return true if business object must be rendered as an element
+ * example JAXBFactory ...true
+ * example SourceFactory...false
+ */
+ public boolean isElement();
}
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?view=diff&rev=502800&r1=502799&r2=502800
==============================================================================
--- 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 Fri Feb 2 15:47:58 2007
@@ -28,6 +28,7 @@
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMNamespace;
import org.apache.axiom.om.OMNode;
+import org.apache.axiom.om.impl.builder.StAXOMBuilder;
import org.apache.axiom.om.impl.llom.OMElementImpl;
import org.apache.axiom.om.impl.llom.OMSourcedElementImpl;
import org.apache.axiom.soap.SOAP11Constants;
@@ -280,6 +281,8 @@
log.debug("getBodyBlock PERFORMANT: Get the block using the block factory, " + blockFactory);
}
+ // TODO Need to upgrade the code to get Blocks that represent text and elements.
+
// Calling getBodyBlock assumes that there is only one or zero body blocks in the message. Subsequent
// Blocks are lost. If the caller needs access to multiple body blocks, then getBodyBlocks(index,...) should be used
@@ -335,12 +338,29 @@
it.remove();
}
- // The block is supposed to represent a single element.
- // But if it does not represent an element , the following will fail.
- QName qName = block.getQName();
+ if (block.isElementData()) {
+ // If the block is element data then it is safe to create
+ // an OMElement representing the block
+
+ // The block is supposed to represent a single element.
+ // But if it does not represent an element , the following will fail.
+ QName qName = block.getQName();
- OMElement newOM = _createOMElementFromBlock(qName, block, soapFactory);
- bElement.addChild(newOM);
+ OMElement newOM = _createOMElementFromBlock(qName, block, soapFactory);
+ bElement.addChild(newOM);
+ } else {
+ // This needs to be fixed, but for now we will require that there must be an element...otherwise no block is added
+ try {
+ QName qName = block.getQName();
+
+ OMElement newOM = _createOMElementFromBlock(qName, block, soapFactory);
+ bElement.addChild(newOM);
+ } catch (Throwable t) {
+ if (log.isDebugEnabled()) {
+ log.debug("An attempt was made to pass a Source or String that does not have an xml element. Processing continues with an empty payload.");
+ }
+ }
+ }
}
public void removeBodyBlock(int index) throws WebServiceException {
Modified: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/provider/SourceMessageProviderTests.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/provider/SourceMessageProviderTests.java?view=diff&rev=502800&r1=502799&r2=502800
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/provider/SourceMessageProviderTests.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/provider/SourceMessageProviderTests.java Fri Feb 2 15:47:58 2007
@@ -45,6 +45,8 @@
super(name);
}
+
+
public void testProviderSource(){
try{
String resourceDir = new File(providerResourceDir, xmlDir).getAbsolutePath();
Modified: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/provider/SourceProviderTests.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/provider/SourceProviderTests.java?view=diff&rev=502800&r1=502799&r2=502800
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/provider/SourceProviderTests.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/provider/SourceProviderTests.java Fri Feb 2 15:47:58 2007
@@ -16,15 +16,24 @@
*/
package org.apache.axis2.jaxws.provider;
+import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
+import java.io.StringWriter;
import javax.xml.namespace.QName;
+import javax.xml.soap.SOAPFault;
+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 javax.xml.ws.BindingProvider;
import javax.xml.ws.Dispatch;
import javax.xml.ws.Service;
+import javax.xml.ws.soap.SOAPFaultException;
public class SourceProviderTests extends ProviderTestCase {
@@ -43,6 +52,183 @@
public SourceProviderTests(String name) {
super(name);
+ }
+
+ private Dispatch<Source> getDispatch() {
+ Service svc = Service.create(serviceName);
+ svc.addPort(portName, null, endpointUrl);
+
+ Dispatch<Source> dispatch = svc
+ .createDispatch(portName, Source.class, Service.Mode.PAYLOAD);
+
+ // Force soap action because we are passing junk over the wire
+ dispatch.getRequestContext().put(BindingProvider.SOAPACTION_USE_PROPERTY, Boolean.TRUE);
+ dispatch.getRequestContext().put(BindingProvider.SOAPACTION_URI_PROPERTY,"invoke");
+
+ return dispatch;
+
+ }
+
+ private Source getSource(String text) {
+ if (text == null) {
+ return null;
+ } else {
+ ByteArrayInputStream stream = new ByteArrayInputStream(text.getBytes());
+ return new StreamSource((InputStream) stream);
+ }
+
+ }
+
+ private String getString(Source source) throws Exception {
+ if (source == null) {
+ return null;
+ }
+ StringWriter writer = new StringWriter();
+ Transformer t = TransformerFactory.newInstance().newTransformer();
+ Result result = new StreamResult(writer);
+ t.transform(source, result);
+ return writer.getBuffer().toString();
+
+ }
+
+ public void testNormal() throws Exception {
+ System.out.println("---------------------------------------");
+ System.out.println("test: " + getName());
+
+ Dispatch<Source> dispatch = getDispatch();
+
+ String request = "<invoke>hello world</invoke>";
+ Source requestSource = getSource(request);
+ Source responseSource = dispatch.invoke(requestSource);
+ String response = getString(responseSource);
+
+ assertTrue(response.contains(request));
+ }
+
+ public void testEmptyString() throws Exception {
+ System.out.println("---------------------------------------");
+ System.out.println("test: " + getName());
+
+ Dispatch<Source> dispatch = getDispatch();
+
+ String request = "";
+ Source requestSource = getSource(request);
+ Source responseSource = dispatch.invoke(requestSource);
+ String response = getString(responseSource);
+
+ // The current belief is that this should return a null indicating
+ // the nothing is echo'ed
+ assertTrue(response == null);
+
+ //assertTrue(request.equals(response));
+ }
+
+ public void testNullSource() throws Exception {
+ System.out.println("---------------------------------------");
+ System.out.println("test: " + getName());
+
+ Dispatch<Source> dispatch = getDispatch();
+
+ Source responseSource = dispatch.invoke(null);
+ String response = getString(responseSource);
+
+ // The current belief is that this should return a null indicating
+ // the nothing is echo'ed
+ assertTrue(response == null);
+ }
+
+ public void testEmptySource() throws Exception {
+ System.out.println("---------------------------------------");
+ System.out.println("test: " + getName());
+
+ Dispatch<Source> dispatch = getDispatch();
+
+ Source responseSource = dispatch.invoke(new StreamSource());
+ String response = getString(responseSource);
+
+ // The current belief is that this should return a null indicating
+ // the nothing is echo'ed
+ assertTrue(response == null);
+ }
+
+ public void testNonNullString() throws Exception {
+ System.out.println("---------------------------------------");
+ System.out.println("test: " + getName());
+
+ Dispatch<Source> dispatch = getDispatch();
+
+ String request = "mixedContent";
+ Source requestSource = getSource(request);
+ Source responseSource = dispatch.invoke(requestSource);
+ String response = getString(responseSource);
+
+ // The current implementation does not send the mixedContent over the wire, so the
+ // expectation is that the echo'd response is null
+ assertTrue(response == null);
+ }
+
+ public void testCommentString() throws Exception {
+ System.out.println("---------------------------------------");
+ System.out.println("test: " + getName());
+
+ Dispatch<Source> dispatch = getDispatch();
+
+ String request = "<!--comment-->";
+ Source requestSource = getSource(request);
+ Source responseSource = dispatch.invoke(requestSource);
+ String response = getString(responseSource);
+ // The current implementation does not send the comment over the wire, so the
+ // expectation is that the echo'd response is null
+ assertTrue(response == null);
+ }
+
+ public void testTwoElementsString() throws Exception {
+ System.out.println("---------------------------------------");
+ System.out.println("test: " + getName());
+
+ Dispatch<Source> dispatch = getDispatch();
+
+ String request = "<a>hello</a><b>world</b>";
+ Source requestSource = getSource(request);
+ Source responseSource = dispatch.invoke(requestSource);
+ String response = getString(responseSource);
+
+ // The current implementatin only sends the first element
+ // So the echo'd response is just the first one.
+ assertTrue(response.contains("<a>hello</a>"));
+ }
+
+ public void testTwoElementsAndMixedContentString() throws Exception {
+ System.out.println("---------------------------------------");
+ System.out.println("test: " + getName());
+
+ Dispatch<Source> dispatch = getDispatch();
+
+ String request = "mixed1<a>hello</a>mixed2<b>world</b>mixed3";
+ Source requestSource = getSource(request);
+ Source responseSource = dispatch.invoke(requestSource);
+ String response = getString(responseSource);
+ // The current implementation only sends the first element.
+ // The mixed content (mixed1) interferes and thus nothing is sent.
+ assertTrue(response == null);
+ }
+
+ public void testException() throws Exception {
+ System.out.println("---------------------------------------");
+ System.out.println("test: " + getName());
+
+ Dispatch<Source> dispatch = getDispatch();
+
+ String request = "<invoke>throwWebServiceException</invoke>";
+ try {
+ Source requestSource = getSource(request);
+ Source responseSource = dispatch.invoke(requestSource);
+ String response = getString(responseSource);
+ fail("Expected Exception");
+ } catch (SOAPFaultException e) {
+ SOAPFault sf = e.getFault();
+ assertTrue(sf.getFaultString().equals("provider"));
+ }
}
public void testProviderSource(){
Modified: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/provider/StringProviderTests.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/provider/StringProviderTests.java?view=diff&rev=502800&r1=502799&r2=502800
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/provider/StringProviderTests.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/provider/StringProviderTests.java Fri Feb 2 15:47:58 2007
@@ -17,10 +17,12 @@
package org.apache.axis2.jaxws.provider;
import javax.xml.namespace.QName;
+import javax.xml.soap.SOAPFault;
import javax.xml.ws.BindingProvider;
import javax.xml.ws.Dispatch;
import javax.xml.ws.ProtocolException;
import javax.xml.ws.Service;
+import javax.xml.ws.soap.SOAPFaultException;
public class StringProviderTests extends ProviderTestCase {
@@ -40,49 +42,128 @@
super(name);
}
- public void testProviderString() throws Exception {
-
- System.out.println("---------------------------------------");
- System.out.println("test: " + getName());
-
+ private Dispatch<String> getDispatch() {
Service svc = Service.create(serviceName);
svc.addPort(portName, null, endpointUrl);
Dispatch<String> dispatch = svc
.createDispatch(portName, String.class, Service.Mode.PAYLOAD);
- System.out.println(">> Invoking Dispatch<String> StringProviderService");
- String retVal = dispatch.invoke(xmlString);
- System.out.println(">> Response [" + retVal + "]");
- Exception ex = null;
- try {
- String re = dispatch.invoke("<invoke>throwException</invoke>");
- } catch (Exception e) {
- ex = e;
- assertTrue(e instanceof ProtocolException);
- }
- assertNotNull(ex);
+ // Force soap action because we are passing junk over the wire
+ dispatch.getRequestContext().put(BindingProvider.SOAPACTION_USE_PROPERTY, Boolean.TRUE);
+ dispatch.getRequestContext().put(BindingProvider.SOAPACTION_URI_PROPERTY,"echoString");
+
+ return dispatch;
+
+ }
+ public void testNormal() throws Exception {
+ System.out.println("---------------------------------------");
+ System.out.println("test: " + getName());
+
+ Dispatch<String> dispatch = getDispatch();
+
+ String request = "<invoke>hello world</invoke>";
+ String response = dispatch.invoke(request);
+ assertTrue(request.equals(response));
}
- public void testSyncPayloadModeWithNull() throws Exception {
+ public void testEmptyString() throws Exception {
System.out.println("---------------------------------------");
System.out.println("test: " + getName());
- Service svc = Service.create(serviceName);
- svc.addPort(portName, null, endpointUrl);
+ Dispatch<String> dispatch = getDispatch();
- Dispatch<String> dispatch = svc
- .createDispatch(portName, String.class, Service.Mode.PAYLOAD);
+ String request = "";
+ String response = dispatch.invoke(request);
- System.out.println(">> Invoking Dispatch<String> StringProviderService");
- dispatch.getRequestContext().put(BindingProvider.SOAPACTION_USE_PROPERTY, Boolean.TRUE);
- dispatch.getRequestContext().put(BindingProvider.SOAPACTION_URI_PROPERTY,"echoString");
- // Invoke the Dispatch
- System.out.println(">> Invoking sync Dispatch With Null Object");
- String response = dispatch.invoke(null);
-
- assertNotNull("dispatch invoke returned null", response);
- System.out.println(response);
+ // The current belief is that this should return a null indicating
+ // the nothing is echo'ed
+ assertTrue(response == null);
+
+ //assertTrue(request.equals(response));
+ }
+
+ public void testNullString() throws Exception {
+ System.out.println("---------------------------------------");
+ System.out.println("test: " + getName());
+
+ Dispatch<String> dispatch = getDispatch();
+
+ String request = null;
+ String response = dispatch.invoke(request);
+
+ // The current belief is that this should return a null indicating
+ // the nothing is echo'ed
+ assertTrue(response == null);
+ }
+
+ public void testNonNullString() throws Exception {
+ System.out.println("---------------------------------------");
+ System.out.println("test: " + getName());
+
+ Dispatch<String> dispatch = getDispatch();
+
+ String request = "mixedContent";
+ String response = dispatch.invoke(request);
+
+ // The current implementation does not send the mixedContent over the wire, so the
+ // expectation is that the echo'd response is null
+ assertTrue(response == null);
+ }
+
+ public void testCommentString() throws Exception {
+ System.out.println("---------------------------------------");
+ System.out.println("test: " + getName());
+
+ Dispatch<String> dispatch = getDispatch();
+
+ String request = "<!--comment-->";
+ String response = dispatch.invoke(request);
+ // The current implementation does not send the comment over the wire, so the
+ // expectation is that the echo'd response is null
+ assertTrue(response == null);
+ }
+
+ public void testTwoElementsString() throws Exception {
+ System.out.println("---------------------------------------");
+ System.out.println("test: " + getName());
+
+ Dispatch<String> dispatch = getDispatch();
- }
+ String request = "<a>hello</a><b>world</b>";
+ String response = dispatch.invoke(request);
+
+ // The current implementatin only sends the first element
+ // So the echo'd response is just the first one.
+ assertTrue("<a>hello</a>".equals(response));
+ }
+
+ public void testTwoElementsAndMixedContentString() throws Exception {
+ System.out.println("---------------------------------------");
+ System.out.println("test: " + getName());
+
+ Dispatch<String> dispatch = getDispatch();
+
+ String request = "mixed1<a>hello</a>mixed2<b>world</b>mixed3";
+ String response = dispatch.invoke(request);
+ // The current implementation only sends the first element.
+ // The mixed content (mixed1) interferes and thus nothing is sent.
+ assertTrue(response == null);
+ }
+
+ public void testException() throws Exception {
+ System.out.println("---------------------------------------");
+ System.out.println("test: " + getName());
+
+ Dispatch<String> dispatch = getDispatch();
+
+ String request = "<invoke>throwWebServiceException</invoke>";
+ try {
+ String response = dispatch.invoke(request);
+ fail("Expected Exception");
+ } catch (SOAPFaultException e) {
+ SOAPFault sf = e.getFault();
+ assertTrue(sf.getFaultString().equals("provider"));
+ }
+ }
}
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?view=diff&rev=502800&r1=502799&r2=502800
==============================================================================
--- 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 Fri Feb 2 15:47:58 2007
@@ -23,34 +23,52 @@
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.TransformerFactoryConfigurationError;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import javax.xml.ws.Provider;
+import javax.xml.ws.WebServiceException;
import javax.xml.ws.WebServiceProvider;
@WebServiceProvider()
public class SourceProvider implements Provider<Source> {
- String responseAsString = new String("<ns2:ReturnType xmlns:ns2=\"http://test\"><return_str>some response</return_str></ns2:ReturnType>");
+
+ // Same logic as StringProvider
public Source invoke(Source source) {
+
System.out.println(">> SourceProvider: Request received.\n");
- //System.out.println(">> Source toString: \n"+source.toString());
+ if (source == null) {
+ return source;
+ }
+
+ // Non-null source
- 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();
+ StringWriter writer = new StringWriter();
+ try {
+ Transformer t = TransformerFactory.newInstance().newTransformer();
+ Result result = new StreamResult(writer);
+ t.transform(source, result);
+ } catch (TransformerConfigurationException e) {
+ throw new WebServiceException(e);
+ } catch (TransformerFactoryConfigurationError e) {
+ throw new WebServiceException(e);
+ } catch (TransformerException e) {
+ throw new WebServiceException(e);
+ }
+ String text = writer.getBuffer().toString();
+ System.out.println(">> Source Request on Server: \n"+ text);
+
+ if (text != null && text.contains("throwWebServiceException")) {
+ throw new WebServiceException("provider");
}
- return null;
+
+ ByteArrayInputStream stream = new ByteArrayInputStream(text.getBytes());
+ Source srcStream = new StreamSource((InputStream) stream);
+ return srcStream;
+
}
Modified: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/provider/string/StringProvider.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/provider/string/StringProvider.java?view=diff&rev=502800&r1=502799&r2=502800
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/provider/string/StringProvider.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/provider/string/StringProvider.java Fri Feb 2 15:47:58 2007
@@ -22,25 +22,14 @@
@WebServiceProvider()
public class StringProvider implements Provider<String> {
-
- private static String responseGood = "<provider><message>request processed</message></provider>";
- private static String responseBad = "<provider><message>ERROR:null request received</message></provider>";
- public String invoke(String obj) {
- if (obj != null) {
-
- // TODO probably not the ideal place for a provider fault scenario test, but it serves its purpose
- if (obj.equals("<invoke>throwException</invoke>")) {
- throw new WebServiceException("provider");
- }
-
- String str = (String) obj;
- System.out.println(">> StringProvider received a new request");
- System.out.println(">> request [" + str + "]");
-
- return responseGood;
+ public String invoke(String text) {
+ System.out.println("StringProvider invoke received the message [" + text + "]");
+ if (text != null && text.contains("throwWebServiceException")) {
+ throw new WebServiceException("provider");
+ } else {
+ // Echo the input
+ return text;
}
- System.out.println(">> ERROR:null request received");
- return responseBad;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org