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 2005/10/20 07:41:59 UTC
svn commit: r326831 - in /webservices/axis2/trunk/java/modules:
codegen/src/org/apache/axis2/rpc/client/
codegen/src/org/apache/axis2/rpc/receivers/
codegen/src/org/apache/axis2/util/ integration/test/org/apache/axis2/rpc/
Author: deepal
Date: Wed Oct 19 22:41:36 2005
New Revision: 326831
URL: http://svn.apache.org/viewcvs?rev=326831&view=rev
Log:
Improved RPCCall to handle the response , overloaded the invokeBlocking method to take array of return JavaTypes , any way I will drop a mail to mailing list describing how to use RPCCall . The interesting with RPCCall it does not use any RPC stuff and user can give a Object array as request parameters and he can get response as an Object array too. I think this cover most of the usecase
Removed:
webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/rpc/receivers/BeanSerializer.java
Modified:
webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/rpc/client/RPCCall.java
webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/rpc/receivers/RPCMessageReceiver.java
webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/rpc/receivers/SimpleTypeMapper.java
webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/util/BeanSerializerUtil.java
webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/rpc/RPCCallTest.java
webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/rpc/RPCServiceClass.java
Modified: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/rpc/client/RPCCall.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/rpc/client/RPCCall.java?rev=326831&r1=326830&r2=326831&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/rpc/client/RPCCall.java (original)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/rpc/client/RPCCall.java Wed Oct 19 22:41:36 2005
@@ -1,18 +1,19 @@
package org.apache.axis2.rpc.client;
import org.apache.axis2.AxisFault;
+import org.apache.axis2.util.BeanSerializerUtil;
+import org.apache.axis2.rpc.receivers.SimpleTypeMapper;
+import org.apache.axis2.databinding.utils.ADBPullParser;
import org.apache.axis2.clientapi.Call;
import org.apache.axis2.clientapi.Callback;
import org.apache.axis2.clientapi.InOutMEPClient;
import org.apache.axis2.context.MessageContext;
import org.apache.axis2.context.ServiceContext;
-import org.apache.axis2.databinding.utils.ADBPullParser;
import org.apache.axis2.description.OperationDescription;
-import org.apache.axis2.om.OMAbstractFactory;
import org.apache.axis2.om.OMElement;
+import org.apache.axis2.om.OMAbstractFactory;
import org.apache.axis2.om.impl.llom.builder.StAXOMBuilder;
import org.apache.axis2.om.impl.llom.factory.OMXMLBuilderFactory;
-import org.apache.axis2.rpc.receivers.SimpleTypeMapper;
import org.apache.axis2.soap.SOAPEnvelope;
import org.apache.wsdl.WSDLConstants;
@@ -98,6 +99,35 @@
}
/**
+ *
+ * @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 {
+ OperationDescription opDesc =
+ serviceContext.getServiceConfig().getOperation(opName);
+ opDesc = createOpDescAndFillInFlowInformation(opDesc, opName.getLocalPart(),
+ WSDLConstants.MEP_CONSTANT_IN_OUT);
+ opDesc.setParent(serviceContext.getServiceConfig());
+ MessageContext msgctx = prepareTheSOAPEnvelope(getOMElement(opName,args));
+ this.lastResponseMessage = super.invokeBlocking(opDesc, msgctx);
+ SOAPEnvelope resEnvelope = lastResponseMessage.getEnvelope();
+ return BeanSerializerUtil.deserialize(resEnvelope.getBody().getFirstElement(),returnTypes);
+ }
+
+ /**
* Invoke the nonblocking/Asynchronous call
*
* @param opName
@@ -126,47 +156,30 @@
* TypeObject , other types of object can not handle yet)
* @param opName
* @param args
- * @return
- * @throws AxisFault
*/
- private OMElement getOMElement(QName opName ,Object [] args) throws AxisFault {
+ private OMElement getOMElement(QName opName ,Object [] args) {
ArrayList objects ;
- try {
- objects = new ArrayList();
- int argCount =0;
- for (int i = 0; i < args.length; i++) {
- Object arg = args[i];
- if(arg instanceof RPCRequestParameter){
- RPCRequestParameter para = (RPCRequestParameter)arg;
- objects.add(para.getName());
- objects.add(para.getValue());
- if (para.isSimpleType()) {
- objects.add(para.getName());
- objects.add(para.getValue().toString());
- } else {
- objects.add(para.getName());
- objects.add(para.getValue().toString());
- }
- } else {
- if(SimpleTypeMapper.isSimpleType(arg)){
- objects.add("arg" + argCount);
- objects.add(arg.toString());
- } else {
- objects.add(new QName("arg" + argCount));
- objects.add(arg);
- }
- argCount ++;
- }
+ objects = new ArrayList();
+ int argCount =0;
+ for (int i = 0; i < args.length; i++) {
+ Object arg = args[i];
+ //todo if the request paramter has name other than argi (0<i<n) , there should be a
+ //was to do that , to solve that problem we need to have RPCRequestParameter
+ //note that The value of request paramter can either be simple type or JavaBean
+ if(SimpleTypeMapper.isSimpleType(arg)){
+ objects.add("arg" + argCount);
+ objects.add(arg.toString());
+ } else {
+ objects.add(new QName("arg" + argCount));
+ objects.add(arg);
}
- XMLStreamReader xr = ADBPullParser.createPullParser(opName,objects.toArray(),null);
- StAXOMBuilder stAXOMBuilder =
- OMXMLBuilderFactory.createStAXOMBuilder(
- OMAbstractFactory.getOMFactory(), xr);
- return stAXOMBuilder.getDocumentElement();
- } catch (ClassCastException e) {
- throw new AxisFault("Object is not a RPCRequestParameter" + e, e);
+ argCount ++;
}
-
+ XMLStreamReader xr = ADBPullParser.createPullParser(opName,objects.toArray(),null);
+ StAXOMBuilder stAXOMBuilder =
+ OMXMLBuilderFactory.createStAXOMBuilder(
+ OMAbstractFactory.getSOAP11Factory(), xr);
+ return stAXOMBuilder.getDocumentElement();
}
}
Modified: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/rpc/receivers/RPCMessageReceiver.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/rpc/receivers/RPCMessageReceiver.java?rev=326831&r1=326830&r2=326831&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/rpc/receivers/RPCMessageReceiver.java (original)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/rpc/receivers/RPCMessageReceiver.java Wed Oct 19 22:41:36 2005
@@ -16,7 +16,6 @@
import javax.xml.namespace.QName;
import javax.xml.stream.XMLStreamReader;
import java.lang.reflect.Method;
-import java.util.Iterator;
/*
* Copyright 2004,2005 The Apache Software Foundation.
*
@@ -113,40 +112,7 @@
private Object[] processRequest(OMElement methodElement) throws AxisFault {
Class[] parameters = method.getParameterTypes();
- int paramCount = 0;
- int numberOfParams = parameters.length;
-
- Object [] objectArray = new Object[numberOfParams];
- Iterator parts = methodElement.getChildren();
- /**
- * Take the number of paramters in the method and , only take that much of child elements
- * from the OMElement , other are ignore , as an example
- * if the method is , foo(String a , int b)
- * and if the OMElemet
- * <foo>
- * <arg0>Val1</arg0>
- * <arg1>Val2</arg1>
- * <arg2>Val3</arg2>
- *
- * only the val1 and Val2 take into account
- */
- while (parts.hasNext() && paramCount < numberOfParams) {
- OMElement omElement = (OMElement) parts.next();
- Class parameter = parameters[paramCount];
- //todo do we need to support REF and MultiRef
- //todo firts xsi:type has to be checked , and if that is there take the
- //todo handle arrays
- // corret one from sereviceDescription
- if(OMElement.class.isAssignableFrom(parameter)){
- objectArray[paramCount] =omElement;
- } else if(SimpleTypeMapper.isSimpleType(parameter)){
- objectArray[paramCount] = SimpleTypeMapper.getSimpleTypeObject(parameter, omElement);
- } else {
- objectArray[paramCount] = new BeanSerializer(parameter, omElement).deserialize();
- }
- paramCount ++;
- }
- return objectArray;
+ return BeanSerializerUtil.deserialize(methodElement,parameters);
}
@@ -156,7 +122,7 @@
//todo first check to see where the desrilizer for the return object
//simple type
if(resObject instanceof OMElement){
- bodyContent = (OMElement)resObject;
+ bodyContent=(OMElement)resObject;
} else if (SimpleTypeMapper.isSimpleType(resObject)) {
bodyContent = getSOAPFactory().createOMElement(
method.getName() + "Response", ns);
@@ -164,17 +130,17 @@
child.addChild(fac.createText(child, SimpleTypeMapper.getStringValue(resObject)));
bodyContent.addChild(child);
} else {
+ bodyContent = getSOAPFactory().createOMElement(
+ method.getName() + "Response", ns);
// Java Beans
- QName wrapperQname = new QName("http://soapenc/", method.getName() + "Response", "res");
XMLStreamReader xr = BeanSerializerUtil.getPullParser(resObject,
- wrapperQname);
+ new QName(RETURN_WRAPPER));
StAXOMBuilder stAXOMBuilder =
OMXMLBuilderFactory.createStAXOMBuilder(
OMAbstractFactory.getOMFactory(), xr);
OMElement documentElement = stAXOMBuilder.getDocumentElement();
-
if (documentElement != null) {
- bodyContent = documentElement;
+ bodyContent.addChild(documentElement);
}
}
}
Modified: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/rpc/receivers/SimpleTypeMapper.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/rpc/receivers/SimpleTypeMapper.java?rev=326831&r1=326830&r2=326831&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/rpc/receivers/SimpleTypeMapper.java (original)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/rpc/receivers/SimpleTypeMapper.java Wed Oct 19 22:41:36 2005
@@ -80,6 +80,22 @@
return new Float(value.getText());
} else if (paramter.getName().equals(CHAR)) {
return new Character(value.getText().toCharArray()[0]);
+ } else if (paramter.getName().equals(W_INT)) {
+ return new Integer(value.getText());
+ } else if (paramter.getName().equals(W_BOOLEAN)) {
+ return Boolean.valueOf(value.getText());
+ } else if (paramter.getName().equals(W_BYTE)) {
+ return new Byte(value.getText());
+ } else if (paramter.getName().equals(W_DOUBLE)) {
+ return new Double(value.getText());
+ } else if (paramter.getName().equals(W_SHORT)) {
+ return new Short(value.getText());
+ } else if (paramter.getName().equals(W_LONG)) {
+ return new Long(value.getText());
+ } else if (paramter.getName().equals(W_FLOAT)) {
+ return new Float(value.getText());
+ } else if (paramter.getName().equals(W_CHAR)) {
+ return new Character(value.getText().toCharArray()[0]);
} else if (paramter.getName().equals(W_CALANDER)) {
return makeCalendar(value.getText(),false);
}else {
Modified: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/util/BeanSerializerUtil.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/util/BeanSerializerUtil.java?rev=326831&r1=326830&r2=326831&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/util/BeanSerializerUtil.java (original)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/util/BeanSerializerUtil.java Wed Oct 19 22:41:36 2005
@@ -1,16 +1,22 @@
package org.apache.axis2.util;
-import org.apache.axis2.databinding.utils.ADBPullParser;
+
import org.apache.axis2.rpc.receivers.SimpleTypeMapper;
+import org.apache.axis2.databinding.utils.ADBPullParser;
+import org.apache.axis2.om.OMElement;
+import org.apache.axis2.AxisFault;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLStreamReader;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
import java.beans.PropertyDescriptor;
import java.beans.Introspector;
import java.beans.IntrospectionException;
+import java.beans.BeanInfo;
/*
* Copyright 2004,2005 The Apache Software Foundation.
*
@@ -39,7 +45,7 @@
* @param beanName
*/
public static XMLStreamReader getPullParser(Object beanObject, QName beanName ) {
- try {
+ try {
Field [] fields = beanObject.getClass().getDeclaredFields();
ArrayList objetc = new ArrayList();
for (int i = 0; i < fields.length; i++) {
@@ -58,14 +64,106 @@
}
}
return ADBPullParser.createPullParser(beanName, objetc.toArray(), null);
- // TODO : Deepal fix this. I added another parameter to the above method in the ADBPullPrser
- // to get the attributes array. For the time being I passed null. Pass attributes array here.
+ // TODO : Deepal fix this. I added another parameter to the above method in the ADBPullPrser
+ // to get the attributes array. For the time being I passed null. Pass attributes array here.
} catch (IllegalAccessException e) {
- //todo has to throw this exeception
- return null;
+ //todo has to throw this exeception
+ return null;
}
}
+ public static Object deserialize(Class beanClass, OMElement beanElement) throws AxisFault{
+ Object beanObj ;
+ try {
+ HashMap properties = new HashMap() ;
+ BeanInfo beanInfo = Introspector.getBeanInfo(beanClass);
+ PropertyDescriptor [] propDescs = beanInfo.getPropertyDescriptors();
+ for (int i = 0; i < propDescs.length; i++) {
+ PropertyDescriptor proprty = propDescs[i];
+ properties.put(proprty.getName(), proprty);
+ }
+
+ beanObj = beanClass.newInstance();
+ Iterator elements = beanElement.getChildren();
+ while (elements.hasNext()) {
+ OMElement parts = (OMElement) elements.next();
+// if parts/@href != null then need to find element with id and deserialize. before that first check wheher already have in hashtable
+ String partsLocalName = parts.getLocalName();
+ PropertyDescriptor prty =(PropertyDescriptor)properties.get(partsLocalName.toLowerCase());
+// if (prty == null) {
+ /**
+ * I think this can be happen , that is because there is a method whcih take Man
+ * object and request can contain a Employee object (which extend Man) , there for
+ * Employee may have more field than Man , so no need to thow an exception
+ */
+// throw new AxisFault("User Error , In vaild bean ! prty does not exist " + "set" +
+// partsLocalName);
+ if(prty !=null){
+ Class parameters = prty.getPropertyType();
+ if (prty.equals("class"))
+ continue;
+ Object partObj = SimpleTypeMapper.getSimpleTypeObject(parameters, parts);
+ if (partObj == null) {
+ partObj = deserialize(parameters, parts);
+ }
+ Object [] parms = new Object[]{partObj};
+ prty.getWriteMethod().invoke(beanObj,parms);
+ }
+ }
+ } catch (InstantiationException e) {
+ throw new AxisFault("InstantiationException : " + e);
+ } catch (IllegalAccessException e) {
+ throw new AxisFault("IllegalAccessException : " + e);
+ } catch (InvocationTargetException e) {
+ throw new AxisFault("InvocationTargetException : " + e);
+ } catch (IntrospectionException e) {
+ throw new AxisFault("IntrospectionException : " + e);
+ }
+ return beanObj;
+ }
+
+
+ /**
+ * To get JavaObjects from XML elemnt , the element most of the time contains only one element
+ * in that case that element will be converted to the JavaType specified by the returnTypes array
+ * The algo is as follows, get the childerns of the response element , and if it conatian more than
+ * one element then check the retuen type of that element and conver that to corresponding JavaType
+ * @param response OMElement
+ * @param returnTypes Array of JavaTypes
+ * @return Array of objects
+ * @throws AxisFault
+ */
+ public static Object [] deserialize(OMElement response , Object [] returnTypes ) throws AxisFault {
+ /**
+ * Take the number of paramters in the method and , only take that much of child elements
+ * from the OMElement , other are ignore , as an example
+ * if the method is , foo(String a , int b)
+ * and if the OMElemet
+ * <foo>
+ * <arg0>Val1</arg0>
+ * <arg1>Val2</arg1>
+ * <arg2>Val3</arg2>
+ *
+ * only the val1 and Val2 take into account
+ */
+ int length = returnTypes.length;
+ int count =0;
+ Object [] retObjs = new Object[length];
+ Iterator parts = response.getChildren();
+ while (parts.hasNext() && count < length) {
+ OMElement omElement = (OMElement) parts.next();
+ Class classType = (Class)returnTypes[count];
+ if(OMElement.class.isAssignableFrom(classType)){
+ retObjs[count] =omElement;
+ } else if(SimpleTypeMapper.isSimpleType(classType)){
+ retObjs[count] = SimpleTypeMapper.getSimpleTypeObject(classType, omElement);
+ } else {
+ retObjs[count] = BeanSerializerUtil.deserialize(classType, omElement);
+ }
+ count ++;
+ }
+ return retObjs;
+ }
}
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=326831&r1=326830&r2=326831&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 Wed Oct 19 22:41:36 2005
@@ -15,8 +15,8 @@
import org.apache.axis2.om.OMElement;
import org.apache.axis2.receivers.AbstractMessageReceiver;
import org.apache.axis2.rpc.client.RPCCall;
-import org.apache.axis2.rpc.receivers.BeanSerializer;
import org.apache.axis2.rpc.receivers.RPCMessageReceiver;
+import org.apache.axis2.util.BeanSerializerUtil;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.wsdl.WSDLService;
@@ -52,9 +52,8 @@
*/
public class RPCCallTest extends TestCase {
- private SimpleDateFormat zulu =new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
- // 0123456789 0 123456789
-
+ private SimpleDateFormat zulu = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
+ // 0123456789 0 123456789
protected EndpointReference targetEPR =
@@ -63,7 +62,7 @@
+ "/axis/services/EchoXMLService/concat");
protected Log log = LogFactory.getLog(getClass());
protected QName serviceName = new QName("EchoXMLService");
- protected QName operationName = new QName("http://localhost/my","concat");
+ protected QName operationName = new QName("http://localhost/my", "concat");
protected QName transportName = new QName("http://localhost/my",
"NullTransport");
@@ -115,23 +114,24 @@
args.add(bean);
args.add("159");
- OMElement response = call.invokeBlocking(operationName,args.toArray());
- MyBean resBean =(MyBean) new BeanSerializer(MyBean.class,response).deserialize();
+ OMElement response = call.invokeBlocking(operationName, args.toArray());
+// MyBean resBean =(MyBean) new BeanSerializer(MyBean.class,response).deserilze();
+ MyBean resBean = (MyBean) BeanSerializerUtil.deserialize(MyBean.class, response.getFirstElement());
assertNotNull(resBean);
- assertEquals(resBean.getAge(),159);
+ assertEquals(resBean.getAge(), 159);
call.close();
}
private void configureSystem(String opName) throws AxisFault {
targetEPR =
new EndpointReference("http://127.0.0.1:"
- + (UtilServer.TESTING_PORT)
- + "/axis/services/EchoXMLService/"+ opName);
+ + (UtilServer.TESTING_PORT)
+ + "/axis/services/EchoXMLService/" + opName);
String className = "org.apache.axis2.rpc.RPCServiceClass";
- operationName = new QName("http://localhost/my",opName,"req");
+ operationName = new QName("http://localhost/my", opName, "req");
ServiceDescription service = new ServiceDescription(serviceName);
service.setClassLoader(Thread.currentThread().getContextClassLoader());
- service.addParameter( new ParameterImpl(AbstractMessageReceiver.SERVICE_CLASS,
+ service.addParameter(new ParameterImpl(AbstractMessageReceiver.SERVICE_CLASS,
className));
OperationDescription axisOp = new InOutOperationDescrition(operationName);
axisOp.setMessageReceiver(new RPCMessageReceiver());
@@ -163,10 +163,11 @@
args.add(bean);
- OMElement response = call.invokeBlocking(operationName,args.toArray());
- MyBean resBean =(MyBean) new BeanSerializer(MyBean.class,response).deserialize();
+ OMElement response = call.invokeBlocking(operationName, args.toArray());
+ MyBean resBean = (MyBean) BeanSerializerUtil.deserialize(MyBean.class, response.getFirstElement());
+// MyBean resBean =(MyBean) new BeanSerializer(MyBean.class,response).deserilze();
assertNotNull(resBean);
- assertEquals(resBean.getAge(),100);
+ assertEquals(resBean.getAge(), 100);
call.close();
}
@@ -183,8 +184,8 @@
ArrayList args = new ArrayList();
args.add("foo");
- OMElement response = call.invokeBlocking(operationName,args.toArray());
- assertEquals(response.getFirstElement().getText(),"foo");
+ OMElement response = call.invokeBlocking(operationName, args.toArray());
+ assertEquals(response.getFirstElement().getText(), "foo");
call.close();
}
@@ -201,8 +202,8 @@
ArrayList args = new ArrayList();
args.add("100");
- OMElement response = call.invokeBlocking(operationName,args.toArray());
- assertEquals(Integer.parseInt(response.getFirstElement().getText()),100);
+ OMElement response = call.invokeBlocking(operationName, args.toArray());
+ assertEquals(Integer.parseInt(response.getFirstElement().getText()), 100);
call.close();
}
@@ -219,8 +220,8 @@
args.add("100");
args.add("200");
- OMElement response = call.invokeBlocking(operationName,args.toArray());
- assertEquals(Integer.parseInt(response.getFirstElement().getText()),300);
+ OMElement response = call.invokeBlocking(operationName, args.toArray());
+ assertEquals(Integer.parseInt(response.getFirstElement().getText()), 300);
call.close();
}
@@ -237,8 +238,8 @@
ArrayList args = new ArrayList();
args.add("10");
args.add("0");
- OMElement response = call.invokeBlocking(operationName,args.toArray());
- assertEquals(response.getFirstElement().getText(),"INF");
+ OMElement response = call.invokeBlocking(operationName, args.toArray());
+ assertEquals(response.getFirstElement().getText(), "INF");
call.close();
}
@@ -256,8 +257,8 @@
ArrayList args = new ArrayList();
args.add("true");
- OMElement response = call.invokeBlocking(operationName,args.toArray());
- assertEquals(Boolean.valueOf(response.getFirstElement().getText()).booleanValue(),true);
+ OMElement response = call.invokeBlocking(operationName, args.toArray());
+ assertEquals(Boolean.valueOf(response.getFirstElement().getText()).booleanValue(), true);
call.close();
}
@@ -273,8 +274,8 @@
ArrayList args = new ArrayList();
args.add("1");
- OMElement response = call.invokeBlocking(operationName,args.toArray());
- assertEquals(Byte.parseByte(response.getFirstElement().getText()),1);
+ OMElement response = call.invokeBlocking(operationName, args.toArray());
+ assertEquals(Byte.parseByte(response.getFirstElement().getText()), 1);
call.close();
}
@@ -290,8 +291,8 @@
ArrayList args = new ArrayList();
args.add("1");
- OMElement response = call.invokeBlocking(operationName,args.toArray());
- assertEquals(Byte.parseByte(response.getFirstElement().getText()),1);
+ OMElement response = call.invokeBlocking(operationName, args.toArray());
+ assertEquals(Byte.parseByte(response.getFirstElement().getText()), 1);
call.close();
}
@@ -307,10 +308,89 @@
false);
ArrayList args = new ArrayList();
- Date date = Calendar.getInstance().getTime();
+ Date date = Calendar.getInstance().getTime();
args.add(zulu.format(date));
- OMElement response = call.invokeBlocking(operationName,args.toArray());
- assertEquals(response.getFirstElement().getText(),zulu.format(date));
+ OMElement response = call.invokeBlocking(operationName, args.toArray());
+ assertEquals(response.getFirstElement().getText(), zulu.format(date));
+ call.close();
+ }
+
+
+ ////////////////////////////////////////////////// Invoking by Passing Return types //////////
+ public void testechoBean2() throws AxisFault {
+ configureSystem("echoBean");
+ RPCCall call =
+ new RPCCall("target/test-resources/intregrationRepo");
+
+ call.setTo(targetEPR);
+ call.setTransportInfo(Constants.TRANSPORT_HTTP,
+ Constants.TRANSPORT_HTTP,
+ false);
+
+ MyBean bean = new MyBean();
+ bean.setAge(100);
+ bean.setName("Deepal");
+ bean.setValue(false);
+ AddressBean ab = new AddressBean();
+ ab.setNumber(1010);
+ ab.setTown("Colombo3");
+ bean.setAddress(ab);
+
+ ArrayList args = new ArrayList();
+ args.add(bean);
+
+ ArrayList ret = new ArrayList();
+ ret.add(MyBean.class);
+
+ Object [] response = call.invokeBlocking(operationName, args.toArray(), ret.toArray());
+ MyBean resBean = (MyBean) response[0];
+ assertNotNull(resBean);
+ assertEquals(resBean.getAge(), 100);
+ call.close();
+ }
+
+ public void testechoInt2() throws AxisFault {
+ configureSystem("echoInt");
+ RPCCall call =
+ new RPCCall("target/test-resources/intregrationRepo");
+
+ call.setTo(targetEPR);
+ call.setTransportInfo(Constants.TRANSPORT_HTTP,
+ Constants.TRANSPORT_HTTP,
+ false);
+
+ ArrayList args = new ArrayList();
+ args.add("100");
+
+ ArrayList ret = new ArrayList();
+ ret.add(Integer.class);
+
+ Object [] response = call.invokeBlocking(operationName, args.toArray(), ret.toArray());
+ assertEquals(((Integer) response[0]).intValue(), 100);
+ call.close();
+ }
+
+ public void testmultireturn() throws AxisFault {
+ configureSystem("multireturn");
+ RPCCall call =
+ new RPCCall("target/test-resources/intregrationRepo");
+
+ call.setTo(targetEPR);
+ call.setTransportInfo(Constants.TRANSPORT_HTTP,
+ Constants.TRANSPORT_HTTP,
+ false);
+
+ ArrayList args = new ArrayList();
+ args.add("1");
+
+ ArrayList ret = new ArrayList();
+ ret.add(Integer.class);
+ ret.add(String.class);
+
+ Object [] response = call.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();
}
Modified: webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/rpc/RPCServiceClass.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/rpc/RPCServiceClass.java?rev=326831&r1=326830&r2=326831&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/rpc/RPCServiceClass.java (original)
+++ webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/rpc/RPCServiceClass.java Wed Oct 19 22:41:36 2005
@@ -3,10 +3,16 @@
import org.apache.axis2.om.OMElement;
import org.apache.axis2.om.OMNamespace;
import org.apache.axis2.om.OMAbstractFactory;
+import org.apache.axis2.om.OMFactory;
+import org.apache.axis2.om.impl.llom.builder.StAXOMBuilder;
import org.apache.axis2.soap.SOAPFactory;
import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamException;
import java.util.Calendar;
+import java.io.ByteArrayInputStream;
/*
* Copyright 2004,2005 The Apache Software Foundation.
*
@@ -64,16 +70,35 @@
SOAPFactory fac = OMAbstractFactory.getSOAP12Factory();
OMNamespace ns = fac.createOMNamespace(
"http://soapenc/", "res");
- OMElement bodyContent = fac.createOMElement(new QName("echoOM") + "Response", ns);
- bodyContent.addChild(b);
+ OMElement bodyContent = fac.createOMElement(
+ "echoOMResponse", ns);
+ OMElement child = fac.createOMElement("return", null);
+ child.addChild(fac.createText(child, b.getText()));
+ bodyContent.addChild(child);
+// bodyContent.addChild(b);
return bodyContent;
}
public double divide(double a , double b){
- return (a/b);
+ return (a/b);
}
public Calendar echoCalander(Calendar in){
return in;
+ }
+
+ public OMElement multireturn(OMElement ele) throws XMLStreamException {
+ SOAPFactory fac = OMAbstractFactory.getSOAP12Factory();
+ OMNamespace omNs = fac.createOMNamespace("http://localhost/my", "res");
+ OMElement method = fac.createOMElement("multiretuenResponse", omNs);
+ OMElement value1 = fac.createOMElement("return0", null);
+ value1.addChild(
+ fac.createText(value1, "10"));
+ method.addChild(value1);
+ OMElement value2 = fac.createOMElement("return1", null);
+ value2.addChild(
+ fac.createText(value2, "foo"));
+ method.addChild(value2);
+ return method;
}
}