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 de...@apache.org on 2006/01/10 06:05:43 UTC
svn commit: r367485 - in /webservices/axis2/trunk/java/modules:
core/src/org/apache/axis2/client/
core/src/org/apache/axis2/deployment/repository/util/
core/src/org/apache/axis2/description/ core/src/org/apache/axis2/util/
integration/test/org/apache/a...
Author: deepal
Date: Mon Jan 9 21:05:22 2006
New Revision: 367485
URL: http://svn.apache.org/viewcvs?rev=367485&view=rev
Log:
Implemented to support generate ServiceClient for a given WSDL. And steps as follows
- First generate ServiceClient using wsdl , and there you have to give service and and port name and
- if they are null defaults will be selected (first element of the iterator if there are many )
- Then you can either create an operation client or invoke any method in ServiceClient
- And you do not need to pass any options (set options only if you want to override them)
Added:
webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/WSDLClientTest.java
Modified:
webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/client/ServiceClient.java
webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/deployment/repository/util/ArchiveReader.java
webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/description/AxisOperation.java
webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/description/ClientUtils.java
webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/description/OutInAxisOperation.java
webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/description/OutOnlyAxisOperation.java
webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/util/CallbackReceiver.java
webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/EchoRawXMLMultipleTest.java
Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/client/ServiceClient.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/client/ServiceClient.java?rev=367485&r1=367484&r2=367485&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/client/ServiceClient.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/client/ServiceClient.java Mon Jan 9 21:05:22 2006
@@ -17,6 +17,7 @@
import org.apache.wsdl.WSDLConstants;
import javax.xml.namespace.QName;
+import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
@@ -75,7 +76,6 @@
// create a config context if needed
this.configContext = (configContext != null) ? configContext
: new ConfigurationContextFactory()
-
.createConfigurationContextFromFileSystem(null);
// save the axisConfig and service
@@ -112,9 +112,23 @@
*/
public ServiceClient(ConfigurationContext configContext, URL wsdlURL,
QName wsdlServiceName, String portName) throws AxisFault {
- // TODO: Srinath to write this code :)
- throw new UnsupportedOperationException(
- "ServiceClient currently does not support direct WSDL construction");
+ // create a config context if needed
+ this.configContext = (configContext != null) ? configContext
+ : new ConfigurationContextFactory()
+ .createConfigurationContextFromFileSystem(null);
+ try {
+ this.axisConfig = this.configContext.getAxisConfiguration();
+ axisService = ClientUtils.creatAxisService(wsdlURL, wsdlServiceName, portName, options);
+ // add the service to the config context if it isn't in there already
+ if (this.axisConfig.getService(this.axisService.getName()) == null) {
+ this.axisConfig.addService(this.axisService);
+ }
+ ServiceGroupContext sgc = new ServiceGroupContext(this.configContext,
+ this.axisService.getParent());
+ this.serviceContext = sgc.getServiceContext(this.axisService);
+ } catch (IOException e) {
+ throw new AxisFault(e);
+ }
}
/**
@@ -349,11 +363,13 @@
}
// process the resule of the invocation
if (callback.envelope != null) {
- MessageContext resMsgctx = new MessageContext();
- resMsgctx.setConfigurationContext(serviceContext
- .getConfigurationContext());
-
- resMsgctx.setEnvelope(callback.envelope);
+// MessageContext resMsgctx = new MessageContext();
+// resMsgctx.setConfigurationContext(serviceContext
+// .getConfigurationContext());
+ MessageContext resMsgctx = callback.getMsgctx();
+// resMsgctx.setEnvelope(callback.envelope);
+ ListenerManager.stop(serviceContext.getConfigurationContext(),
+ resMsgctx.getTransportIn().getName().getLocalPart());
return callback.envelope.getBody().getFirstElement();
} else {
@@ -481,15 +497,21 @@
*/
private class SyncCallBack extends Callback {
private SOAPEnvelope envelope;
+ private MessageContext msgctx;
private Exception error;
public void onComplete(AsyncResult result) {
this.envelope = result.getResponseEnvelope();
+ this.msgctx = result.getResponseMessageContext();
}
public void onError(Exception e) {
error = e;
+ }
+
+ public MessageContext getMsgctx() {
+ return msgctx;
}
}
}
Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/deployment/repository/util/ArchiveReader.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/deployment/repository/util/ArchiveReader.java?rev=367485&r1=367484&r2=367485&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/deployment/repository/util/ArchiveReader.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/deployment/repository/util/ArchiveReader.java Mon Jan 9 21:05:22 2006
@@ -80,7 +80,7 @@
if (!axisService.isWsdlfound()) {
//trying to generate WSDL for the service using JAM and Java refelection
try {
- Utils.fillAxisService(service,axisConfig);
+ Utils.fillAxisService(service, axisConfig);
} catch (Exception e) {
log.info("Error in schema generating :" + e.getMessage());
}
Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/description/AxisOperation.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/description/AxisOperation.java?rev=367485&r1=367484&r2=367485&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/description/AxisOperation.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/description/AxisOperation.java Mon Jan 9 21:05:22 2006
@@ -31,6 +31,8 @@
private Log log = LogFactory.getLog(getClass());
private int mep = MEP_CONSTANT_INVALID;
+ public static final String SOAP_ACTION ="soapaction";
+
// to store engaged modules
private ArrayList engagedModules = new ArrayList();
Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/description/ClientUtils.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/description/ClientUtils.java?rev=367485&r1=367484&r2=367485&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/description/ClientUtils.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/description/ClientUtils.java Mon Jan 9 21:05:22 2006
@@ -8,13 +8,29 @@
import org.apache.axis2.context.ServiceContext;
import org.apache.axis2.engine.AxisConfiguration;
import org.apache.axis2.i18n.Messages;
-
+import org.apache.axis2.util.XMLUtils;
+import org.w3c.dom.Document;
+import org.xml.sax.SAXException;
+
+import javax.wsdl.*;
+import javax.wsdl.extensions.soap.SOAPAddress;
+import javax.wsdl.extensions.soap.SOAPOperation;
+import javax.wsdl.factory.WSDLFactory;
+import javax.wsdl.xml.WSDLReader;
import javax.xml.namespace.QName;
+import javax.xml.parsers.ParserConfigurationException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
/**
* Utility methods for various clients to use.
*/
public class ClientUtils {
+
public static TransportOutDescription inferOutTransport(AxisConfiguration ac,
EndpointReference epr) throws AxisFault {
if (epr == null || (epr.getAddress() == null)) {
@@ -55,5 +71,119 @@
}
return transportIn;
+ }
+
+ /**
+ * To create a AxisService for a given WSDL and the created client is most suitable for clinet side
+ * invocation not for server side invocation. Since all the soap acction and wsa action is added to
+ * operations
+ *
+ * @param wsdlURL location of the WSDL
+ * @param wsdlServiceName name of the service to be invoke , if it is null then the first one will
+ * be selected if there are more than one
+ * @param portName name of the port , if there are more than one , if it is null then the
+ * first one in the iterator will be selected
+ * @param options Service client options, to set the target EPR
+ * @return AxisService , the created servie will be return
+ */
+ public static AxisService creatAxisService(URL wsdlURL,
+ QName wsdlServiceName,
+ String portName,
+ Options options) throws AxisFault {
+ AxisService axisService;
+ try {
+ InputStream in = wsdlURL.openConnection().getInputStream();
+ Document doc = XMLUtils.newDocument(in);
+ WSDLReader reader = WSDLFactory.newInstance().newWSDLReader();
+ reader.setFeature("javax.wsdl.importDocuments", true);
+ Definition wsdlDefinition = reader.readWSDL(null, doc);
+ axisService = new AxisService();
+
+ Service wsdlService;
+ if (wsdlServiceName != null) {
+ wsdlService = wsdlDefinition.getService(wsdlServiceName);
+ if (wsdlService == null) {
+ throw new AxisFault("Service" + wsdlServiceName + " not found in the wsdl ");
+ }
+
+ } else {
+ Collection col = wsdlDefinition.getServices().values();
+ if (col != null && col.size() > 0) {
+ wsdlService = (Service) col.iterator().next();
+ if (wsdlService == null) {
+ throw new AxisFault("No servoce found in the given wsdl");
+ }
+ } else {
+ throw new AxisFault("No servoce found in the given wsdl");
+ }
+ }
+ axisService.setName(wsdlService.getQName().getLocalPart());
+
+ Port port;
+ if (portName != null) {
+ port = wsdlService.getPort(portName);
+ if (port == null) {
+ throw new AxisFault("No port found for the given port name : " + portName);
+ }
+ } else {
+ Collection ports = wsdlService.getPorts().values();
+ if (ports != null && ports.size() > 0) {
+ port = (Port) ports.iterator().next();
+ if (port == null) {
+ throw new AxisFault("no port found in the service element");
+ }
+ } else {
+ throw new AxisFault("no port found in the service element");
+ }
+ }
+ List exteElemts = port.getExtensibilityElements();
+ if (exteElemts != null) {
+ Iterator extItr = exteElemts.iterator();
+ while (extItr.hasNext()) {
+ Object extensibilityElement = extItr.next();
+ if (extensibilityElement instanceof SOAPAddress) {
+ SOAPAddress address = (SOAPAddress) extensibilityElement;
+ options.setTo(new EndpointReference(address.getLocationURI()));
+ }
+ }
+ }
+
+ Binding binding = port.getBinding();
+ Iterator bindingOperations = binding.getBindingOperations().iterator();
+ while (bindingOperations.hasNext()) {
+ BindingOperation bindingOperation = (BindingOperation) bindingOperations.next();
+ AxisOperation axisOperation;
+ if (bindingOperation.getBindingInput() == null &&
+ bindingOperation.getBindingOutput() != null) {
+ axisOperation = new OutOnlyAxisOperation();
+ } else {
+ axisOperation = new OutInAxisOperation();
+ }
+ axisOperation.setName(new QName(bindingOperation.getName()));
+ List list = bindingOperation.getExtensibilityElements();
+ if (list != null) {
+ Iterator exteElements = list.iterator();
+ while (exteElements.hasNext()) {
+ Object extensibilityElement = exteElements.next();
+ if (extensibilityElement instanceof SOAPOperation) {
+ SOAPOperation soapOp = (SOAPOperation) extensibilityElement;
+ axisOperation.addParameter(new ParameterImpl(AxisOperation.SOAP_ACTION,
+ soapOp.getSoapActionURI()));
+ }
+ }
+ }
+ axisService.addOperation(axisOperation);
+ }
+
+ } catch (IOException e) {
+ throw new AxisFault("IOException" + e.getMessage());
+ } catch (ParserConfigurationException e) {
+ throw new AxisFault("ParserConfigurationException" + e.getMessage());
+ } catch (SAXException e) {
+ throw new AxisFault("SAXException" + e.getMessage());
+ } catch (WSDLException e) {
+ throw new AxisFault("WSDLException" + e.getMessage());
+ }
+ return axisService;
}
}
Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/description/OutInAxisOperation.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/description/OutInAxisOperation.java?rev=367485&r1=367484&r2=367485&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/description/OutInAxisOperation.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/description/OutInAxisOperation.java Mon Jan 9 21:05:22 2006
@@ -237,6 +237,13 @@
}
}
+ if (mc.getSoapAction() == null || "".equals(mc.getSoapAction())) {
+ Parameter soapaction = axisOp.getParameter(AxisOperation.SOAP_ACTION);
+ if (soapaction != null) {
+ mc.setSoapAction((String) soapaction.getValue());
+ }
+ }
+
if (options.isUseSeparateListener()) {
CallbackReceiver callbackReceiver = (CallbackReceiver) axisOp
.getMessageReceiver();
@@ -257,7 +264,7 @@
} else {
if (block) {
// Send the SOAP Message and receive a response
- MessageContext response = send(mc, options.getTransportIn());
+ MessageContext response = send(mc);
// check for a fault and return the result
SOAPEnvelope resenvelope = response.getEnvelope();
if (resenvelope.getBody().hasFault()) {
@@ -301,12 +308,10 @@
* Sends the message using a two way transport and waits for a response
*
* @param msgctx
- * @param transportIn
* @return Returns MessageContext.
* @throws AxisFault
*/
- public MessageContext send(MessageContext msgctx,
- TransportInDescription transportIn) throws AxisFault {
+ private MessageContext send(MessageContext msgctx) throws AxisFault {
AxisEngine engine = new AxisEngine(msgctx.getConfigurationContext());
engine.send(msgctx);
@@ -315,7 +320,7 @@
MessageContext responseMessageContext = new MessageContext();
responseMessageContext.setTransportIn(msgctx.getTransportIn());
responseMessageContext.setTransportOut(msgctx.getTransportOut());
-
+
// This is a hack - Needs to change
responseMessageContext.setOptions(options);
@@ -342,6 +347,7 @@
throw new AxisFault(Messages
.getMessage("blockingInvocationExpectsResponse"));
}
+
return responseMessageContext;
}
@@ -380,7 +386,7 @@
try {
// send the request and wait for reponse
- MessageContext response = send(msgctx, options.getTransportIn());
+ MessageContext response = send(msgctx);
// call the callback
SOAPEnvelope resenvelope = response.getEnvelope();
Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/description/OutOnlyAxisOperation.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/description/OutOnlyAxisOperation.java?rev=367485&r1=367484&r2=367485&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/description/OutOnlyAxisOperation.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/description/OutOnlyAxisOperation.java Mon Jan 9 21:05:22 2006
@@ -282,6 +282,13 @@
}
mc.setTransportOut(senderTransport);
+ if (mc.getSoapAction() == null) {
+ Parameter soapaction = axisOp.getParameter(AxisOperation.SOAP_ACTION);
+ if (soapaction != null) {
+ mc.setSoapAction((String) soapaction.getValue());
+ }
+ }
+
// create the operation context for myself
OperationContext oc = new OperationContext(axisOp, sc);
oc.addMessageContext(mc);
Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/util/CallbackReceiver.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/util/CallbackReceiver.java?rev=367485&r1=367484&r2=367485&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/util/CallbackReceiver.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/util/CallbackReceiver.java Mon Jan 9 21:05:22 2006
@@ -35,6 +35,8 @@
if (callback != null) {
callback.onComplete(result);
callback.setComplete(true);
+ //TODO : need to close the InputStream at this point ,
+ // first need to read the enevelop fully and then close the in
} else {
throw new AxisFault("The Callback realtes to MessageID " + messageID + " is not found");
}
Modified: webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/EchoRawXMLMultipleTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/EchoRawXMLMultipleTest.java?rev=367485&r1=367484&r2=367485&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/EchoRawXMLMultipleTest.java (original)
+++ webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/EchoRawXMLMultipleTest.java Mon Jan 9 21:05:22 2006
@@ -30,9 +30,7 @@
import org.apache.axis2.engine.util.TestConstants;
import org.apache.axis2.integration.TestingUtils;
import org.apache.axis2.integration.UtilServer;
-import org.apache.axis2.om.OMAbstractFactory;
import org.apache.axis2.om.OMElement;
-import org.apache.axis2.soap.SOAPFactory;
import org.apache.axis2.util.Utils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -173,8 +171,6 @@
}
public void testEchoXMLMultipleSync() throws Exception {
- SOAPFactory fac = OMAbstractFactory.getSOAP11Factory();
-
OMElement payload = TestingUtils.createDummyOMElement();
for (int i = 0; i < 5; i++) {
Options options = new Options();
Added: webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/WSDLClientTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/WSDLClientTest.java?rev=367485&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/WSDLClientTest.java (added)
+++ webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/WSDLClientTest.java Mon Jan 9 21:05:22 2006
@@ -0,0 +1,70 @@
+package org.apache.axis2.engine;
+
+import junit.framework.TestCase;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.client.ServiceClient;
+import org.apache.axis2.description.AxisService;
+import org.apache.axis2.engine.util.TestConstants;
+import org.apache.axis2.integration.TestingUtils;
+import org.apache.axis2.integration.UtilServer;
+import org.apache.axis2.om.OMElement;
+
+import javax.xml.namespace.QName;
+import java.io.IOException;
+import java.net.URL;
+/*
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* 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.
+*
+* @author : Deepal Jayasinghe (deepal@apache.org)
+*
+*/
+
+public class WSDLClientTest extends TestCase implements TestConstants {
+
+ protected AxisService service;
+
+ protected void setUp() throws Exception {
+ UtilServer.start();
+ service = org.apache.axis2.deployment.util.Utils.createService(Echo.class.getName(),
+ UtilServer.getConfigurationContext().getAxisConfiguration());
+ service.setName(serviceName.getLocalPart());
+ UtilServer.deployService(service);
+ }
+
+ protected void tearDown() throws Exception {
+ UtilServer.unDeployService(serviceName);
+ UtilServer.stop();
+ UtilServer.unDeployClientService();
+ }
+
+ public void testWSDLClient() throws AxisFault {
+ try {
+ URL wsdlURL = new URL("http://localhost:" + UtilServer.TESTING_PORT +
+ "/axis2/services/EchoXMLService?wsdl");
+ ServiceClient serviceClient = new ServiceClient(null, wsdlURL,
+ new QName("http://org.apache.axis2/", "EchoXMLService"),
+ "EchoXMLServicePortType");
+ OMElement payload = TestingUtils.createDummyOMElement();
+ OMElement response = serviceClient.sendReceive(
+ new QName("http://org.apache.axis2/", "echoOMElement"), payload);
+ assertNotNull(response);
+ String textValue = response.getText();
+ assertEquals(textValue, "Isaac Asimov, The Foundation Trilogy");
+ } catch (IOException e) {
+ throw new AxisFault(e);
+ }
+ }
+
+}