Why do you cast Future<?> .get() ? You cast it in enthuware.ocejws.v6.2.277 as well. In the explanation you argue against it:
"Client code should not attempt to cast the object to any particular type as this will result in non-portable behavior."
The Dispatch API is even more restrictive:
"This object MUST NOT be used to try to obtain the results of the operation"
https://docs.oracle.com/javaee/6/api/ja ... ncHandler)
How to get back the response from a callback? Do we really need it outside of it?
I think we don't. All the response handling should be done in the callback method.
Future<?> should be used only for polling scenarios.
About Question enthuware.ocejws.v6.2.278 :
Moderators: Site Manager, fjwalraven
-
- Posts: 28
- Joined: Fri Jan 02, 2015 12:13 pm
- Contact:
-
- Posts: 429
- Joined: Tue Jul 24, 2012 2:43 am
- Contact:
Re: About Question enthuware.ocejws.v6.2.278 :
You are absolutely right!
The JAX-WS User guide shows the correct way of dealing with the response (via the Handler):
https://jax-ws.java.net/2.2.1/docs/asynch.html
I will change the question accordingly.
Thank you for your feedback!
Regards,
Frits
The JAX-WS User guide shows the correct way of dealing with the response (via the Handler):
https://jax-ws.java.net/2.2.1/docs/asynch.html
Code: Select all
1.2 Async Callback
//async callback Method
public Future<?> addNumbers(int number1, int number2, AsyncHandler<AddNumbersResponse>);
Here the client application provides an AsyncHandler by implementing the javax.xml.ws.AsyncHandler<T> interface.
/**
*
* Async callback handler
*/
class AddNumbersCallbackHandler implements AsyncHandler<AddNumbersResponse> {
private AddNumbersResponse output;
/*
*
* @see javax.xml.ws.AsyncHandler#handleResponse(javax.xml.ws.Response)
*/
public void handleResponse(Response<AddNumbersResponse> response) {
try {
output = response.get();
} catch (ExecutionException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
AddNumbersResponse getResponse(){
return output;
}
}
The async handler is then passed as the last parameter of the async callback method:
//instantiates the callback handler
AddNumbersCallbackHandler callbackHandler = new AddNumbersCallbackHandler();
//invoke the async callback method
Future<?> resp = port.addNumbersAsync(number1, number2, callbackHandler);
while(!resp.isDone()){
//do something
}
System.out.println("The sum is: " + callbackHandler.getResponse().getReturn());
Thank you for your feedback!
Regards,
Frits
Who is online
Users browsing this forum: Bing [Bot] and 6 guests