WEB开发网
开发学院软件开发Java 关于在weblogic中异步调用webservice 阅读

关于在weblogic中异步调用webservice

 2009-09-22 00:00:00 来源:WEB开发网   
核心提示: //listener1AsyncInfoasyncInfo=newAsyncInfo();2asyncInfo.setResultListener(newResultListener(){3publicvoidonCompletion(InvokeCompletedEventevent){4Si

//listener

 1 AsyncInfo asyncInfo = new AsyncInfo();
 2 asyncInfo.setResultListener( new ResultListener(){
 3     public void onCompletion( InvokeCompletedEvent event ){
 4         SimpleTestSoap source = (SimpleTestSoap)event.getSource();
 5         try{
 6             String result = source.endEchoString ( event.getFutureResult() );
 7         } catch ( RemoteException e ){
 8             e.printStackTrace ( System.out );
 9         }
10     }
11 });
12 echoPort.startEchoString( "94501", asyncInfo );

现在回头看看开篇的问题,客户端线程退出时,如果服务器端还没有处理完,请求结果会怎么办?是否会保存下来?如果这样的客户端很多,服务器内存开销岂不是很大?

要解释这个问题,我们先来看看这种调用方式的流程。对于服务器而言,异步、同步调用是一样的,它只负责接收、处理请求,web service的处理,在服务器端是由weblogic.webservice. server.servlet. WebServiceServlet .serverSideInvoke(WebService webservice, Binding binding, HttpServletRequest request, HttpServletResponse response)。同步、异步的处理完全是在客户端完成的,下面就看看客户端的调用流程。

FutureResult result = port.startSayHello(3, "test", null); 
//it's a JAX-RPC stub, and it extends StubImpl.java
====>
weblogic.webservice.core.rpc.StubImpl._startAsyncInvoke( String method, Map args, AsyncInfo wsAsyncContext )
//in this method, Operation is retrieved from Port
====>
weblogic.webservice.core.DefaultOperation.asyncInvoke( Map outParams, Object[] args, AsyncInfo wsContext, PrintStream logStream )
//a ClientDispatcher is created here and then we dispatch our requst with this dispatcher
====>
weblogic.webservice.core.ClientDispatcher.asyncDispatch(final Object[] args, final AsyncInfo async)
//in this method, FutureResultImpl is created and it will be returned to client. It's responsible to send message and 
//receive response from server in another. For receiving response, it's will be discussed later.
====>
weblogic.webservice.core.ClientDispatcher.send(Object[] args)
//MessageContext is set(for example, BindInfo is set) here and the request will be handle by a handler chain. 
====>
weblogic.webservice.core.handler.ClientHandler.handleRequest(MessageContext ctx)
//it check bind info and the delegate the request to binding
====>
weblogic.webservice.binding.http11.Http11ClientBinding.send(MessageContext ctx)
//it retrieve endpoint from bindinfo and then open a HttpURLConnection with the URL created basing on endpoint. 
//Reqeust is sent to server with this HttpURLConnection.
1 connection = (HttpURLConnection)url.openConnection();
2 
3 outputStream = connection.getOutputStream();
4 request.writeTo( outputStream );

上一页  1 2 3 4 5  下一页

Tags:关于 weblogic 异步

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接