You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ode.apache.org by bo...@apache.org on 2007/05/02 02:50:27 UTC
svn commit: r534290 - in /incubator/ode/trunk/axis2/src:
main/java/org/apache/ode/axis2/ main/java/org/apache/ode/axis2/util/
test/java/org/apache/ode/axis2/
Author: boisvert
Date: Tue May 1 17:50:26 2007
New Revision: 534290
URL: http://svn.apache.org/viewvc?view=rev&rev=534290
Log:
Minor refactoring of SoapMessageConverter related to SOAPFactory
Modified:
incubator/ode/trunk/axis2/src/main/java/org/apache/ode/axis2/ExternalService.java
incubator/ode/trunk/axis2/src/main/java/org/apache/ode/axis2/ODEService.java
incubator/ode/trunk/axis2/src/main/java/org/apache/ode/axis2/util/SoapMessageConverter.java
incubator/ode/trunk/axis2/src/test/java/org/apache/ode/axis2/SoapMessageConverterTest.java
incubator/ode/trunk/axis2/src/test/java/org/apache/ode/axis2/SoapMessageConverterTestFromRaja1.java
Modified: incubator/ode/trunk/axis2/src/main/java/org/apache/ode/axis2/ExternalService.java
URL: http://svn.apache.org/viewvc/incubator/ode/trunk/axis2/src/main/java/org/apache/ode/axis2/ExternalService.java?view=diff&rev=534290&r1=534289&r2=534290
==============================================================================
--- incubator/ode/trunk/axis2/src/main/java/org/apache/ode/axis2/ExternalService.java (original)
+++ incubator/ode/trunk/axis2/src/main/java/org/apache/ode/axis2/ExternalService.java Tue May 1 17:50:26 2007
@@ -19,7 +19,6 @@
package org.apache.ode.axis2;
-import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.soap.SOAPEnvelope;
import org.apache.axis2.AxisFault;
import org.apache.axis2.addressing.EndpointReference;
@@ -52,8 +51,9 @@
import java.util.concurrent.ExecutorService;
/**
- * Acts as a service not provided by ODE. Used mainly for invocation as a way to maintain the WSDL decription of used services.
- *
+ * Acts as a service not provided by ODE. Used mainly for invocation as a way to maintain the WSDL decription of used
+ * services.
+ *
* @author Matthieu Riou <mriou at apache dot org>
*/
public class ExternalService implements PartnerRoleChannel {
@@ -84,8 +84,7 @@
_executorService = executorService;
_axisConfig = axisConfig;
_sched = sched;
- _converter = new SoapMessageConverter(OMAbstractFactory.getSOAP11Factory(), definition, serviceName, portName,
- _isReplicateEmptyNS);
+ _converter = new SoapMessageConverter(definition, serviceName, portName, _isReplicateEmptyNS);
}
public void invoke(final PartnerRoleMessageExchange odeMex) {
@@ -94,16 +93,15 @@
// Override options are passed to the axis MessageContext so we can
// retrieve them in our session out handler.
MessageContext mctx = new MessageContext();
- writeHeader(mctx.getOptions(), odeMex);
+ Options options = mctx.getOptions();
+ writeHeader(options, odeMex);
- SOAPEnvelope soapEnv = OMAbstractFactory.getSOAP11Factory().getDefaultEnvelope();
+ _converter.createSoapRequest(mctx, odeMex.getRequest().getMessage(), odeMex.getOperation());
- _converter.createSoapRequest(soapEnv, odeMex.getRequest().getMessage(), odeMex.getOperation());
+ SOAPEnvelope soapEnv = mctx.getEnvelope();
- mctx.setEnvelope(soapEnv);
-
- Options options = new Options();
- EndpointReference axisEPR = new EndpointReference(((MutableEndpoint) odeMex.getEndpointReference()).getUrl());
+ EndpointReference axisEPR = new EndpointReference(((MutableEndpoint) odeMex.getEndpointReference())
+ .getUrl());
if (__log.isDebugEnabled()) {
__log.debug("Axis2 sending message to " + axisEPR.getAddress() + " using MEX " + odeMex);
__log.debug("Message: " + soapEnv);
@@ -201,7 +199,8 @@
if (myRoleEPR != null) {
if (myRoleSessionId != null) {
if (__log.isDebugEnabled()) {
- __log.debug("MyRole session identifier found for myrole (callback) WSA endpoint: " + myRoleSessionId);
+ __log.debug("MyRole session identifier found for myrole (callback) WSA endpoint: "
+ + myRoleSessionId);
}
myRoleEPR.setSessionId(myRoleSessionId);
}
@@ -227,8 +226,7 @@
public void setReplicateEmptyNS(boolean isReplicateEmptyNS) {
_isReplicateEmptyNS = isReplicateEmptyNS;
try {
- _converter = new SoapMessageConverter(OMAbstractFactory.getSOAP11Factory(), _definition, _serviceName, _portName,
- _isReplicateEmptyNS);
+ _converter = new SoapMessageConverter(_definition, _serviceName, _portName, _isReplicateEmptyNS);
} catch (Exception ex) {
throw new RuntimeException(ex);
}
@@ -242,8 +240,8 @@
return _serviceName;
}
- private void replyWithFailure(final PartnerRoleMessageExchange odeMex, final FailureType error, final String errmsg,
- final Element details) {
+ private void replyWithFailure(final PartnerRoleMessageExchange odeMex, final FailureType error,
+ final String errmsg, final Element details) {
// ODE MEX needs to be invoked in a TX.
try {
_sched.execIsolatedTransaction(new Callable<Void>() {
@@ -283,9 +281,9 @@
try {
_sched.execIsolatedTransaction(new Callable<Void>() {
public Void call() throws Exception {
- Message response = fault ? odeMex.createMessage(odeMex.getOperation().getFault(faultType.getLocalPart())
- .getMessage().getQName()) : odeMex.createMessage(odeMex.getOperation().getOutput().getMessage()
- .getQName());
+ Message response = fault ? odeMex.createMessage(odeMex.getOperation().getFault(
+ faultType.getLocalPart()).getMessage().getQName()) : odeMex.createMessage(odeMex
+ .getOperation().getOutput().getMessage().getQName());
try {
if (__log.isDebugEnabled()) {
__log.debug("Received response for MEX " + odeMex);
@@ -299,10 +297,12 @@
odeMex.replyWithFault(faultType, response);
} else {
if (__log.isDebugEnabled()) {
- __log.debug("FAULT RESPONSE(unknown fault type): " + DOMUtils.domToString(odeMsgEl));
+ __log
+ .debug("FAULT RESPONSE(unknown fault type): "
+ + DOMUtils.domToString(odeMsgEl));
}
- odeMex.replyWithFailure(FailureType.FORMAT_ERROR, reply.getEnvelope().getBody().getFault()
- .getText(), null);
+ odeMex.replyWithFailure(FailureType.FORMAT_ERROR, reply.getEnvelope().getBody()
+ .getFault().getText(), null);
}
} else {
if (__log.isDebugEnabled()) {
Modified: incubator/ode/trunk/axis2/src/main/java/org/apache/ode/axis2/ODEService.java
URL: http://svn.apache.org/viewvc/incubator/ode/trunk/axis2/src/main/java/org/apache/ode/axis2/ODEService.java?view=diff&rev=534290&r1=534289&r2=534290
==============================================================================
--- incubator/ode/trunk/axis2/src/main/java/org/apache/ode/axis2/ODEService.java (original)
+++ incubator/ode/trunk/axis2/src/main/java/org/apache/ode/axis2/ODEService.java Tue May 1 17:50:26 2007
@@ -30,7 +30,17 @@
import javax.wsdl.extensions.soap.SOAPAddress;
import javax.xml.namespace.QName;
-import org.apache.axiom.om.OMAbstractFactory;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+
+import javax.transaction.TransactionManager;
+import javax.wsdl.Definition;
+import javax.wsdl.Port;
+import javax.wsdl.Service;
+import javax.wsdl.extensions.UnknownExtensibilityElement;
+import javax.wsdl.extensions.soap.SOAPAddress;
+import javax.xml.namespace.QName;
+
import org.apache.axiom.soap.SOAPEnvelope;
import org.apache.axiom.soap.SOAPFactory;
import org.apache.axis2.AxisFault;
@@ -82,8 +92,7 @@
_serviceName = serviceName;
_portName = portName;
_serviceRef = EndpointFactory.convertToWSA(createServiceRef(genEPRfromWSDL(_wsdlDef, serviceName, portName)));
- _converter = new SoapMessageConverter(OMAbstractFactory.getSOAP11Factory(), def, serviceName, portName,
- _isReplicateEmptyNS);
+ _converter = new SoapMessageConverter(def, serviceName, portName, _isReplicateEmptyNS);
}
@@ -223,8 +232,7 @@
_converter.createSoapFault(mex.getFaultResponse().getMessage(), mex.getFault(), mex.getOperation()));
case ASYNC:
case RESPONSE:
- _converter.createSoapResponse(msgContext.getEnvelope(), mex.getResponse().getMessage(),
- mex.getOperation());
+ _converter.createSoapResponse(msgContext, mex.getResponse().getMessage(), mex.getOperation());
if (__log.isDebugEnabled())
__log.debug("Generated response message " +
msgContext.getEnvelope());
Modified: incubator/ode/trunk/axis2/src/main/java/org/apache/ode/axis2/util/SoapMessageConverter.java
URL: http://svn.apache.org/viewvc/incubator/ode/trunk/axis2/src/main/java/org/apache/ode/axis2/util/SoapMessageConverter.java?view=diff&rev=534290&r1=534289&r2=534290
==============================================================================
--- incubator/ode/trunk/axis2/src/main/java/org/apache/ode/axis2/util/SoapMessageConverter.java (original)
+++ incubator/ode/trunk/axis2/src/main/java/org/apache/ode/axis2/util/SoapMessageConverter.java Tue May 1 17:50:26 2007
@@ -42,6 +42,7 @@
import javax.wsdl.extensions.soap.SOAPOperation;
import javax.xml.namespace.QName;
+import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMNode;
import org.apache.axiom.soap.SOAPEnvelope;
@@ -49,6 +50,8 @@
import org.apache.axiom.soap.SOAPFault;
import org.apache.axiom.soap.SOAPFaultDetail;
import org.apache.axis2.AxisFault;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.namespace.Constants;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.ode.axis2.Messages;
@@ -94,10 +97,8 @@
private SOAPBinding _soapBinding;
- public SoapMessageConverter(SOAPFactory soapFactory, Definition def, QName serviceName, String portName,
+ public SoapMessageConverter(Definition def, QName serviceName, String portName,
boolean replicateEmptyNS) throws AxisFault {
- if (soapFactory == null)
- throw new NullPointerException("Null soapFactory");
if (def == null)
throw new NullPointerException("Null wsdl def.");
if (serviceName == null)
@@ -105,7 +106,6 @@
if (portName == null)
throw new NullPointerException("Null portName");
- _soapFactory = soapFactory;
_def = def;
_serviceName = serviceName;
_portName = portName;
@@ -131,16 +131,24 @@
_soapBinding = (SOAPBinding) soapBindings.iterator().next();
String style = _soapBinding.getStyle();
_isRPC = style != null && style.equals("rpc");
+
+ if (_soapBinding.getElementType().getNamespaceURI().equals(Constants.URI_WSDL11_SOAP)) {
+ _soapFactory = OMAbstractFactory.getSOAP11Factory();
+ } else if (_soapBinding.getElementType().getNamespaceURI().equals(Constants.URI_WSDL12_SOAP)) {
+ _soapFactory = OMAbstractFactory.getSOAP12Factory();
+ } else {
+ throw new IllegalStateException("Unsupported SOAP binding: " + _soapBinding.getElementType());
+ }
}
@SuppressWarnings("unchecked")
- public void createSoapRequest(SOAPEnvelope soapEnv, Element message, Operation op) throws AxisFault {
+ public void createSoapRequest(MessageContext msgCtx, Element message, Operation op) throws AxisFault {
if (op == null)
throw new NullPointerException("Null operation");
if (message == null)
throw new NullPointerException("Null message.");
- if (soapEnv == null)
- throw new NullPointerException("Null soapEnv");
+ if (msgCtx == null)
+ throw new NullPointerException("Null msgCtx");
BindingOperation bop = _binding.getBindingOperation(op.getName(), null, null);
@@ -151,6 +159,9 @@
if (bi == null)
throw new OdeFault(__msgs.msgBindingInputNotFound(_serviceName, _portName, op.getName()));
+ SOAPEnvelope soapEnv = _soapFactory.createSOAPEnvelope();
+ msgCtx.setEnvelope(soapEnv);
+
List<SOAPHeader> soapHeaders = getSOAPHeaders(bi);
for (SOAPHeader sh : soapHeaders)
createSoapHeader(soapEnv, sh, op.getInput().getMessage(), message);
@@ -165,13 +176,13 @@
}
- public void createSoapResponse(SOAPEnvelope soapEnv, Element message, Operation op) throws AxisFault {
+ public void createSoapResponse(MessageContext msgCtx, Element message, Operation op) throws AxisFault {
if (op == null)
throw new NullPointerException("Null operation");
if (message == null)
throw new NullPointerException("Null message.");
- if (soapEnv == null)
- throw new NullPointerException("Null soapEnv");
+ if (msgCtx == null)
+ throw new NullPointerException("Null msgCtx");
BindingOperation bop = _binding.getBindingOperation(op.getName(),null,null);
@@ -182,6 +193,7 @@
if (bo == null)
throw new OdeFault(__msgs.msgBindingOutputNotFound(_serviceName, _portName, op.getName()));
+ SOAPEnvelope soapEnv = _soapFactory.createSOAPEnvelope();
List<SOAPHeader> soapHeaders = getSOAPHeaders(bo);
for (SOAPHeader sh : soapHeaders)
createSoapHeader(soapEnv, sh, op.getOutput().getMessage(), message);
Modified: incubator/ode/trunk/axis2/src/test/java/org/apache/ode/axis2/SoapMessageConverterTest.java
URL: http://svn.apache.org/viewvc/incubator/ode/trunk/axis2/src/test/java/org/apache/ode/axis2/SoapMessageConverterTest.java?view=diff&rev=534290&r1=534289&r2=534290
==============================================================================
--- incubator/ode/trunk/axis2/src/test/java/org/apache/ode/axis2/SoapMessageConverterTest.java (original)
+++ incubator/ode/trunk/axis2/src/test/java/org/apache/ode/axis2/SoapMessageConverterTest.java Tue May 1 17:50:26 2007
@@ -34,27 +34,36 @@
import org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder;
import org.apache.axiom.soap.impl.dom.soap11.SOAP11Factory;
import org.apache.axis2.AxisFault;
+import org.apache.axis2.context.MessageContext;
import org.apache.ode.axis2.util.SoapMessageConverter;
import org.apache.ode.utils.DOMUtils;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
public class SoapMessageConverterTest extends TestCase {
-
- Definition wsdl1,wsdlHW;
+
+ Definition wsdl1, wsdlHW;
+
String wsdl1tns = "http://documentum.com/ws/2005/services";
- QName repoService = new QName(wsdl1tns, "RepoAccessorService");
- QName portTypeName = new QName(wsdl1tns,"RepoAccessor");
+
+ QName repoService = new QName(wsdl1tns, "RepoAccessorService");
+
+ QName portTypeName = new QName(wsdl1tns, "RepoAccessor");
+
String portName = "RepoAccessor";
+
SoapMessageConverter portmapper;
-
+
PortType portType, portTypeHW;
+
Document req1bad;
+
Document req1;
- private Operation op1,opHello;
-
+
+ private Operation op1, opHello;
+
public SoapMessageConverterTest() throws Exception {
- req1bad = DOMUtils.parse(getClass().getResourceAsStream("/testRequest1Bad.xml"));
+ req1bad = DOMUtils.parse(getClass().getResourceAsStream("/testRequest1Bad.xml"));
req1 = DOMUtils.parse(getClass().getResourceAsStream("/testRequest1.xml"));
WSDLReader reader = WSDLFactory.newInstance().newWSDLReader();
wsdl1 = reader.readWSDL(getClass().getResource("/test1.wsdl").toExternalForm());
@@ -62,93 +71,93 @@
op1 = portType.getOperation("getObjectId", null, null);
wsdlHW = reader.readWSDL(getClass().getResource("/HelloWorld.wsdl").toExternalForm());
- portTypeHW = wsdlHW.getPortType(new QName(wsdlHW.getTargetNamespace(),"HelloPortType"));
- opHello = portTypeHW.getOperation("hello",null,null);
-}
-
+ portTypeHW = wsdlHW.getPortType(new QName(wsdlHW.getTargetNamespace(), "HelloPortType"));
+ opHello = portTypeHW.getOperation("hello", null, null);
+ }
+
public void setUp() throws Exception {
- portmapper = new SoapMessageConverter(new SOAP11Factory(),
- wsdl1, repoService, portName, true);
+ portmapper = new SoapMessageConverter(wsdl1, repoService, portName, true);
}
-
+
public void tearDown() {
-
+
}
-
+
public void testBadPortName() {
try {
- new SoapMessageConverter(new SOAP11Factory(),
- wsdl1, repoService, "badPort", true);
+ new SoapMessageConverter(wsdl1, repoService, "badPort", true);
fail("Should have thrown axis error.");
- } catch(AxisFault af) {
- ;//expected
+ } catch (AxisFault af) {
+ ;// expected
}
}
public void testBadServiceName() {
try {
- new SoapMessageConverter(new SOAP11Factory(),
- wsdl1, new QName(wsdl1tns, "foobar"), portName, true);
+ new SoapMessageConverter(wsdl1, new QName(wsdl1tns, "foobar"), portName, true);
fail("Should have thrown axis error.");
- } catch(AxisFault af) {
- ;//expected
+ } catch (AxisFault af) {
+ ;// expected
}
}
public void testCreateSOAPRequest() throws Exception {
- SOAPEnvelope env = new SOAP11Factory().createSOAPEnvelope();
- portmapper.createSoapRequest(env, req1.getDocumentElement(),
- portType.getOperation("getObjectId", null, null));
- System.out.println(env);
+ MessageContext msgCtx = new MessageContext();
+ portmapper.createSoapRequest(msgCtx, req1.getDocumentElement(), portType.getOperation("getObjectId", null, null));
+ SOAPEnvelope env = msgCtx.getEnvelope();
+ System.out.println("testCreateSOAPRequest: " + env);
QName elPartName = new QName(wsdl1tns, "getObjectId");
assertNotNull(env.getBody());
assertNotNull(env.getBody().getFirstElement());
// doc-lit style, no part wrapper
- assertEquals(elPartName,env.getBody().getFirstElement().getQName());
-
+ assertEquals(elPartName, env.getBody().getFirstElement().getQName());
+
}
-
+
public void testCreateSOAPRequestFail() throws Exception {
- SOAPEnvelope env = new SOAP11Factory().createSOAPEnvelope();
+ MessageContext msgCtx = new MessageContext();
try {
- portmapper.createSoapRequest(env, req1bad.getDocumentElement(),
- portType.getOperation("getObjectId", null, null));
- fail("Should have caused an ex");
+ portmapper.createSoapRequest(msgCtx, req1bad.getDocumentElement(), portType.getOperation("getObjectId", null,
+ null));
+ fail("Should have caused an ex");
} catch (AxisFault af) {
; // expected
}
}
-
+
public void testGetSoapAction() throws Exception {
assertEquals("getObjectIdAction", portmapper.getSoapAction("getObjectId"));
assertEquals("", portmapper.getSoapAction("foo"));
}
-
+
public void testParseRequest() throws Exception {
- SOAPEnvelope env = new SOAP11Factory().createSOAPEnvelope();
- portmapper.createSoapRequest(env, req1.getDocumentElement(),op1);
- System.out.println(env);
+ MessageContext msgCtx = new MessageContext();
+ portmapper.createSoapRequest(msgCtx, req1.getDocumentElement(), op1);
+ SOAPEnvelope env = msgCtx.getEnvelope();
+ System.out.println("testParseRequest: " + env);
Element odeMsg = DOMUtils.stringToDOM("<message/>");
portmapper.parseSoapRequest(odeMsg, env, op1);
- System.out.println(DOMUtils.domToString(odeMsg));
+ System.out.println("testParseRequest: " + DOMUtils.domToString(odeMsg));
Element params = DOMUtils.findChildByName(odeMsg, new QName(null, "parameters"));
assertNotNull(params);
- Element hdr = DOMUtils.findChildByName(odeMsg,new QName("urn:ode.apache.org/axis2-il/header","DocumentumRequestHeader"));
+ Element hdr = DOMUtils.findChildByName(odeMsg, new QName("urn:ode.apache.org/axis2-il/header",
+ "DocumentumRequestHeader"));
assertNotNull(hdr);
}
-
+
/** Make sure hello world request parses correctly. */
public void testHelloWorldRequest() throws Exception {
- XMLStreamReader sr = XMLInputFactory.newInstance().createXMLStreamReader(getClass().getResourceAsStream("/HelloWorldRequest.soap"));
- StAXSOAPModelBuilder builder = OMXMLBuilderFactory.createStAXSOAPModelBuilder(new SOAP11Factory(),sr);
+ SoapMessageConverter portmaper1 = new SoapMessageConverter(wsdlHW, new QName(wsdlHW
+ .getTargetNamespace(), "HelloService"), "HelloPort", false);
+
+ XMLStreamReader sr = XMLInputFactory.newInstance().createXMLStreamReader(
+ getClass().getResourceAsStream("/HelloWorldRequest.soap"));
+ StAXSOAPModelBuilder builder = OMXMLBuilderFactory.createStAXSOAPModelBuilder(new SOAP11Factory(), sr);
SOAPEnvelope se = builder.getSOAPEnvelope();
- SoapMessageConverter portmaper1 = new SoapMessageConverter(new SOAP11Factory(),
- wsdlHW,new QName(wsdlHW.getTargetNamespace(),"HelloService"),"HelloPort",false);
-
+
Element msg = DOMUtils.stringToDOM("<message/>");
portmaper1.parseSoapRequest(msg, se, opHello);
System.out.println(DOMUtils.domToString(msg));
}
}
-
Modified: incubator/ode/trunk/axis2/src/test/java/org/apache/ode/axis2/SoapMessageConverterTestFromRaja1.java
URL: http://svn.apache.org/viewvc/incubator/ode/trunk/axis2/src/test/java/org/apache/ode/axis2/SoapMessageConverterTestFromRaja1.java?view=diff&rev=534290&r1=534289&r2=534290
==============================================================================
--- incubator/ode/trunk/axis2/src/test/java/org/apache/ode/axis2/SoapMessageConverterTestFromRaja1.java (original)
+++ incubator/ode/trunk/axis2/src/test/java/org/apache/ode/axis2/SoapMessageConverterTestFromRaja1.java Tue May 1 17:50:26 2007
@@ -59,8 +59,7 @@
wsdl1tns = wsdl1.getTargetNamespace();
portType = wsdl1.getPortType(new QName(wsdl1tns,"SimpleServicesPortType"));
op1 = portType.getOperation("addNumbers", null, null);
- portmapper = new SoapMessageConverter(new SOAP11Factory(),
- wsdl1, new QName(wsdl1tns,"SimpleServices"),
+ portmapper = new SoapMessageConverter(wsdl1, new QName(wsdl1tns,"SimpleServices"),
"SimpleServicesHttpPort", true);
}