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/10/25 10:45:51 UTC
svn commit: r328315 - in /webservices/axis2/trunk/java/modules:
codegen/src/org/apache/axis2/util/ integration/test/org/apache/axis2/rpc/
Author: deepal
Date: Tue Oct 25 01:45:30 2005
New Revision: 328315
URL: http://svn.apache.org/viewcvs?rev=328315&view=rev
Log:
added Cyclic mulrefs , now RPCMessageReciver can support smt like below;
<soapenv:Body>
<my:echoEmployee xmlns:my="http://localhost/my">
<arg0 href="#1"></arg0>
</my:echoEmployee>
<reference id="1">
<name>John</name>
<age>50</age>
<emplyer href="#1"></emplyer>
<address href="#2"></address>
</reference>
<reference id="2">
<town>Colombo3</town>
<number>1010</number>
</reference>
</soapenv:Body>
Added:
webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/rpc/Employee.java
webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/rpc/Person.java
Modified:
webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/util/BeanSerializerUtil.java
webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/rpc/MultirefTest.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/util/BeanSerializerUtil.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/util/BeanSerializerUtil.java?rev=328315&r1=328314&r2=328315&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 Tue Oct 25 01:45:30 2005
@@ -29,7 +29,6 @@
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;
@@ -50,28 +49,30 @@
*/
public static XMLStreamReader getPullParser(Object beanObject, QName beanName ) {
try {
- Field [] fields = beanObject.getClass().getDeclaredFields();
+ BeanInfo beanInfo = Introspector.getBeanInfo(beanObject.getClass());
+ PropertyDescriptor [] propDescs = beanInfo.getPropertyDescriptors();
ArrayList objetc = new ArrayList();
- for (int i = 0; i < fields.length; i++) {
- Field filed = fields[i];
- Class parameters = filed.getType();
- if(SimpleTypeMapper.isSimpleType(parameters)){
- objetc.add(filed.getName());
- filed.setAccessible(true);
- objetc.add(filed.get(beanObject).toString());
- filed.setAccessible(false);
+ for (int i = 0; i < propDescs.length; i++) {
+ PropertyDescriptor propDesc = propDescs[i];
+ Class ptype = propDesc.getPropertyType();
+ if(propDesc.getName().equals("class")){
+ continue;
+ }
+ if(SimpleTypeMapper.isSimpleType(ptype)){
+ Object value = propDesc.getReadMethod().invoke(beanObject,null);
+ objetc.add(propDesc.getName());
+ objetc.add(value.toString());
} else {
- objetc.add(new QName(filed.getName()));
- filed.setAccessible(true);
- objetc.add(filed.get(beanObject));
- filed.setAccessible(false);
+ objetc.add(new QName(propDesc.getName()));
+ Object value = propDesc.getReadMethod().invoke(beanObject,null);
+ objetc.add(value);
}
}
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.
- } catch (IllegalAccessException e) {
+ } catch (Exception e) {
//todo has to throw this exeception
return null;
}
@@ -96,11 +97,11 @@
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
- */
+/**
+ * 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){
@@ -141,7 +142,13 @@
beanObj = beanClass.newInstance();
Iterator elements = beanElement.getChildren();
while (elements.hasNext()) {
- OMElement parts = (OMElement) elements.next();
+ Object child = elements.next();
+ OMElement parts ;
+ if(child instanceof OMElement){
+ parts= (OMElement) child;
+ } else {
+ continue;
+ }
String partsLocalName = parts.getLocalName();
PropertyDescriptor prty =(PropertyDescriptor)properties.get(partsLocalName.toLowerCase());
if(prty !=null){
@@ -206,24 +213,24 @@
int count =0;
Object [] retObjs = new Object[length];
- /**
- * If the body first child contains , then there can not be any other element withot
- * refs , so I can assume if the first child of the body first element has ref then
- * the messge has to handle as mutiref message.
- * as an exmple if the body is like below
- * <foo>
- * <arg0 href="#0"/>
- * </foo>
- *
- * then there can not be any element without refs , meaning following we are not handling
- * <foo>
- * <arg0 href="#0"/>
- * <arg1>absbsbs</arg1>
- * </foo>
- */
+/**
+ * If the body first child contains , then there can not be any other element withot
+ * refs , so I can assume if the first child of the body first element has ref then
+ * the messge has to handle as mutiref message.
+ * as an exmple if the body is like below
+ * <foo>
+ * <arg0 href="#0"/>
+ * </foo>
+ *
+ * then there can not be any element without refs , meaning following we are not handling
+ * <foo>
+ * <arg0 href="#0"/>
+ * <arg1>absbsbs</arg1>
+ * </foo>
+ */
Iterator parts = response.getChildren();
- //to handle multirefs
- //have to check the instnceof
+//to handle multirefs
+//have to check the instnceof
MultirefHelper helper = new MultirefHelper((OMElement)response.getParent());
boolean hasRef = false;
while (parts.hasNext() && count < length) {
@@ -236,7 +243,7 @@
}
Class classType = (Class)javaTypes[count];
- //handling refs
+//handling refs
OMAttribute omatribute = MultirefHelper.processRefAtt(omElement);
String ref=null;
if(omatribute !=null) {
@@ -287,9 +294,9 @@
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
+//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());
Added: webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/rpc/Employee.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/rpc/Employee.java?rev=328315&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/rpc/Employee.java (added)
+++ webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/rpc/Employee.java Tue Oct 25 01:45:30 2005
@@ -0,0 +1,46 @@
+package org.apache.axis2.rpc;
+/*
+* 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 Employee extends Person{
+
+ protected Person emplyer;
+ protected AddressBean address;
+
+ public Person getEmplyer() {
+ return emplyer;
+ }
+
+ public void setEmplyer(Person emplyer) {
+ this.emplyer = emplyer;
+ }
+
+ public AddressBean getAddress() {
+ return address;
+ }
+
+ public void setAddress(AddressBean address) {
+ this.address = address;
+ }
+
+ public String toString(){
+ String str = "Name:" + getName() + " Age: " + getAge();
+ return str;
+ }
+}
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=328315&r1=328314&r2=328315&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 Tue Oct 25 01:45:30 2005
@@ -421,6 +421,47 @@
}
+ public void testechoEmployee() throws AxisFault {
+ configureSystem("echoEmployee");
+ OMFactory fac = OMAbstractFactory.getOMFactory();
+
+ OMNamespace omNs = fac.createOMNamespace("http://localhost/my", "my");
+ OMElement method = fac.createOMElement("echoEmployee", omNs);
+
+ OMElement value = fac.createOMElement("arg0", null);
+ value.addAttribute(fac.createOMAttribute("href",null,"#1"));
+ method.addChild(value);
+
+
+ SOAPFactory factory = OMAbstractFactory.getSOAP11Factory();
+ SOAPEnvelope envelope = factory.getDefaultEnvelope();
+ envelope.getBody().addChild(method);
+
+
+ String str= "<reference id=\"1\">\n" +
+ " <name>John</name>\n" +
+ " <age>50</age>\n" +
+ " <emplyer href=\"#1\"/>\n" +
+ " <address href=\"#2\"/>\n" +
+ "</reference>";
+ envelope.getBody().addChild(getOMelemnt(str,fac));
+ str ="<reference id=\"2\">\n" +
+ "<town>Colombo3</town><number>1010</number>\n" +
+ "</reference>";
+ envelope.getBody().addChild(getOMelemnt(str,fac));
+ RPCCall call =
+ new RPCCall("target/test-resources/intregrationRepo");
+
+ call.setTo(targetEPR);
+ call.setTransportInfo(Constants.TRANSPORT_HTTP,
+ Constants.TRANSPORT_HTTP,
+ false);
+ SOAPEnvelope env = call.invokeBlocking("echoEmployee",envelope);
+ Employee emp = (Employee) BeanSerializerUtil.deserialize(Employee.class, env.getBody().getFirstElement().getFirstElement());
+ assertNotNull(emp);
+ }
+
+
public void testMulitrefArray() throws AxisFault {
configureSystem("handleArrayList");
OMFactory fac = OMAbstractFactory.getOMFactory();
Added: webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/rpc/Person.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/rpc/Person.java?rev=328315&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/rpc/Person.java (added)
+++ webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/rpc/Person.java Tue Oct 25 01:45:30 2005
@@ -0,0 +1,40 @@
+package org.apache.axis2.rpc;
+/*
+* 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 Person {
+ protected String name;
+ protected int age;
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public int getAge() {
+ return age;
+ }
+
+ public void setAge(int age) {
+ this.age = age;
+ }
+}
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=328315&r1=328314&r2=328315&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 Tue Oct 25 01:45:30 2005
@@ -142,4 +142,9 @@
}
return str + b;
}
+
+ public Employee echoEmployee(Employee em){
+ System.out.println("vale: " + em.toString());
+ return em;
+ }
}