axis2嵌入至webapp中的方案(axis2版本号:1.4)
1、
WEB-INF
-- services
-- BookService (服务)
-- META-INF
-- services.xml
2、web.xml
<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>
3、demo:
public class BookServiceHelper {
private static BookServiceHelper helper = new BookServiceHelper();
private static final String NS_URI = "http://ws.b2b.com/imagedispose/services/BookService";
public static void main(String[] args) {
try{
/** 同步 */
helper.testNewOperation();
/** 异步 */
helper.testStartNewOperation();
}catch(Exception e){
e.printStackTrace();
}
}
/**
* Auto generated test method
*/
public void testNewOperation() throws java.lang.Exception {
com.hc360.b2b.ws.bookservice.BookServiceStub stub = new com.hc360.b2b.ws.bookservice.BookServiceStub(NS_URI);
BookServiceRequest param18 = (BookServiceRequest)getTestObject(BookServiceRequest.class);
param18.setName("sync");
param18.setId(93);
BookServiceResponse res = stub.SendMessage(param18);
String msg = res.getMsg();
System.out.println(msg + ", boolean: " + res.getValid());
}
/**
* Auto generated test method
*/
public void testStartNewOperation() throws java.lang.Exception {
com.hc360.b2b.ws.bookservice.BookServiceStub stub = new com.hc360.b2b.ws.bookservice.BookServiceStub(NS_URI);
BookServiceRequest param18 = (BookServiceRequest) getTestObject(BookServiceRequest.class);
param18.setName("asyc");
param18.setId(3);
// todo Fill in the param18 here
BookServiceCallbackHandler call = new tempCallbackN65547();
stub.startSendMessage(param18, call);
int i = 0;
while(!call.isComplete() && !call.isTimeOut()){
i++;
System.out.println("loop: " + i);
Thread.sleep(1000);
}
System.out.println("asynchronism!");
}
//Create an ADBBean and provide it as the test object
public org.apache.axis2.databinding.ADBBean getTestObject(
java.lang.Class type) throws Exception {
return (org.apache.axis2.databinding.ADBBean) type.newInstance();
}
private class tempCallbackN65547
extends com.hc360.b2b.ws.bookservice.BookServiceCallbackHandler {
public tempCallbackN65547() {
super(null);
}
public void receiveResultSendMessage(
BookServiceResponse param13) {
System.out.println("receiveResultNewOperation11");
System.out.println("call back result: " + param13.getMsg());
System.out.println("receiveResultNewOperation22");
this.setComplete(true);
}
public void receiveErrorNewOperation(java.lang.Exception e) {
System.out.println("call back error!");
}
}
}
1、
WEB-INF
-- services
-- BookService (服务)
-- META-INF
-- services.xml
2、web.xml
<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>
3、demo:
public class BookServiceHelper {
private static BookServiceHelper helper = new BookServiceHelper();
private static final String NS_URI = "http://ws.b2b.com/imagedispose/services/BookService";
public static void main(String[] args) {
try{
/** 同步 */
helper.testNewOperation();
/** 异步 */
helper.testStartNewOperation();
}catch(Exception e){
e.printStackTrace();
}
}
/**
* Auto generated test method
*/
public void testNewOperation() throws java.lang.Exception {
com.hc360.b2b.ws.bookservice.BookServiceStub stub = new com.hc360.b2b.ws.bookservice.BookServiceStub(NS_URI);
BookServiceRequest param18 = (BookServiceRequest)getTestObject(BookServiceRequest.class);
param18.setName("sync");
param18.setId(93);
BookServiceResponse res = stub.SendMessage(param18);
String msg = res.getMsg();
System.out.println(msg + ", boolean: " + res.getValid());
}
/**
* Auto generated test method
*/
public void testStartNewOperation() throws java.lang.Exception {
com.hc360.b2b.ws.bookservice.BookServiceStub stub = new com.hc360.b2b.ws.bookservice.BookServiceStub(NS_URI);
BookServiceRequest param18 = (BookServiceRequest) getTestObject(BookServiceRequest.class);
param18.setName("asyc");
param18.setId(3);
// todo Fill in the param18 here
BookServiceCallbackHandler call = new tempCallbackN65547();
stub.startSendMessage(param18, call);
int i = 0;
while(!call.isComplete() && !call.isTimeOut()){
i++;
System.out.println("loop: " + i);
Thread.sleep(1000);
}
System.out.println("asynchronism!");
}
//Create an ADBBean and provide it as the test object
public org.apache.axis2.databinding.ADBBean getTestObject(
java.lang.Class type) throws Exception {
return (org.apache.axis2.databinding.ADBBean) type.newInstance();
}
private class tempCallbackN65547
extends com.hc360.b2b.ws.bookservice.BookServiceCallbackHandler {
public tempCallbackN65547() {
super(null);
}
public void receiveResultSendMessage(
BookServiceResponse param13) {
System.out.println("receiveResultNewOperation11");
System.out.println("call back result: " + param13.getMsg());
System.out.println("receiveResultNewOperation22");
this.setComplete(true);
}
public void receiveErrorNewOperation(java.lang.Exception e) {
System.out.println("call back error!");
}
}
}