Asynchronous invoke web serivce by AXIS2
Hi guys:
Recently, I test asynchronous web service with axis2,the service has been deployed as a asynchronous service and the client do a non-blocking invoke.client code shows below
Options options = new Options();
options.setTo(targetEPR);
options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
options.setUseSeparateListener(true);
options.setAction("urn:test");
ConfigurationContext configurationContext =
ConfigurationContextFactory.createConfigurationContextFromFileSystem(
"E:\\axis2-1.4\\repository", "E:\\axis2-1.4\\conf\\axis2.xml");
//Non-Blocking Invocation
AxisService service= new AxisService("AsynchService");
service.addOperation(createOperation());
ServiceClient sender = new ServiceClient(configurationContext,service);
sender.setOptions(options);
sender.engageModule("addressing");
sender.sendReceiveNonBlocking(new QName("http://asych.neo.net", "test"),payload, callBack);
the first invoke is ok,after that I send two consecutive non-blocking invokings,get the error message below
[WARN] Attempt number 1 of 10 to reestalish connection listener org.apache.axis2.transport.http.server.DefaultConnectionListener@10849bc due to failure
java.net.BindException: Address already in use: JVM_Bind
at java.net.PlainSocketImpl.socketBind(Native Method)
at java.net.PlainSocketImpl.bind(Unknown Source)
at java.net.ServerSocket.bind(Unknown Source)
at java.net.ServerSocket.(Unknown Source)
at java.net.ServerSocket.(Unknown Source)
at org.apache.axis2.transport.http.server.DefaultConnectionListener.run(DefaultConnectionListener.java:72)
at edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:665)
at edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:690)
at java.lang.Thread.run(Unknown Source)
So, is there anyboby can help me? thanks in advance!
Neo
- Login or register to post comments
- Printer friendly version
- 938 reads











Change the port using the axis2.xml
When your using a separate Listener to invoke a service in a async manner the client starts a separate server (Simple HTTP Server) to listen to the response. So In this case it looks like your server is running on 6060 (The default port the simple HTTP server uses). So you will either have to change the port that the server or clients run. You can do this by editing your axis2.xml.
Thanks,
Keith.
http://www.keith-chapman.org
Maybe tow same listeners running
Hi keith,thanks for your quick reley,I do not try your approach,because my app use 8080,I think maybe just because two same listeners running,the 2nd request has been sent when the 1st does not close(waiting the response because it is async),it should cause the error? could you please explain the axis2 how to creat the two listener? thanks a lot!
Change the source code
How about changing the source code(org.apache.axis2.transport.http.server.SimpleHttpServer.java)
public SimpleHttpServer(HttpFactory httpFactory, int port) throws IOException {
this.httpFactory = httpFactory;
this.port = Util.getAvaliblePort(port);//add my code at here
this.workerFactory = httpFactory.newRequestWorkerFactory();
this.params = httpFactory.newRequestConnectionParams();
this.params.setIntParameter(AxisParams.LISTENER_PORT, port);
}
the listener does not close
After I tested the async invoking, I found that the listenner which monitor the callback does not close after receive the response.
the condition is we do not use System.exit(0),after reading the code regarding org.apache.axis2.transport.http.SimpleHttpServer.there is a line of code shows below
Runtime.getRuntime().addShutdownHook(new ShutdownThread(receiver));
so if the user does not exit,the listener should not be closed.
Through our testing it costs 20M memory per simpleHttpServer,if axis2 engine always does not close the listernes,the application server will OOM soon or later.
So I think this is a bug.
Our solution
Once we create the stub instance,
add the code below
ConfigurationContext configurationContext=ConfigurationContextFactory.createConfigurationContextFromFileSystem("C:\\axis2-1.3\\repository","C:\\axis2-1.3\\conf\\axis2.xml");
AxisAsynStub stub = new AxisAsynStub(configurationContext);
int availablePort=getAvailablePort();//get a available port
TransportListener listener=new SimpleHTTPServer(configurationContext,avalibePort);
stub._getServiceClient().getOptions().setListener(listener);
stub._getServiceClient().engageModule("addressing");
stub._getServiceClient().getOptions().setUseSeparateListener(true);
.....//invoke web service at here
listener.destroy();//destroy it after recerive the response