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 2006/09/25 17:05:31 UTC
svn commit: r449702 - in /webservices/axis2/trunk/java/modules/jaxws:
src/org/apache/axis2/jaxws/i18n/ src/org/apache/axis2/jaxws/message/impl/
src/org/apache/axis2/jaxws/message/util/
src/org/apache/axis2/jaxws/message/util/impl/ test/org/apache/axis2...
Author: scheu
Date: Mon Sep 25 08:05:31 2006
New Revision: 449702
URL: http://svn.apache.org/viewvc?view=rev&rev=449702
Log:
AXIS2-1213
Fixes and tests to JAX-WS related to SOAP 1.2 support
Modified:
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/impl/MessageImpl.java
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/util/SAAJConverter.java
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/util/impl/SAAJConverterImpl.java
webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/message/MessageTests.java
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?view=diff&rev=449702&r1=449701&r2=449702
==============================================================================
--- 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 Sep 25 08:05:31 2006
@@ -100,3 +100,4 @@
AsyncListenerErr1=AxisCallback Object cannot be null, Internal error.
DocLitProxyHandlerErr1=As per WS-I compliance, Multi part WSDL not allowed for Doc/Lit NON Wrapped request, Method invoked has multiple input parameter.
DocLitProxyHandlerErr2 = Method Input parameter for NON Wrapped Request cannot be null.
+SOAP12WithSAAJ12Err=A SOAP 1.2 Message cannot be rendered in an SAAJ 1.2 Object Model.
\ No newline at end of file
Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/MessageImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/MessageImpl.java?view=diff&rev=449702&r1=449701&r2=449702
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/MessageImpl.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/MessageImpl.java Mon Sep 25 08:05:31 2006
@@ -23,6 +23,7 @@
import javax.xml.soap.MessageFactory;
import javax.xml.soap.MimeHeaders;
+import javax.xml.soap.SOAPBody;
import javax.xml.soap.SOAPEnvelope;
import javax.xml.soap.SOAPMessage;
import javax.xml.stream.XMLStreamException;
@@ -30,6 +31,7 @@
import javax.xml.stream.XMLStreamWriter;
import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMNamespace;
import org.apache.axis2.jaxws.ExceptionFactory;
import org.apache.axis2.jaxws.i18n.Messages;
import org.apache.axis2.jaxws.message.Attachment;
@@ -39,7 +41,9 @@
import org.apache.axis2.jaxws.message.Protocol;
import org.apache.axis2.jaxws.message.XMLPart;
import org.apache.axis2.jaxws.message.factory.BlockFactory;
+import org.apache.axis2.jaxws.message.factory.SAAJConverterFactory;
import org.apache.axis2.jaxws.message.factory.XMLPartFactory;
+import org.apache.axis2.jaxws.message.util.SAAJConverter;
import org.apache.axis2.jaxws.registry.FactoryRegistry;
import java.io.ByteArrayOutputStream;
@@ -56,6 +60,12 @@
List<Attachment> attachments = new ArrayList<Attachment>(); // non-xml parts
boolean mtomEnabled;
+ // Constants
+ private static final String SOAP11_ENV_NS = "http://schemas.xmlsoap.org/soap/envelope/";
+ private static final String SOAP12_ENV_NS = "http://www.w3.org/2003/05/soap-envelope";
+ private static final String SOAP11_CONTENT_TYPE ="text/xml";
+ private static final String SOAP12_CONTENT_TYPE = "application/soap+xml";
+
/**
* MessageImpl should be constructed via the MessageFactory.
* This constructor constructs an empty message with the specified protocol
@@ -113,13 +123,19 @@
try {
// Get OMElement from XMLPart.
OMElement element = xmlPart.getAsOMElement();
+
+ // Get the namespace so that we can determine SOAP11 or SOAP12
+ OMNamespace ns = element.getNamespace();
+
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
element.serialize(outStream);
// Create InputStream
ByteArrayInputStream inStream = new ByteArrayInputStream(outStream
.toByteArray());
- MessageFactory mf = MessageFactory.newInstance();
+
+ // Create MessageFactory that supports the version of SOAP in the om element
+ MessageFactory mf = getSAAJConverter().createMessageFactory(ns.getNamespaceURI());
// Create soapMessage object from Message Factory using the input
// stream created from OM.
@@ -128,9 +144,16 @@
// For now I will create a default header
MimeHeaders defaultHeader = new MimeHeaders();
- // FIXME: Need to toggle based on SOAP 1.1 or SOAP 1.2
- defaultHeader.addHeader("Content-type", "text/xml; charset=UTF-8");
+ // Toggle based on SOAP 1.1 or SOAP 1.2
+ String contentType = null;
+ if (ns.getNamespaceURI().equals(SOAP11_ENV_NS)) {
+ contentType = SOAP11_CONTENT_TYPE;
+ } else {
+ contentType = SOAP12_CONTENT_TYPE;
+ }
+ defaultHeader.addHeader("Content-type", contentType +"; charset=UTF-8");
SOAPMessage soapMessage = mf.createMessage(defaultHeader, inStream);
+
return soapMessage;
} catch (Exception e) {
throw ExceptionFactory.makeMessageException(e);
@@ -233,6 +256,20 @@
public String traceString(String indent) {
return xmlPart.traceString(indent);
+ }
+
+ /**
+ * Load the SAAJConverter
+ * @return SAAJConverter
+ */
+ SAAJConverter converter = null;
+ private SAAJConverter getSAAJConverter() {
+ if (converter == null) {
+ SAAJConverterFactory factory = (
+ SAAJConverterFactory)FactoryRegistry.getFactory(SAAJConverterFactory.class);
+ converter = factory.getSAAJConverter();
+ }
+ return converter;
}
public void addAttachment(Attachment data) {
Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/util/SAAJConverter.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/util/SAAJConverter.java?view=diff&rev=449702&r1=449701&r2=449702
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/util/SAAJConverter.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/util/SAAJConverter.java Mon Sep 25 08:05:31 2006
@@ -16,8 +16,10 @@
*/
package org.apache.axis2.jaxws.message.util;
+import javax.xml.soap.MessageFactory;
import javax.xml.soap.SOAPElement;
import javax.xml.soap.SOAPEnvelope;
+import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPFactory;
import org.apache.axiom.om.OMElement;
@@ -83,4 +85,13 @@
public SOAPElement toSAAJ(OMElement omElement, SOAPElement parent, SOAPFactory sf)
throws MessageException;
+ /**
+ * Creates a MessageFactory that can support the SOAP version identified
+ * by the specified envelope namespace.
+ * @param namespace
+ * @return
+ * @throws MessageException if the namespace is SOAP 1.2 and the SAAJ does not support
+ * SOAP 1.2 or the namespace is unknown.
+ */
+ public MessageFactory createMessageFactory(String namespace) throws SOAPException, MessageException;
}
Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/util/impl/SAAJConverterImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/util/impl/SAAJConverterImpl.java?view=diff&rev=449702&r1=449701&r2=449702
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/util/impl/SAAJConverterImpl.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/util/impl/SAAJConverterImpl.java Mon Sep 25 08:05:31 2006
@@ -16,6 +16,7 @@
*/
package org.apache.axis2.jaxws.message.util.impl;
+import java.lang.reflect.Method;
import java.util.Iterator;
import javax.xml.namespace.QName;
@@ -35,6 +36,7 @@
import javax.xml.stream.XMLStreamReader;
import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMNamespace;
import org.apache.axiom.om.impl.builder.StAXOMBuilder;
import org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder;
import org.apache.axis2.jaxws.ExceptionFactory;
@@ -49,6 +51,13 @@
*/
public class SAAJConverterImpl implements SAAJConverter {
+ private static final String SOAP11_ENV_NS = "http://schemas.xmlsoap.org/soap/envelope/";
+ private static final String SOAP12_ENV_NS = "http://www.w3.org/2003/05/soap-envelope";
+
+ public static final String SOAP_1_1_PROTOCOL = "SOAP 1.1 Protocol";
+ public static final String SOAP_1_2_PROTOCOL = "SOAP 1.2 Protocol";
+ public static final String DYNAMIC_PROTOCOL = "Dynamic Protocol";
+
/**
* Constructed via SAAJConverterFactory
*/
@@ -64,7 +73,8 @@
SOAPEnvelope soapEnvelope = null;
try {
// Build the default envelope
- MessageFactory mf = MessageFactory.newInstance();
+ OMNamespace ns = omEnvelope.getNamespace();
+ MessageFactory mf = createMessageFactory(ns.getNamespaceURI());
SOAPMessage sm = mf.createMessage();
SOAPPart sp = sm.getSOAPPart();
soapEnvelope = sp.getEnvelope();
@@ -75,17 +85,12 @@
SOAPBody soapBody = soapEnvelope.getBody();
if (soapBody != null) {
soapBody.detachNode();
- //soapEnvelope.removeChild(soapBody);
}
SOAPHeader soapHeader = soapEnvelope.getHeader();
if (soapHeader != null) {
soapHeader.detachNode();
- //soapEnvelope.removeChild(soapHeader);
}
- // Adjust tag data on the SOAPEnvelope. (i.e. set the prefix, set the attributes)
- //adjustTagData(soapEnvelope, omEnvelope);
-
// We don't know if there is a real OM tree or just a backing XMLStreamReader.
// The best way to walk the data is to get the XMLStreamReader and use this
// to build the SOAPElements
@@ -176,6 +181,50 @@
return buildSOAPTree(nc, null, parent, reader, false);
}
+ /**
+ * Create MessageFactory using information from the envelope namespace
+ * @param namespace
+ * @return
+ */
+ public MessageFactory createMessageFactory(String namespace) throws MessageException, SOAPException {
+ Method m = getNewInstanceProtocolMethod();
+ MessageFactory mf = null;
+ if (m == null) {
+ if (namespace.equals(SOAP11_ENV_NS)) {
+ mf = MessageFactory.newInstance();
+ } else {
+ throw ExceptionFactory.makeMessageException(Messages.getMessage("SOAP12WithSAAJ12Err"));
+ }
+ } else {
+ String protocol = DYNAMIC_PROTOCOL;
+ if (namespace.equals(SOAP11_ENV_NS)) {
+ protocol = SOAP_1_1_PROTOCOL;
+ } else if (namespace.equals(SOAP12_ENV_NS)) {
+ protocol = SOAP_1_2_PROTOCOL;
+ }
+ try {
+ mf = (MessageFactory) m.invoke(null, new Object[] {protocol});
+ } catch (Exception e) {
+ throw ExceptionFactory.makeMessageException(e);
+ }
+ }
+ return mf;
+ }
+
+ private Method newInstanceProtocolMethod = null;
+ private Method getNewInstanceProtocolMethod() {
+ if (newInstanceProtocolMethod == null) {
+ try {
+ newInstanceProtocolMethod = MessageFactory.class.getMethod("newInstance", new Class[] {String.class});
+ } catch (Exception e) {
+ // TODO Might want to log this.
+ // Flow to here indicates that the installed SAAJ model does not support version 1.3
+ newInstanceProtocolMethod = null;
+ }
+ }
+ return newInstanceProtocolMethod;
+ }
+
/**
* Build SOAPTree
* Either the root or the parent is null.
Modified: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/message/MessageTests.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/message/MessageTests.java?view=diff&rev=449702&r1=449701&r2=449702
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/message/MessageTests.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/message/MessageTests.java Mon Sep 25 08:05:31 2006
@@ -18,11 +18,11 @@
import java.io.ByteArrayOutputStream;
import java.io.StringReader;
-import java.util.HashMap;
import javax.xml.bind.JAXBContext;
import javax.xml.namespace.QName;
import javax.xml.soap.SOAPEnvelope;
+import javax.xml.soap.SOAPMessage;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamReader;
@@ -33,8 +33,10 @@
import org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder;
import org.apache.axis2.jaxws.message.factory.JAXBBlockFactory;
import org.apache.axis2.jaxws.message.factory.MessageFactory;
+import org.apache.axis2.jaxws.message.factory.SAAJConverterFactory;
import org.apache.axis2.jaxws.message.factory.XMLStringBlockFactory;
import org.apache.axis2.jaxws.message.util.Reader2Writer;
+import org.apache.axis2.jaxws.message.util.SAAJConverter;
import org.apache.axis2.jaxws.registry.FactoryRegistry;
import test.EchoStringResponse;
@@ -48,8 +50,14 @@
public class MessageTests extends TestCase {
// String test variables
- private static final String sampleEnvelopeHead =
- "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\">" +
+ private static final String soap11env = "http://schemas.xmlsoap.org/soap/envelope/";
+ private static final String soap12env = "http://www.w3.org/2003/05/soap-envelope";
+ private static final String sampleEnvelopeHead11 =
+ "<soapenv:Envelope xmlns:soapenv=\"" + soap11env + "\">" +
+ "<soapenv:Header /><soapenv:Body>";
+
+ private static final String sampleEnvelopeHead12 =
+ "<soapenv:Envelope xmlns:soapenv=\"" + soap12env + "\">" +
"<soapenv:Header /><soapenv:Body>";
private static final String sampleEnvelopeTail =
@@ -61,8 +69,13 @@
"<c>World</c>" +
"</pre:a>";
- private static final String sampleEnvelope =
- sampleEnvelopeHead +
+ private static final String sampleEnvelope11 =
+ sampleEnvelopeHead11 +
+ sampleText +
+ sampleEnvelopeTail;
+
+ private static final String sampleEnvelope12 =
+ sampleEnvelopeHead12 +
sampleText +
sampleEnvelopeTail;
@@ -71,17 +84,30 @@
"<echoStringReturn>sample return value</echoStringReturn>" +
"</echoStringResponse>";
- private static final String sampleJAXBEnvelope =
- sampleEnvelopeHead +
+ private static final String sampleJAXBEnvelope11 =
+ sampleEnvelopeHead11 +
+ sampleJAXBText +
+ sampleEnvelopeTail;
+
+ private static final String sampleJAXBEnvelope12 =
+ sampleEnvelopeHead12 +
sampleJAXBText +
sampleEnvelopeTail;
- private static final String sampleEnvelopeNoHeader =
- "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\">" +
+ private static final String sampleEnvelopeNoHeader11 =
+ "<soapenv:Envelope xmlns:soapenv=\""+ soap11env +"\">" +
"<soapenv:Body>" +
sampleText +
"</soapenv:Body></soapenv:Envelope>";
+ private static final String sampleEnvelopeNoHeader12 =
+ "<soapenv:Envelope xmlns:soapenv=\""+ soap12env +"\">" +
+ "<soapenv:Body>" +
+ sampleText +
+ "</soapenv:Body></soapenv:Envelope>";
+
+
+
private static final QName sampleQName = new QName("urn://sample", "a");
private static XMLInputFactory inputFactory = XMLInputFactory.newInstance();
@@ -194,8 +220,13 @@
* normal Dispatch<String> input flow
* @throws Exception
*/
-
- public void testStringInflow() throws Exception {
+ public void testStringInflow_soap11() throws Exception {
+ _testStringInflow(sampleEnvelope11);
+ }
+ public void testStringInflow_soap12() throws Exception {
+ _testStringInflow(sampleEnvelope12);
+ }
+ public void _testStringInflow(String sampleEnvelope) throws Exception {
// On inbound, there will already be an OM
// which represents the message. The following code simulates the input
@@ -231,7 +262,20 @@
* normal Dispatch<String> input flow with a JAX-WS Handler
* @throws Exception
*/
- public void testStringInflow2() throws Exception {
+ public void testStringInflow2_soap11() throws Exception {
+ _testStringInflow2(sampleEnvelope11);
+ }
+ public void testStringInflow2_soap12() throws Exception {
+ // Only run test if an SAAJ 1.3 MessageFactory is available
+ javax.xml.soap.MessageFactory mf = null;
+ try {
+ mf = getSAAJConverter().createMessageFactory(soap12env);
+ } catch (Exception e) {}
+ if (mf != null) {
+ _testStringInflow2(sampleEnvelope12);
+ }
+ }
+ public void _testStringInflow2(String sampleEnvelope) throws Exception {
// On inbound, there will already be an OM
// which represents the message. The following code simulates the input
@@ -268,14 +312,75 @@
assertTrue(sampleText.equals(bo.toString()));
}
+
+ /**
+ * Create a Block representing an XMLString and simulate a
+ * normal Dispatch<String> input flow with a JAX-WS Handler that needs the whole Message
+ * @throws Exception
+ */
+ public void testStringInflow3_soap11() throws Exception {
+ _testStringInflow3(sampleEnvelope11);
+ }
+ public void testStringInflow3_soap12() throws Exception {
+ //Only run test if an SAAJ 1.3 MessageFactory is available
+ javax.xml.soap.MessageFactory mf = null;
+ try {
+ mf = getSAAJConverter().createMessageFactory(soap12env);
+ } catch (Exception e) {}
+ if (mf != null) {
+ _testStringInflow3(sampleEnvelope12);
+ }
+ }
+ public void _testStringInflow3(String sampleEnvelope) throws Exception {
+
+ // On inbound, there will already be an OM
+ // which represents the message. The following code simulates the input
+ // OM
+ StringReader sr = new StringReader(sampleEnvelope);
+ XMLStreamReader inflow = inputFactory.createXMLStreamReader(sr);
+ StAXSOAPModelBuilder builder = new StAXSOAPModelBuilder(inflow, null);
+ OMElement omElement = builder.getSOAPEnvelope();
+
+ // The JAX-WS layer creates a Message from the OM
+ MessageFactory mf = (MessageFactory)
+ FactoryRegistry.getFactory(MessageFactory.class);
+ Message m = mf.createFrom(omElement);
+
+ // If there is a JAX-WS handler, the Message is converted into a SOAPEnvelope
+ SOAPMessage sm = m.getAsSOAPMessage();
+
+ // Normally the handler would not touch the body...but for our scenario, assume that it does.
+ String name = sm.getSOAPBody().getFirstChild().getLocalName();
+ assertTrue("a".equals(name));
+
+ // The next thing that will happen
+ // is the proxy code will ask for the business object (String).
+ XMLStringBlockFactory blockFactory =
+ (XMLStringBlockFactory) FactoryRegistry.getFactory(XMLStringBlockFactory.class);
+ Block block = m.getBodyBlock(0, null, blockFactory);
+ Object bo = block.getBusinessObject(true);
+ assertTrue(bo instanceof String);
+
+ // The block should be consumed
+ assertTrue(block.isConsumed());
+
+ // Check the String for accuracy
+ assertTrue(sampleText.equals(bo.toString()));
+
+ }
/**
* Create a Block representing an XMLString, but this time use one that
* doesn't have a <soap:Header> element in it.
* @throws Exception
*/
- public void testStringInflow3() throws Exception {
-
+ public void testStringInflow4_soap11() throws Exception {
+ _testStringInflow4(sampleEnvelopeNoHeader11);
+ }
+ public void testStringInflow4_soap12() throws Exception {
+ _testStringInflow4(sampleEnvelopeNoHeader12);
+ }
+ public void _testStringInflow4(String sampleEnvelopeNoHeader) throws Exception {
// On inbound, there will already be an OM
// which represents the message. The following code simulates the input
// OM
@@ -357,7 +462,13 @@
assertTrue(newText.contains("Body"));
}
- public void testJAXBInflow() throws Exception {
+ public void testJAXBInflow_soap11() throws Exception {
+ _testJAXBInflow(sampleJAXBEnvelope11);
+ }
+ public void testJAXBInflow_soap12() throws Exception {
+ _testJAXBInflow(sampleJAXBEnvelope12);
+ }
+ public void _testJAXBInflow(String sampleJAXBEnvelope) throws Exception {
// Create a SOAP OM out of the sample incoming XML. This
// simulates what Axis2 will be doing with the inbound message.
StringReader sr = new StringReader(sampleJAXBEnvelope);
@@ -394,4 +505,13 @@
assertNotNull(esr.getEchoStringReturn());
assertTrue(esr.getEchoStringReturn().equals("sample return value"));
}
+ SAAJConverter converter = null;
+ private SAAJConverter getSAAJConverter() {
+ if (converter == null) {
+ SAAJConverterFactory factory = (
+ SAAJConverterFactory)FactoryRegistry.getFactory(SAAJConverterFactory.class);
+ converter = factory.getSAAJConverter();
+ }
+ return converter;
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org