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 de...@apache.org on 2005/12/30 10:53:32 UTC
svn commit: r360056 - in /webservices/axis2/trunk/java/modules:
codegen/src/org/apache/axis2/rpc/client/RPCServiceClient.java
integration/test/org/apache/axis2/rpc/MultirefTest.java
integration/test/org/apache/axis2/rpc/RPCCallTest.java
Author: deepal
Date: Fri Dec 30 01:53:15 2005
New Revision: 360056
URL: http://svn.apache.org/viewcvs?rev=360056&view=rev
Log:
added RPCServiceCleint extend service client . And after doing some work we can remove RPCCall
Added:
webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/rpc/client/RPCServiceClient.java
Modified:
webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/rpc/MultirefTest.java
webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/rpc/RPCCallTest.java
Added: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/rpc/client/RPCServiceClient.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/rpc/client/RPCServiceClient.java?rev=360056&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/rpc/client/RPCServiceClient.java (added)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/rpc/client/RPCServiceClient.java Fri Dec 30 01:53:15 2005
@@ -0,0 +1,111 @@
+package org.apache.axis2.rpc.client;
+
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.client.ServiceClient;
+import org.apache.axis2.client.async.Callback;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.context.ServiceContext;
+import org.apache.axis2.databinding.utils.BeanUtil;
+import org.apache.axis2.om.OMElement;
+
+import javax.xml.namespace.QName;
+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 RPCServiceClient extends ServiceClient {
+
+ public RPCServiceClient(ConfigurationContext configContext) throws AxisFault {
+ super(configContext);
+ }
+
+ public RPCServiceClient() throws AxisFault {
+ super();
+ }
+
+ public RPCServiceClient(ServiceContext serviceContext) {
+ super(serviceContext);
+ }
+
+ public RPCServiceClient(ConfigurationContext configContext,
+ URL wsdlURL, QName wsdlServiceName,
+ String portName) throws AxisFault {
+ super(configContext, wsdlURL, wsdlServiceName, portName);
+ }
+
+ /**
+ * Return value can be a single a object or an object array (itself an object) , but it is
+ * difficulty to figure the return object correctly unless we have TyepMapping in the client
+ * side too. Until it is finalized lets return OMElement as return value. And the retuen
+ * value will be the body first element user has to deal with that and create
+ * his own object out of that.
+ *
+ * @param opName Operation QName (to get the body wrapper element)
+ * @param args Arraylist of objects
+ * @return Response OMElement
+ */
+ public OMElement invokeBlocking(QName opName, Object [] args) throws AxisFault {
+ OMElement omElement = BeanUtil.getOMElement(opName, args);
+ return super.sendReceive(omElement);
+ }
+
+ /**
+ * @param opName Operation QName (to get the body wrapper element)
+ * @param args Arraylist of objects
+ * @param returnTypes , this array contains the JavaTypes for the return object , it could be one
+ * or more depending on the return type , most of the type array will contain just one element
+ * It should be noted that the array should only contains JavaTypes NOT real object , what this
+ * methods does is , get the body first element , and if it contains more than one childern take
+ * ith element and convert that to ith javatype and fill the return arrya
+ * the array will look like as follows
+ * [Integer, String, MyBean , etc]
+ * @return Object array , whic will contains real object , but the object can either be simple type
+ * object or the JavaBeans, thats what this method can handle right now
+ * the return array will contains [10, "Axis2Echo", {"foo","baa","11"}]
+ * @throws AxisFault
+ */
+
+ public Object[] invokeBlocking(QName opName, Object [] args, Object [] returnTypes) throws AxisFault {
+ OMElement omElement = BeanUtil.getOMElement(opName, args);
+ OMElement response = super.sendReceive(omElement);
+ return BeanUtil.deserialize(response, returnTypes);
+ }
+
+ /**
+ * Invoke the nonblocking/Asynchronous call
+ *
+ * @param opName
+ * @param args - This should be OM Element (payload)
+ * invocation behaves accordingly
+ * @param callback
+ * @throws org.apache.axis2.AxisFault
+ */
+
+ public void invokeNonBlocking(QName opName,
+ Object [] args,
+ Callback callback)
+ throws AxisFault {
+ OMElement omElement = BeanUtil.getOMElement(opName, args);
+ //call the underline implementation
+ super.sendReceiveNonblocking(omElement, callback);
+ }
+
+
+}
Modified: webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/rpc/MultirefTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/rpc/MultirefTest.java?rev=360056&r1=360055&r2=360056&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/rpc/MultirefTest.java (original)
+++ webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/rpc/MultirefTest.java Fri Dec 30 01:53:15 2005
@@ -50,15 +50,10 @@
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import java.io.ByteArrayInputStream;
-import java.text.SimpleDateFormat;
import java.util.ArrayList;
public class MultirefTest extends TestCase {
- private SimpleDateFormat zulu = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
- // 0123456789 0 123456789
-
-
protected EndpointReference targetEPR =
new EndpointReference("http://127.0.0.1:"
+ (UtilServer.TESTING_PORT)
@@ -129,6 +124,7 @@
call.setClientOptions(options);
options.setTo(targetEPR);
options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
+
SOAPEnvelope env = call.invokeBlocking("echoString", envelope);
assertEquals(env.getBody().getFirstElement().getFirstElement().getText(), "hello Axis2");
Modified: webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/rpc/RPCCallTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/rpc/RPCCallTest.java?rev=360056&r1=360055&r2=360056&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/rpc/RPCCallTest.java (original)
+++ webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/rpc/RPCCallTest.java Fri Dec 30 01:53:15 2005
@@ -21,6 +21,8 @@
import org.apache.axis2.Constants;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.context.ConfigurationContextFactory;
import org.apache.axis2.context.MessageContext;
import org.apache.axis2.context.ServiceContext;
import org.apache.axis2.databinding.utils.BeanUtil;
@@ -35,7 +37,7 @@
import org.apache.axis2.om.OMFactory;
import org.apache.axis2.om.impl.llom.builder.StAXOMBuilder;
import org.apache.axis2.receivers.AbstractMessageReceiver;
-import org.apache.axis2.rpc.client.RPCCall;
+import org.apache.axis2.rpc.client.RPCServiceClient;
import org.apache.axis2.rpc.receivers.RPCMessageReceiver;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -99,11 +101,14 @@
String clientHome = "target/test-resources/integrationRepo";
Options options = new Options();
- options.setTo(targetEPR);
options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
- RPCCall call = new RPCCall(clientHome);
- call.setClientOptions(options);
+ ConfigurationContextFactory factory = new ConfigurationContextFactory();
+ ConfigurationContext configContext =
+ factory.buildConfigurationContext(clientHome);
+ RPCServiceClient sender = new RPCServiceClient(configContext);
+ sender.setOptions(options);
+ options.setTo(targetEPR);
MyBean bean = new MyBean();
bean.setAge(100);
@@ -119,12 +124,12 @@
args.add(bean);
args.add("159");
- OMElement response = call.invokeBlocking(operationName, args.toArray());
+ OMElement response = sender.invokeBlocking(operationName, args.toArray());
// MyBean resBean =(MyBean) new BeanSerializer(MyBean.class,response).deserilze();
MyBean resBean = (MyBean) BeanUtil.deserialize(MyBean.class, response.getFirstElement());
assertNotNull(resBean);
assertEquals(resBean.getAge(), 159);
- call.close();
+ sender.finalizeInvoke();
}
private void configureSystem(String opName) throws AxisFault {
@@ -153,9 +158,11 @@
options.setTo(targetEPR);
options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
- RPCCall call =
- new RPCCall("target/test-resources/integrationRepo");
- call.setClientOptions(options);
+ ConfigurationContextFactory factory = new ConfigurationContextFactory();
+ ConfigurationContext configContext =
+ factory.buildConfigurationContext("target/test-resources/integrationRepo");
+ RPCServiceClient sender = new RPCServiceClient(configContext);
+ sender.setOptions(options);
MyBean bean = new MyBean();
bean.setAge(100);
@@ -170,12 +177,12 @@
args.add(bean);
- OMElement response = call.invokeBlocking(operationName, args.toArray());
+ OMElement response = sender.invokeBlocking(operationName, args.toArray());
MyBean resBean = (MyBean) BeanUtil.deserialize(MyBean.class, response.getFirstElement());
// MyBean resBean =(MyBean) new BeanSerializer(MyBean.class,response).deserilze();
assertNotNull(resBean);
assertEquals(resBean.getAge(), 100);
- call.close();
+ sender.finalizeInvoke();
}
@@ -186,15 +193,17 @@
options.setTo(targetEPR);
options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
- RPCCall call =
- new RPCCall("target/test-resources/integrationRepo");
- call.setClientOptions(options);
+ ConfigurationContextFactory factory = new ConfigurationContextFactory();
+ ConfigurationContext configContext =
+ factory.buildConfigurationContext("target/test-resources/integrationRepo");
+ RPCServiceClient sender = new RPCServiceClient(configContext);
+ sender.setOptions(options);
ArrayList args = new ArrayList();
args.add("foo");
- OMElement response = call.invokeBlocking(operationName, args.toArray());
+ OMElement response = sender.invokeBlocking(operationName, args.toArray());
assertEquals(response.getFirstElement().getText(), "foo");
- call.close();
+ sender.finalizeInvoke();
}
public void testEchoInt() throws AxisFault {
@@ -204,70 +213,81 @@
options.setTo(targetEPR);
options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
- RPCCall call =
- new RPCCall("target/test-resources/integrationRepo");
- call.setClientOptions(options);
+ ConfigurationContextFactory factory = new ConfigurationContextFactory();
+ ConfigurationContext configContext =
+ factory.buildConfigurationContext("target/test-resources/integrationRepo");
+ RPCServiceClient sender = new RPCServiceClient(configContext);
+ sender.setOptions(options);
ArrayList args = new ArrayList();
args.add("100");
- OMElement response = call.invokeBlocking(operationName, args.toArray());
+ OMElement response = sender.invokeBlocking(operationName, args.toArray());
assertEquals(Integer.parseInt(response.getFirstElement().getText()), 100);
- call.close();
+ sender.finalizeInvoke();
}
public void testAdd() throws AxisFault {
configureSystem("add");
- RPCCall call =
- new RPCCall("target/test-resources/integrationRepo");
+ ConfigurationContextFactory factory = new ConfigurationContextFactory();
+ ConfigurationContext configContext =
+ factory.buildConfigurationContext("target/test-resources/integrationRepo");
+ RPCServiceClient sender = new RPCServiceClient(configContext);
Options options = new Options();
options.setTo(targetEPR);
options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
- call.setClientOptions(options);
+ sender.setOptions(options);
ArrayList args = new ArrayList();
args.add("100");
args.add("200");
- OMElement response = call.invokeBlocking(operationName, args.toArray());
+ OMElement response = sender.invokeBlocking(operationName, args.toArray());
assertEquals(Integer.parseInt(response.getFirstElement().getText()), 300);
- call.close();
+ sender.finalizeInvoke();
}
public void testDivide() throws AxisFault {
configureSystem("divide");
- RPCCall call =
- new RPCCall("target/test-resources/integrationRepo");
Options options = new Options();
- call.setClientOptions(options);
options.setTo(targetEPR);
options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
+ ConfigurationContextFactory factory = new ConfigurationContextFactory();
+ ConfigurationContext configContext =
+ factory.buildConfigurationContext("target/test-resources/integrationRepo");
+ RPCServiceClient sender = new RPCServiceClient(configContext);
+ sender.setOptions(options);
+
+
ArrayList args = new ArrayList();
args.add("10");
args.add("0");
- OMElement response = call.invokeBlocking(operationName, args.toArray());
+ OMElement response = sender.invokeBlocking(operationName, args.toArray());
assertEquals(response.getFirstElement().getText(), "INF");
- call.close();
+ sender.finalizeInvoke();
}
public void testEchoBool() throws AxisFault {
configureSystem("echoBool");
- RPCCall call =
- new RPCCall("target/test-resources/integrationRepo");
Options options = new Options();
options.setTo(targetEPR);
options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
- call.setClientOptions(options);
+
+ ConfigurationContextFactory factory = new ConfigurationContextFactory();
+ ConfigurationContext configContext =
+ factory.buildConfigurationContext("target/test-resources/integrationRepo");
+ RPCServiceClient sender = new RPCServiceClient(configContext);
+ sender.setOptions(options);
ArrayList args = new ArrayList();
args.add("true");
- OMElement response = call.invokeBlocking(operationName, args.toArray());
+ OMElement response = sender.invokeBlocking(operationName, args.toArray());
assertEquals(Boolean.valueOf(response.getFirstElement().getText()).booleanValue(), true);
- call.close();
+ sender.finalizeInvoke();
}
public void testEchoByte() throws AxisFault {
@@ -278,15 +298,17 @@
options.setTo(targetEPR);
options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
- RPCCall call =
- new RPCCall("target/test-resources/integrationRepo");
- call.setClientOptions(options);
+ ConfigurationContextFactory factory = new ConfigurationContextFactory();
+ ConfigurationContext configContext =
+ factory.buildConfigurationContext("target/test-resources/integrationRepo");
+ RPCServiceClient sender = new RPCServiceClient(configContext);
+ sender.setOptions(options);
ArrayList args = new ArrayList();
args.add("1");
- OMElement response = call.invokeBlocking(operationName, args.toArray());
+ OMElement response = sender.invokeBlocking(operationName, args.toArray());
assertEquals(Byte.parseByte(response.getFirstElement().getText()), 1);
- call.close();
+ sender.finalizeInvoke();
}
public void testCompany() throws AxisFault {
@@ -296,9 +318,11 @@
options.setTo(targetEPR);
options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
- RPCCall call =
- new RPCCall("target/test-resources/integrationRepo");
- call.setClientOptions(options);
+ ConfigurationContextFactory factory = new ConfigurationContextFactory();
+ ConfigurationContext configContext =
+ factory.buildConfigurationContext("target/test-resources/integrationRepo");
+ RPCServiceClient sender = new RPCServiceClient(configContext);
+ sender.setOptions(options);
Company com = new Company();
com.setName("MyCompany");
@@ -323,8 +347,8 @@
com.setPersons(ps);
ArrayList args = new ArrayList();
args.add(com);
- OMElement response = call.invokeBlocking(operationName, args.toArray());
- call.close();
+ sender.invokeBlocking(operationName, args.toArray());
+ sender.finalizeInvoke();
}
public void testEchoOM() throws AxisFault {
@@ -334,15 +358,17 @@
options.setTo(targetEPR);
options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
- RPCCall call =
- new RPCCall("target/test-resources/integrationRepo");
- call.setClientOptions(options);
+ ConfigurationContextFactory factory = new ConfigurationContextFactory();
+ ConfigurationContext configContext =
+ factory.buildConfigurationContext("target/test-resources/integrationRepo");
+ RPCServiceClient sender = new RPCServiceClient(configContext);
+ sender.setOptions(options);
ArrayList args = new ArrayList();
args.add("1");
- OMElement response = call.invokeBlocking(operationName, args.toArray());
+ OMElement response = sender.invokeBlocking(operationName, args.toArray());
assertEquals(Byte.parseByte(response.getFirstElement().getText()), 1);
- call.close();
+ sender.finalizeInvoke();
}
public void testCalender() throws AxisFault {
@@ -353,16 +379,18 @@
options.setTo(targetEPR);
options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
- RPCCall call =
- new RPCCall("target/test-resources/integrationRepo");
- call.setClientOptions(options);
+ ConfigurationContextFactory factory = new ConfigurationContextFactory();
+ ConfigurationContext configContext =
+ factory.buildConfigurationContext("target/test-resources/integrationRepo");
+ RPCServiceClient sender = new RPCServiceClient(configContext);
+ sender.setOptions(options);
ArrayList args = new ArrayList();
Date date = Calendar.getInstance().getTime();
args.add(zulu.format(date));
- OMElement response = call.invokeBlocking(operationName, args.toArray());
+ OMElement response = sender.invokeBlocking(operationName, args.toArray());
assertEquals(response.getFirstElement().getText(), zulu.format(date));
- call.close();
+ sender.finalizeInvoke();
}
@@ -374,9 +402,11 @@
options.setTo(targetEPR);
options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
- RPCCall call =
- new RPCCall("target/test-resources/integrationRepo");
- call.setClientOptions(options);
+ ConfigurationContextFactory factory = new ConfigurationContextFactory();
+ ConfigurationContext configContext =
+ factory.buildConfigurationContext("target/test-resources/integrationRepo");
+ RPCServiceClient sender = new RPCServiceClient(configContext);
+ sender.setOptions(options);
MyBean bean = new MyBean();
bean.setAge(100);
@@ -393,11 +423,11 @@
ArrayList ret = new ArrayList();
ret.add(MyBean.class);
- Object [] response = call.invokeBlocking(operationName, args.toArray(), ret.toArray());
+ Object [] response = sender.invokeBlocking(operationName, args.toArray(), ret.toArray());
MyBean resBean = (MyBean) response[0];
assertNotNull(resBean);
assertEquals(resBean.getAge(), 100);
- call.close();
+ sender.finalizeInvoke();
}
public void testechoInt2() throws AxisFault {
@@ -407,9 +437,11 @@
options.setTo(targetEPR);
options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
- RPCCall call =
- new RPCCall("target/test-resources/integrationRepo");
- call.setClientOptions(options);
+ ConfigurationContextFactory factory = new ConfigurationContextFactory();
+ ConfigurationContext configContext =
+ factory.buildConfigurationContext("target/test-resources/integrationRepo");
+ RPCServiceClient sender = new RPCServiceClient(configContext);
+ sender.setOptions(options);
ArrayList args = new ArrayList();
args.add("100");
@@ -417,9 +449,9 @@
ArrayList ret = new ArrayList();
ret.add(Integer.class);
- Object [] response = call.invokeBlocking(operationName, args.toArray(), ret.toArray());
+ Object [] response = sender.invokeBlocking(operationName, args.toArray(), ret.toArray());
assertEquals(((Integer) response[0]).intValue(), 100);
- call.close();
+ sender.finalizeInvoke();
}
public void testmultireturn() throws AxisFault {
@@ -429,9 +461,11 @@
options.setTo(targetEPR);
options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
- RPCCall call =
- new RPCCall("target/test-resources/integrationRepo");
- call.setClientOptions(options);
+ ConfigurationContextFactory factory = new ConfigurationContextFactory();
+ ConfigurationContext configContext =
+ factory.buildConfigurationContext("target/test-resources/integrationRepo");
+ RPCServiceClient sender = new RPCServiceClient(configContext);
+ sender.setOptions(options);
ArrayList args = new ArrayList();
args.add("1");
@@ -440,11 +474,11 @@
ret.add(Integer.class);
ret.add(String.class);
- Object [] response = call.invokeBlocking(operationName, args.toArray(), ret.toArray());
+ Object [] response = sender.invokeBlocking(operationName, args.toArray(), ret.toArray());
assertEquals(((Integer) response[0]).intValue(), 10);
assertEquals(response[1], "foo");
// assertEquals(Byte.parseByte(response.getFirstElement().getText()),1);
- call.close();
+ sender.finalizeInvoke();
}
public void testmulReturn() throws AxisFault {
@@ -454,17 +488,19 @@
options.setTo(targetEPR);
options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
- RPCCall call =
- new RPCCall("target/test-resources/integrationRepo");
- call.setClientOptions(options);
+ ConfigurationContextFactory factory = new ConfigurationContextFactory();
+ ConfigurationContext configContext =
+ factory.buildConfigurationContext("target/test-resources/integrationRepo");
+ RPCServiceClient sender = new RPCServiceClient(configContext);
+ sender.setOptions(options);
ArrayList args = new ArrayList();
args.add("foo");
- OMElement response = call.invokeBlocking(operationName, args.toArray());
+ sender.invokeBlocking(operationName, args.toArray());
// assertEquals(response.getFirstElement().getText(), "foo");
- call.close();
+ sender.finalizeInvoke();
}
@@ -475,13 +511,15 @@
options.setTo(targetEPR);
options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
- RPCCall call =
- new RPCCall("target/test-resources/integrationRepo");
- call.setClientOptions(options);
+ ConfigurationContextFactory factory = new ConfigurationContextFactory();
+ ConfigurationContext configContext =
+ factory.buildConfigurationContext("target/test-resources/integrationRepo");
+ RPCServiceClient sender = new RPCServiceClient(configContext);
+ sender.setOptions(options);
- OMElement elem = call.invokeBlocking("handleArrayList", getpayLoad());
+ OMElement elem = sender.sendReceive(getpayLoad());
assertEquals(elem.getFirstElement().getText(), "abcdefghiklm10");
- call.close();
+ sender.finalizeInvoke();
}
private OMElement getpayLoad() throws AxisFault {