67,513
社区成员
发帖
与我相关
我的任务
分享
package palmcity.sketchmap.ws.base;
import java.io.Serializable;
public class ReturnResult implements Serializable{
private static final long serialVersionUID = 1L;
private int returnCode = 0;
private Object returnObject;
private String faultString;
public int getReturnCode() {
return returnCode;
}
public void setReturnCode(int returnCode) {
this.returnCode = returnCode;
}
public Object getReturnObject() {
return returnObject;
}
public void setReturnObject(Object returnObject) {
this.returnObject = returnObject;
}
public String getFaultString() {
return faultString;
}
public void setFaultString(String faultString) {
this.faultString = faultString;
}
}
package palmcity.sketchmap.ws.base;
public class Person {
int userId;
String userName;
int age;
public int getUserId() {
return userId;
}
public void setUserId(int userId) {
this.userId = userId;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
package palmcity.sketchmap.ws.common;
import java.util.ArrayList;
import java.util.List;
import palmcity.sketchmap.ws.base.Person;
import palmcity.sketchmap.ws.base.ReturnResult;
public class PersonManager {
public ReturnResult getPerson(int num){
List<Person> persons = new ArrayList<Person>();
for (int i = 1; i <= num; i++) {
Person person = new Person();
person.setUserId(i);
person.setUserName("人造人" + i + "号");
person.setAge(i * 10);
persons.add(person);
}
ReturnResult rr = new ReturnResult();
rr.setFaultString("faultString");
rr.setReturnObject(persons);
return rr;
}
}
package aixs2listtest;
import java.util.*;
public class HelloBean {
private String name;
private int id;
private List<HelloBeanClass> helloBeanClasses;
public HelloBean(){}
public HelloBean(String name, int id ,List<HelloBeanClass> helloBeanClass){
this.name=name;
this.id=id;
this.helloBeanClasses=helloBeanClass;
}
public void setName(String name){
this.name=name;
}
public String getName(){
return this.name;
}
public void setId(int id){
this.id=id;
}
public int getId(){
return this.id;
}
public List<HelloBeanClass> getHelloBeanClass(){
return this.helloBeanClasses;
}
public void setHelloBeanClass(List<HelloBeanClass> helloBeanClass){
this.helloBeanClasses=helloBeanClass;
}
}
package aixs2listtest;
public class HelloBeanClass {
private int id;
private String className;
public HelloBeanClass(){}
public HelloBeanClass(int id, String className){
this.id=id;
this.className=className;
}
public void setId(int id){
this.id=id;
}
public int getId(){
return this.id;
}
public void setClassName(String className){
this.className=className;
}
public String getClassName(){
return this.className;
}
}
package aixs2listtest;
import java.util.*;
import org.apache.axiom.om.OMNode;
import org.apache.axiom.om.OMElement;
import org.apache.axis2.util.StreamWrapper;
import org.apache.axiom.om.impl.builder.StAXOMBuilder;
import org.apache.axiom.om.impl.llom.factory.OMXMLBuilderFactory;
import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axis2.databinding.utils.BeanUtil;
import javax.xml.namespace.QName;
public class HelloSource {
public OMElement echo(){
HelloBeanClass hbc1=new HelloBeanClass(11,"moonlight1");
HelloBeanClass hbc2=new HelloBeanClass(22,"moonlight2");
HelloBeanClass hbc3=new HelloBeanClass(33,"moonlight3");
List<HelloBeanClass> clss=new ArrayList<HelloBeanClass>();
clss.add(hbc1);clss.add(hbc2);clss.add(hbc3);
HelloBean hbs=new HelloBean("moon",1,clss);
HelloBean hbs2=new HelloBean("mo"+"\non2",2,clss);
HelloBean hbs3=new HelloBean("moon3",3,clss);
List<HelloBean> list = new ArrayList<HelloBean>();
list.add(hbs);
list.add(hbs2);
list.add(hbs3);
OMElement omElement = BeanUtil.getOMElement(new QName("HelloBeans"), list.toArray(), new QName("HelloBean"), false, null);
return omElement;
}
public static void main(String [] args){
HelloSource h=new HelloSource();
System.out.println("asd"+"\n"+"sdf");
h.echo();
}
}
package aixs2listtest;
import java.util.*;
import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMNamespace;
import org.apache.axiom.om.OMNode;
import org.apache.axis2.AxisFault;
import org.apache.axis2.Constants;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;
import org.apache.axis2.databinding.utils.BeanUtil;
import org.apache.axis2.engine.DefaultObjectSupplier;
public class StubTest {
private static EndpointReference targetEPR =
new EndpointReference("http://localhost:8080/axis2/services/HelloSource");
public static OMElement getPricePayload() {
OMFactory fac = OMAbstractFactory.getOMFactory();
OMNamespace omNs = fac.createOMNamespace("http://hello/xsd", "tns");
OMElement method = fac.createOMElement("echo", omNs);
return method;
}
public static void main(String[] args) {
try {
OMElement getPricePayload = getPricePayload();
Options options = new Options();
options.setTo(targetEPR);
options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
ServiceClient sender = new ServiceClient();
sender.setOptions(options);
OMElement result = sender.sendReceive(getPricePayload);
System.err.println(getResults(result));
} catch (Exception e) {
e.printStackTrace();
}
}
private static List<HelloBean> getResults(OMElement element) throws AxisFault {
if (element == null) {
return null;
}
Iterator iterator = element.getChildElements();
List<HelloBean> list = new ArrayList<HelloBean>();
while (iterator.hasNext()) {
OMNode omNode = (OMNode) iterator.next();
if (omNode.getType() == OMNode.ELEMENT_NODE) {
OMElement omElement = (OMElement) omNode;
if (omElement.getLocalName().toLowerCase().equals("return")) {
HelloBean person = (HelloBean) BeanUtil.processObject(omElement,
HelloBean.class, null, true,
new DefaultObjectSupplier());
list.add(person);
}
}
}
return list;
}
}
<service name="HelloSource" scope="application">
<description>
HelloSource
</description>
<messageReceivers>
<messageReceiver
mep="http://www.w3.org/2004/08/wsdl/in-only"
class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver"/>
<messageReceiver
mep="http://www.w3.org/2004/08/wsdl/in-out"
class="org.apache.axis2.rpc.receivers.RPCMessageReceiver"/>
</messageReceivers>
<parameter name="ServiceClass">
aixs2listtest.HelloSource
</parameter>
</service>