Axis2 Pass List Object _list

Source: Internet
Author: User
Tags wsdl

Download jar Package: Axis2-1.5.4-bin.zip

Download War Package: Axis2-1.5.4-war.zip

Path Online has

Service-Side directory:

Client directory:

Unpack Axis2-1.5.4-war.zip, get Axis2.war package, put it under Tomcat, start Tomcat

1.tomcat.0\webapps\axis2\web-inf, copy the Conf folder and Services folder under this path to the Web-inf in the server

2. Create the corresponding directory under the Services folder. Create a new Service.xml file, copy the following service.xml code

3. Note Web-inf\conf\axis2.xml under "<module ref=" addressing "/>" is about 237 lines

4. Copy Axis2-1.5.4-bin.zip extract all the jars under the Lib package to the server and client (then filter the necessary jar packages)

4. Add in Web.xml

Web.xml Code

<?xml version= "1.0" encoding= "UTF-8"?> <web-app version= "2.5" xmlns= "Http://java.sun.com/xml/ns/javaee" Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xsi:schemalocation= "Http://java.sun.com/xml/ns/javaee http ://java.sun.com/xml/ns/javaee/web-app_2_5.xsd "> <servlet> &LT;SERVLET-NAME&GT;AXISSERVLET&LT;/SERVL et-name> <servlet-class> Org.apache.axis2.transport.http.AxisServlet </se rvlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-map Ping> <servlet-name>AxisServlet</servlet-name> <url-pattern>/servlet/axisservle t</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>axisse   
    Rvlet</servlet-name> <url-pattern>*.jws</url-pattern> </servlet-mapping>   
        <servlet-mapping><servlet-name>AxisServlet</servlet-name> <url-pattern>/services/*</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </wel
 Come-file-list> </web-app>


Service-side Service.xml code

 <serviceGroup> <!--define the service name and use this service name when accessing the URL--> <service name= "Boboservice" scope= "Soapsession" > <description></description> <messageReceivers> <messagereceiver mep= "HTTP://WWW.W3.ORG/2 004/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> <!--serviceclass Specifies the location of the Java class, which is the class that implements the service. --> <parameter name= "ServiceClass" locked= "Xsd:false" > Com.bobo.service.BOBOService </parameter> & lt;! --operation corresponds to the method name in Java class--> <operation name= "Receiveuser" > <messagereceiver class= "Org.apache.a" Xis2.receivers.RawXMLINOutMessageReceiver "/> <actionMapping>urn:receiveUser</actionMapping> </ Operation> </service> </servicegroup> 


Service side, client same user code

Package com.bobo.entity;

Import java.io.Serializable;


public class User implements Serializable {
	private static final long serialversionuid = 677484458789332877L;
	private int id;
	private String name;
	private String Email;
	Private String address;
	
	Public User () {} public

	int getId () {return
		ID;
	}

	public void setId (int id) {
		this.id = ID;
	}

	Public String GetName () {return
		name;
	}

	public void SetName (String name) {
		this.name = name;
	}

	Public String Getemail () {return
		email;
	}

	public void Setemail (String email) {
		This.email = email;
	}

	Public String getaddress () {return address
		;
	}

	public void setaddress (String address) {
		this.address = address;
	}

	@Override public
	String toString () {return
		this.id + "#" + THIS.name + "#" + This.email + "#" + this.address;
  }
}


Client Boboclient Code

Package com.bobo.client;
Import java.util.ArrayList;

Import java.util.List;

Import Javax.xml.namespace.QName;
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.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.transport.http.HTTPConstants;

Import Com.bobo.entity.User; public class Boboclient {public static void main (string[] args) throws Exception {endpointreference Targetepr = new E
		Ndpointreference ("Http://localhost:8085/Axis2service/services/BOBOService");


		EndpointReference Targetepr = new EndpointReference ("Http://localhost:8085/SayHello/services/APIWebService2");
			try {Options options = new options ();
			
			Options.setto (TARGETEPR); Options.settranspOrtinprotocol (constants.transport_http);
			
			
			Options.setproperty (httpconstants.chunked, "false");//settings Unrestricted.
			ServiceClient sender = new ServiceClient ();
			Sender.setoptions (options);
			System.out.println ("WebService start");
			
			Omelement SayHello = Dosetomelement ();
			Omfactory FAC = omabstractfactory.getomfactory ();
			Omnamespace omns = Fac.createomnamespace ("", "");
			Omelement method = Fac.createomelement ("Receiveuser", omns);
			
			Method.addchild (SayHello);
			Omelement result = Sender.sendreceive (method);

		System.out.println ("WebService End");
		catch (Exception e) {e.printstacktrace ();
	 }/** * Creates the parameters Omelement object required to invoke the WebService interface.
		* * @return/public static omelement Dosetomelement () {list<user> List = new arraylist<user> ();
		User User1 = new user ();
		User1.setid (1);
		User1.setname ("Chenbo");
		User1.setaddress ("AAAA");
		User1.setemail ("ddddddd");
		User User2 = new user ();
		User2.setid (2); User2.setname ("Chenbo2");
		User2.setaddress ("Aaaa2");
		User2.setemail ("Ddddddd2");
		List.add (user1);
		List.add (User2);
		String typeName = "Computer";
		Construction of Omfactory factory omfactory factory = Omabstractfactory.getomfactory ();
		Omnamespace omnamespace = Factory.createomnamespace ("http://service.bob.com", "ns");
		Omelement omelement = beanutil.getomelement (New QName ("root"), List.toarray (), New QName ("User"), false, NULL);
		Omelement.addattribute ("name", TypeName, Omnamespace);
		
	return omelement;
 }
}


Service-side Boboservice code

Package com.bobo.service;
Import java.util.ArrayList;
Import Java.util.Iterator;

Import java.util.List;
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.databinding.utils.BeanUtil;

Import Org.apache.axis2.engine.DefaultObjectSupplier;

Import Com.bobo.entity.User; public class Boboservice {public omelement receiveuser (omelement userele) throws Exception {System.out.println ("Enter suit Service End method ....
		");

		list<user> list = GetResults (Userele);
		for (User user:list) {System.out.println (User.getname ());
		} omfactory FAC = Omabstractfactory.getomfactory ();
		Omnamespace omns = Fac.createomnamespace ("", "");

		Omelement Soapmain = fac.createomelement ("Sendclient", omns);
	return soapmain; private static list<user> GetResults (omelement element) throws Axisfault {if (element = = null) {return null; element = (omelement) element.getchildelements (). Next ();
		The next element iterator iterator = element.getchildelements ();
		list<user> list = new arraylist<user> ();
			while (Iterator.hasnext ()) {Omnode Omnode = (omnode) iterator.next ();
				if (omnode.gettype () = = Omnode.element_node) {omelement omelement = (omelement) Omnode;
				System.out.println (Omelement.getlocalname ()); if (Omelement.getlocalname (). toLowerCase (). Equals ("user") {User user = (user) Beanutil.processobject (omelement, use
					R.class, NULL, True, New Defaultobjectsupplier ());
				List.add (User);
	}} return list; }

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.