cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From André Costa Lima <andreclima...@gmail.com>
Subject Re: Async Calls
Date Thu, 08 Jan 2015 13:02:28 GMT
The asynchronous implementation is only called if you annotate your
synchronous method with @UseAsyncMethod in the implementation. Do not use
it in the interface. There is an example here
<http://cxf.apache.org/docs/annotations.html#Annotations-org.apache.cxf.annotations.UseAsyncMethod%28since2.6.0%29>
.

You can generate the wsdl with java2ws
<http://cxf.apache.org/docs/java-to-ws.html> or generate the SEI from a
wsdl with wsdl2java <http://cxf.apache.org/docs/wsdl-to-java.html>.

Take a look at the samples that are distributed with CXF. There is at least
one example for your use case.


André Costa Lima


2015-01-08 12:10 GMT+00:00 gido <gido@uninova.pt>:

> Hi Daniel,
>
>
>
> I have also spoken with André Costa Lima (via CXF). I can send you some
> other info.
>
> This is the code that I am going to test:
>
>
>
> @WebService
>
> @SOAPBinding(style = SOAPBinding.Style.DOCUMENT)
>
>  public interface IProsecoService {
>      @WebMethod(operationName = "startWebService")
>
>      public void start();
>
>      @WebMethod(operationName = "stopWebService")
>        public void stop();
>
>
>
>      @WebMethod(operationName = "restartWebService")
>       public void restart();
>
>
>
>      @WebMethod(operationName = "pingWebService")
>       public String ping();
>
>
>
>      @WebMethod(operationName = "invokeWebService")
>      public boolean configure(String Configuration);
>
>
>
> }
>
>
>
>  @WebService(name = "AmIMonitoringService", targetNamespace = "
> <http://proseco-project.eu/> http://proseco-project.eu/")
>
>  @SOAPBinding(style = SOAPBinding.Style.DOCUMENT)
>
>  public interface IAmIMonitoringService extends IProsecoService {
>
>
>
>    @UseAsyncMethod
>     public String Myping(String par);
>
>
>
>     public Future<?> MypingAsync(String par, AsyncHandler<MypingResponse>
> asyncHandler);
>
>
>
>     public Response<MypingResponse> MypingAsync(String par);
> }
>
>
>
>
>
> public class AmIMonitoringService implements IAmIMonitoringService {
>
>
>
>     private static final Logger logger =
> LoggerFactory.getLogger(AmIMonitoringService.class);
>
>
>
>     @Override
>
>     public void start() throws ProsecoFault {
>
>         logger.info(String.format("Starting %s ...",
> this.getClass().getSimpleName()));
>
>     }
>
>
>
>     @Override
>
>     public void stop() throws ProsecoFault {
>
>         logger.info(String.format("Stopping %s ...",
> this.getClass().getSimpleName()));
>
>     }
>
>
>
>     @Override
>
>     public void restart() throws ProsecoFault {
>
>         logger.info(String.format("Restarting %s ...",
> this.getClass().getSimpleName()));
>
>     }
>
>
>
>     @Override
>
>     public String ping() throws ProsecoFault {
>
>         logger.info(String.format("%s was pinged",
> this.getClass().getSimpleName()));
>
>                         return ServiceManager.PING_RESPONSE;
>
>     }
>
>
>
>     @Override
>
>     public boolean configure(String Configuration) throws ProsecoFault {
>
>         throw new UnsupportedOperationException("Not supported yet."); //To
> change body of generated methods, choose Tools | Templates.
>
>     }
>
>
>
>     @Override
>
>     public Future<?> MypingAsync(final String par, final
> AsyncHandler<MypingResponse> asyncHandler) {
>
>         System.out.println("Executing operation changeStudentAsync
> asynchronously\n");
>
>         final ServerAsyncResponse<MypingResponse> asyncResponse = new
> ServerAsyncResponse<MypingResponse>();
>
>         new Thread() {
>
>             @Override
>
>             public void run() {
>
>                 try {
>
>                     Thread.sleep(10000);
>
>                 } catch (InterruptedException e) {
>
>                 }
>
>                 MypingResponse resp = new MypingResponse();
>
>                 resp.setTestValue("Ola " + par);
>
>                 asyncResponse.set(resp);
>
>                 System.out.println("Responding on background thread\n");
>
>                 asyncHandler.handleResponse(asyncResponse);
>
>             }
>
>         }.start();
>
>
>
>         return asyncResponse;
>
>     }
>
>
>
>     @Override
>
>     public String Myping(String par) {
>
>         System.out.println("Synchrounous call");
>
>         return null;
>
>     }
>
>
>
>     @Override
>
>     public Response<MypingResponse> MypingAsync(String par) {
>
>         return null;
>
>     }
>
>
>
> }
>
>
>
> -          Client code:
>
>  IAmIMonitoringService client = ServiceManager.getWebservice("localhost",
> Integer.parseInt("19004"), IAmIMonitoringService.class);
>          String pong = client.ping();
>          TestAsyncHandler handler = new TestAsyncHandler();
>          Future<?> response = client.MypingAsync("Giovanni", handler);
>           while (!response.isDone()) {
>              Thread.sleep(100);
>          }
>
>
>
> public class TestAsyncHandler implements AsyncHandler<MypingResponse> {
>      private MypingResponse reply;
>      @Override
>      public void handleResponse(Response<MypingResponse> rspns) {
>          try {
>              System.err.println("handleResponse called");
>              reply = rspns.get();
>          } catch (InterruptedException | ExecutionException ex) {
>
> Logger.getLogger(TestAsyncHandler.class.getName()).log(Level.SEVERE, null,
> ex);
>         }
>    }
>    public String getResponse() {
>          return reply.getTestValue();
>     }
> }
>
>
>
>
> The exception that I have when running the following code is:
>
>
>
>
>
> SEVERE: null
> java.util.concurrent.ExecutionException: java.lang.ClassCastException:
> pt.uninova.proseco.services.jaxws_asm.MypingWebServiceResponse cannot be
> cast to pt.uninova.proseco.services.async.response.MypingMessage
>                at
> org.apache.cxf.jaxws.JaxwsClientCallback$2.get(JaxwsClientCallback.java:99)
>                 at
>
> pt.uninova.proseco.services.async.TestAsyncHandler.handleResponse(TestAsyncH
> andler.java:27)
>                 at
>
> org.apache.cxf.jaxws.JaxwsClientCallback.handleException(JaxwsClientCallback
> .java:87)
>                 at
> org.apache.cxf.endpoint.ClientImpl.onMessage(ClientImpl.java:821)
>                 at
>
> org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponse
> Internal(HTTPConduit.java:1636)
>                 at
>
> org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream$1.run(HTTPCond
> uit.java:1145)
>                 at
>
> org.apache.cxf.workqueue.AutomaticWorkQueueImpl$3.run(AutomaticWorkQueueImpl
> .java:428)
>                 at
>
> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:11
> 45)
>                 at
>
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:6
> 15)
>                 at
>
> org.apache.cxf.workqueue.AutomaticWorkQueueImpl$AWQThreadFactory$1.run(Autom
> aticWorkQueueImpl.java:353)
>                 at java.lang.Thread.run(Thread.java:744)
> Caused by: java.lang.ClassCastException:
> pt.uninova.proseco.services.jaxws_asm.MypingWebServiceResponse cannot be
> cast to pt.uninova.proseco.services.async.response.MypingMessage
>                 at
>
> pt.uninova.proseco.services.async.TestAsyncHandler.handleResponse(TestAsyncH
> andler.java:27)
>                 at
>
> org.apache.cxf.jaxws.JaxwsClientCallback.handleResponse(JaxwsClientCallback.
> java:44)
>                 at
> org.apache.cxf.endpoint.ClientImpl.onMessage(ClientImpl.java:819)
>                ... 7 more
> Exception in thread "main" java.lang.NullPointerException
>                 at
>
> pt.uninova.proseco.services.async.TestAsyncHandler.getResponse(TestAsyncHand
> ler.java:34)
>                 at
>
> pt.uninova.proseco.async.AsyncTestMainClass.main(AsyncTestMainClass.java:51)
>
>
>
>
>
> Basically I have a cast exception here:
> public class TestAsyncHandler implements AsyncHandler<MypingResponse> {
>     private MypingResponse reply;
>      @Override
>      public void handleResponse(Response<MypingResponse> rspns) {
>          try {
>
>             System.err.println("handleResponse called");
>             reply = rspns.get();
>          } catch (InterruptedException | ExecutionException ex) {
> Logger.getLogger(TestAsyncHandler.class.getName()).log(Level.SEVERE, null,
> ex);
>          }
>
>      }
>     public String getResponse() {
>
>          return reply.getTestValue();
>
>      }
>  }
>
>
>
> I am using the simplefrontend and the jetty embedded application server for
> that reason I don’t have the wsdl since it is automatically generated from
> the java code and handled by the environment (I think). Is there any way to
> retrieve the wsdl?
>
>
>
> BR,
>
>
>
> Giovanni
>
>
>
> De: Daniel Kulp [via CXF] [mailto:ml-node+s547215n5752856h18@n5.nabble.com
> ]
> Enviada: 7 de janeiro de 2015 22:32
> Para: gido
> Assunto: Re: Async Calls
>
>
>
>
> My suggestion would be to take the generated wsdl from the service and run
> the wsdl2java with the -asyncMethods switch on the wsdl and make sure you
> either use the generated SEI directly or at least make sure the method
> signatures and such directly match what is there.
>
> Dan
>
>
>
>
> > On Jan 6, 2015, at 6:41 PM, gido <[hidden email]> wrote:
> >
> > Dear all,
> >
> > I have a little problem with the async communication. In particular I am
> > trying to implement async calls. My idea is to provide a synchronous
> method
> > as well as its async implementation. In such a way I can decide which
> method
> > is suitable for me according to the specific application context. To do
> > that, I have followed the Apache CXF documentation and the tutorials:
> >
> > http://www.javatips.net/blog/2014/03/asynchronous-web-service-using-cxf
> > http://www.javatips.net/blog/2014/03/cxf-asynchronous-client
> >
> > However when I try to call the async method I always receive the
> following
>
> > exception:
> >
> > Exception in thread "main" javax.xml.ws.WebServiceException: Could not
> find
> > wsdl:binding operation info for web method testAsync.
> > at
> org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:126)
>
> > at com.sun.proxy.$Proxy62.testAsync(Unknown Source)
> > at
> >
>
> pt.uninova.proseco.async.AsyncTestMainClass.main(AsyncTestMainClass.java:46)
>
> >
> > If I try to call the synch implmentation I have no problem.
> >
> > I have checked the generated wsdl (I am using the Java first approach)
> and
> I
> > see that no async operation is included.
> >
> > Do you have any sugestion?
> >
> > BR
> >
> > Giovanni
> >
> >
> >
> > --
> > View this message in context:
> http://cxf.547215.n5.nabble.com/Async-Calls-tp5752830.html
> > Sent from the cxf-user mailing list archive at Nabble.com.
>
>
> --
> Daniel Kulp
> [hidden email] - http://dankulp.com/blog
> Talend Community Coder - http://coders.talend.com
>
>
>
>
>   _____
>
> If you reply to this email, your message will be added to the discussion
> below:
>
> http://cxf.547215.n5.nabble.com/Async-Calls-tp5752830p5752856.html
>
> To unsubscribe from Async Calls, click here
> <
> http://cxf.547215.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_
> by_code&node=5752830&code=Z2lkb0B1bmlub3ZhLnB0fDU3NTI4MzB8LTQwODEwNTMyNQ==
> <http://cxf.547215.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=5752830&code=Z2lkb0B1bmlub3ZhLnB0fDU3NTI4MzB8LTQwODEwNTMyNQ==>
> >
> .
>
> <
> http://cxf.547215.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer
>
> &id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicName
>
> space-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.Node
>
> Namespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_email
> s%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml
> <http://cxf.547215.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>>
> NAML
>
>
>
>
>
> --
> View this message in context:
> http://cxf.547215.n5.nabble.com/Async-Calls-tp5752830p5752862.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message