You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Hervé BARRAULT <he...@gmail.com> on 2012/01/26 12:58:16 UTC
Asynchronous Invocation
Hi,
i'm doing some tesst with the asynchronous Invocation of methods.
My test is to send a message to an unknown hosts (15.21.23.36).
I have used the following test :
final JaxWsProxyFactoryBean proxyFactory = new JaxWsProxyFactoryBean();
proxyFactory.setAddress("http://15.21.23.36:9999/test");
proxyFactory.setServiceClass(MyPortType.class);
final MyPortType port = (MyPortType) proxyFactory.create();
final ... request = ...
try {
final Response<Ack> response = port.myMethodAsync(request);
System.out.println("Call sent");
final GetInformationAck ack = response.get(10L, TimeUnit.SECONDS);
System.out.println("Response received");
} catch(Exception e) {
System.out.println("Call failed " + e.getMessage());
}
I have the following trace :
---
Warning: Interceptor for ... has thrown exception, unwinding now
org.apache.cxf.interceptor.Fault: Could not send Message.
Caused by: java.net.ConnectException: ConnectException invoking
http://15.21.23.36:9999/test: Connection timed out: connect
Caused by: java.net.ConnectException: Connection timed out: connect
Call sent
Call failed org.apache.cxf.interceptor.Fault: Could not send Message.
---
I was expecting the same thing without the "Call sent" the connection
Exception sent by the method call.
Is there a way to have this behavior ?
I would only ensure that the message is sent (not yet processed by the
server) when calling my method, after i can wait the answer.
When is returned the Response<T> (after some checks ?) ?
Thanks for answers.
Regards
Hervé
Re: Asynchronous Invocation
Posted by Daniel Kulp <dk...@apache.org>.
> I was expecting the same thing without the "Call sent" the connection
> Exception sent by the method call.
>
>
> Is there a way to have this behavior ?
> I would only ensure that the message is sent (not yet processed by the
> server) when calling my method, after i can wait the answer.
>
> When is returned the Response<T> (after some checks ?) ?
This is all per JAX-WS spec. The Response is returned after the outgoing
chain has completed. Thus, when you have the Response, it's in one of three
states:
1) the message has been sucessfully sent and the Response object is waiting
for a response. response.isDone() will return false;
2) The Response object is marked "done", but is holding an exception caused by
a connection issue or timeout or similar. isDone() returns true, a call to
get() will throw the exception.
3) the message has been sucessfully sent and the Response object already has a
response. (due to threading, the response may already have come back on a
different thread prior to the main thread returning.) In this case, isDone()
returns true and get() returns the object.
Thus, for you , you could likely do:
try {
final Response<Ack> response = port.myMethodAsync(request);
if (response.isDone()) {
response.get();
}
System.out.println("Call sent");
final GetInformationAck ack = response.get(10L, TimeUnit.SECONDS);
System.out.println("Response received");
} catch(Exception e) {
System.out.println("Call failed " + e.getMessage());
}
Dan
On Thursday, January 26, 2012 12:58:16 PM Hervé BARRAULT wrote:
> Hi,
> i'm doing some tesst with the asynchronous Invocation of methods.
>
> My test is to send a message to an unknown hosts (15.21.23.36).
>
> I have used the following test :
>
> final JaxWsProxyFactoryBean proxyFactory = new JaxWsProxyFactoryBean();
> proxyFactory.setAddress("http://15.21.23.36:9999/test");
> proxyFactory.setServiceClass(MyPortType.class);
> final MyPortType port = (MyPortType) proxyFactory.create();
>
> final ... request = ...
>
> try {
> final Response<Ack> response = port.myMethodAsync(request);
> System.out.println("Call sent");
> final GetInformationAck ack = response.get(10L, TimeUnit.SECONDS);
> System.out.println("Response received");
> } catch(Exception e) {
> System.out.println("Call failed " + e.getMessage());
> }
>
> I have the following trace :
> ---
> Warning: Interceptor for ... has thrown exception, unwinding now
> org.apache.cxf.interceptor.Fault: Could not send Message.
> Caused by: java.net.ConnectException: ConnectException invoking
> http://15.21.23.36:9999/test: Connection timed out: connect
> Caused by: java.net.ConnectException: Connection timed out: connect
>
> Call sent
> Call failed org.apache.cxf.interceptor.Fault: Could not send Message.
> ---
>
> I was expecting the same thing without the "Call sent" the connection
> Exception sent by the method call.
>
>
> Is there a way to have this behavior ?
> I would only ensure that the message is sent (not yet processed by the
> server) when calling my method, after i can wait the answer.
>
> When is returned the Response<T> (after some checks ?) ?
>
> Thanks for answers.
> Regards
> Hervé
--
Daniel Kulp
dkulp@apache.org - http://dankulp.com/blog
Talend Community Coder - http://coders.talend.com