Some time ago in the development of a short message to send the Access function, involving the WebServices interface of the call and be called. Below is a record of the steps of the AXIS2 Spring Integration Development webservices (assuming that the Web project has been configured for SSH integration and is functioning properly).
1, add the required jar bag
2, Java class, call and the main code called
/**
* Call external WebServices main code
/**
private static EndpointReference Targetepr = new EndpointReference (Cmproperties.get ("Zn_webservice_url")); Gets the call path of the WebServices interface from the configuration file
private static QName QName = new QName (Cmproperties.get ("Zn_qname"), "main"); Gets the namespace and method name of the call
public static byte[] Callznwebservice (String XML) {
Rpcserviceclient serviceclient = null;
try {
ServiceClient = new Rpcserviceclient ();
catch (Axisfault E3) {
Logger.error ("An exception occurred in the RPC call, WebService call failed.) error message:" +e3.getmessage ());
return null;
}
Options options = Serviceclient.getoptions ();
Options.settimeoutinmilliseconds (9000000);
Options.setproperty (Httpconstants.so_timeout, 9000000);
Options.setproperty (Httpconstants.connection_timeout, 9000000);
Options.setproperty (Httpconstants.reuse_http_client, boolean.true);
Options.setto (TARGETEPR);
try {
object[] args = new object[] {xml.getbytes ("UTF-8")};
class[] Returntypes = new class[] {byte[].class};
object[] response = new object[]{};
Response = serviceclient.invokeblocking (Qname,args, returntypes);
Byte[] result = (byte[]) response[0];
return result;
catch (Exception e) {
Logger.error ("WebService call failed.) error message:" +e.getmessage ());
return null;
}finally{
try {
Serviceclient.cleanuptransport ();
catch (Axisfault e) {
Logger.error ("WebService call failed.) error message:" +e.getmessage ());
return null;
}
}
}
/**
* SMSService class method that provides the invoked WebService interface
*smsreceipt is the name of the method being invoked
/**
Public byte[] Smsreceipt (byte[] xmlstr) {
TODO auto-generated Method Stub
Base64decoder b64d = new Base64decoder ();
byte[] re = null;
try {
The agreed-upon content is base64decoder encoded, so the decoding is done here first.
Re = B64d.decodebuffer (new String (XMLSTR));
StringReader sr = new StringReader (new String (Re, "UTF-8"));
Saxreader Saxxmlreader = new Saxreader ();
Document d = saxxmlreader.read (new InputSource (SR));
Element root = D.getrootelement ();
list<element> nodeelements = root.elements ("note");
if (Nodeelements.size () >0) {
for (int i=0;i<nodeelements.size (); i++) {
Element e = Nodeelements.get (i);
String Staccount = E.elementtext ("account");
Here to do the relevant logical processing
}
}
catch (Exception e) {
Logger.error ("error message" +e.getmessage ());
}
Return Genericanswerxml ("1");
}
Private byte[] Genericanswerxml (String code) {
String XML = "<root><code>" +code+ "</code></root>";
Base64encoder b64e = new Base64encoder ();
byte[] Xmlencode = null;
try {
Base64decoder encoding when returning (BASE64 encoding when the Convention interacts)
Xmlencode = B64e.encodebuffer (Xml.getbytes ("UTF-8")). GetBytes ("UTF-8");
catch (Unsupportedencodingexception e) {
Logger.error ("WebService interface construct successfully returned identity when BASE64 encoding failed.") Error message: "+e.getmessage ());
}
return xmlencode;
} *
3. Configuration of spring configuration file Application*.xml
<bean id= "SMSService" class= "Cn.ltang.cm.webservice.SmsService" >
<!--service type--> to be injected
<property name= "Ecpinfomanager" ref= "Ecpinfomanager"/>
<property name= "Smsrecordmanager" ref= "Smsrecordmanager"/>
</bean>
4. Web.xml Configuration <!--add Spring listener-->
< listener >
< Listener-class >
Org.springframework.web.context.ContextLoaderListener
</Listener-class >
</Listener >
<!--load Spring's configuration file-->
< Context-param >
< Param-name > contextconfiglocation </param-name >
< Param-value > Classpath:applicationcontext*.xml </param-value >
</Context-param >
<!--register the Axis2 servlet-->
<servlet>
<servlet-name>AxisServlet</servlet-name>
<servlet-class>
Org.apache.axis2.transport.http.AxisServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>AxisServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
5, in the web-inf\services\axis\meta-inf\ directory to configure Services.xml (do not exist to create their own)
<?xml version= "1.0" encoding= "UTF-8"?>
<serviceGroup>
<service name= "SMSService" >
<!--<parameter name= "ServiceClass" >cn.ltang.cm.webservice.SmsService</parameter>-->
<parameter name= "Serviceobjectsupplier" locked= "false" > Org.apache.axis2.extensions.spring.receivers.springservletcontextobjectsupplier</parameter>
<parameter name= "Springbeanname" locked= "false" >smsService</parameter>
<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>
</service>
</serviceGroup>
Finally, test, release. Browser access to http://localhost:8080/project name/services/smsservice?wsdl see if WebServices published successfully