You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Kent Närling <ke...@seamless.se> on 2011/08/17 10:23:26 UTC

Making async interfaces manually with annotations etc?

Hi!

We declare our SOAP interfaces in java and then build the WSDL:s from the
java code since 99% of our clients are in java and to make it most
convenient for them we have decided to follow this path.

eg we might have a sample service declared like:

@WebService

public interface MyService

{

@WebMethod(operationName = "doSomething")

DoSomethingResult doSomething(

 @WebParam(name = "someParam") String someParam);

}


Now, we could like to be able to call this using the async way with
callbacks, is there some way we can declare this manually with annotations?
(ie without generating the code from wsdl)

And would it then be possible to JUST declare the callback variations, since
we know we won't use the polling approach etc?

Thanks
/Kent

Re: Making async interfaces manually with annotations etc?

Posted by Kent Närling <ke...@seamless.se>.
Ok, I was considering that but all the samples I saw then depended on the
WSDL:s which we dont want.


But it seems you are saying that once I generated the wsdl:s and then
back-generated the code (to get it correct) I should be able to discard the
wsdl:s if we want and depend only on the code declarations?

Will try this and see how it goes and maybe decrypt the async "magic" a bit
;-)

Thanks!


On 26 August 2011 17:15, Daniel Kulp <dk...@apache.org> wrote:

>
>
> Creating the async methods can be tricky as the request object gets
> unwrapped,
> the the wrapper object is used for the callback.
>
> My suggestion is to create your service, grab the wsdl, and generate a
> client
> with it enabling the async methods.  (with 2.4.2, you can pass
> -asyncMethods
> flag).  Use that generated interface as the basis fro your async methods
> and
> such.
>
> Dan
>
>
> On Friday, August 26, 2011 9:25:35 AM Kent Närling wrote:
> > Now I did some small modifcations to my interfaces so I created a sample
> > service with a method declared like:
> > @WebMethod(operationName = "doAdd")
> > String doAdd(
> > @WebParam(name = "a") String a,
> > @WebParam(name = "b") String b);
> >
> > @WebMethod(operationName = "doAdd")
> > @WebEndpoint(name="doAdd")
> > Future<?> doAddAsync(
> > String a,
> > String b,
> > AsyncHandler<String> handler);
> >
> >
> > The server implements this (with an empty stub for the async call) and
> > publishes simply with:
> >
> > AdderService service = new AdderService();
> > Endpoint.publish("http://localhost:8989/adder", service);
> >
> > The client simply creates the interface connection with:
> > AdderInterface adder;
> >
> > JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
> > factory.setServiceClass(AdderInterface.class);
> > factory.setAddress("http://localhost:8989/adder");
> > adder = (AdderInterface)factory.create();
> >
> > Now, STILL, if I call the async method I get:
> > "javax.xml.ws.WebServiceException: Could not find wsdl:binding operation
> > info for web method doAddAsync."
> >
> > It seems to me that CXF thinks that the operation name on the server is
> > "doAddAsync" despite that I explictly named it as "doAdd" in the
> annotation?
> >
> > There should be a way to tell CXF through annotations that "for this
> method
> > stub X, call SOAP method Y on the server"?
> > Or am I missunderstanding what the problem is here?
> >
> > I have a full sample code of the above if anyone is interested I can send
> > it, I cannot get this to work and I am a bit stuck right now... :-(
> >
> > On 18 August 2011 00:48, Kent Närling <ke...@seamless.se> wrote:
> > > On 17 August 2011 23:21, Kent Närling <ke...@seamless.se>
> wrote:
> > >> On 17 August 2011 18:08, Daniel Kulp <dk...@apache.org> wrote:
> > >>> On Wednesday, August 17, 2011 4:17:58 PM Kent Närling wrote:
> > >>> > I tried ad-hoc and just wrote the interface myself as:
> > >>> >
> > >>> > @WebService
> > >>> >
> > >>> > public interface MyService
> > >>> >
> > >>> > {
> > >>> >
> > >>> > @WebMethod(operationName = "doSomething")
> > >>> >
> > >>> > Future<?> doSomething(
> > >>> >
> > >>> > @WebParam(name = "someParam") String someParam,
> > >>> > AsyncHandler<DoSomethingResult> asyncHandler);
> > >>> >
> > >>> > }
> > >>> > But with this I just god the error : "Could not find
> > >>> > wsdl:binding
> > >>>
> > >>> operation
> > >>>
> > >>> > info for web method doSomething"
> > >>> >
> > >>> > So I guess this means I would have to annotate some binding
> > >>>
> > >>> information? or
> > >>>
> > >>> > is this impossible to do with annotations?
> > >>>
> > >>> You ALWAYS have to have the non-async versions there.   Thus, put
> > >>> your
> > >>> original method signature in there.   You can then optionally add
> > >>> the
> > >>> async
> > >>> versions as needed and only for the methods you need.
> > >>>
> > >>> Dan
> > >>>
> > >>>
> > >>>
> > >>> Does this mean that the server side will have to implement the async
> > >>
> > >> version as well?
> > >> (would be a bit odd if the server has to implement the same method
> > >> twice?
> > >>
> > >> Since it has to implement the same interface then it has to implement
> > >> the async version...
> > >>
> > >> Also, can the method name & SOAP operation name be the same? or should
> > >> the methods have different names?
> > >>
> > >>
> > >> ie in the above you are saying that I  should declare an interface as:
> > >>
> > >> @WebService
> > >>
> > >> public interface MyService
> > >>
> > >> {
> > >>
> > >> @WebMethod(operationName = "doSomething")
> > >>
> > >> DoSomethingResult doSomething(
> > >>
> > >> @WebParam(name = "someParam") String someParam);
> > >>
> > >> @WebMethod(operationName = "doSomething")
> > >>
> > >> Future<?> doSomething(
> > >>
> > >> @WebParam(name = "someParam") String someParam,
> > >>
> > >> AsyncHandler<DoSomethingResult> handler);
> > >>
> > >> }
> > >>
> > >>
> > >> Or?
> > >
> > > I tried to declare it as above, still get the same error as before:
> > > "Could not find wsdl:binding operation info for web method doSomething"
> > >
> > > Do I have to
> --
> Daniel Kulp
> dkulp@apache.org
> http://dankulp.com/blog
> Talend - http://www.talend.com
>

Re: Making async interfaces manually with annotations etc?

Posted by Daniel Kulp <dk...@apache.org>.

Creating the async methods can be tricky as the request object gets unwrapped, 
the the wrapper object is used for the callback.   

My suggestion is to create your service, grab the wsdl, and generate a client 
with it enabling the async methods.  (with 2.4.2, you can pass -asyncMethods 
flag).  Use that generated interface as the basis fro your async methods and 
such.

Dan


On Friday, August 26, 2011 9:25:35 AM Kent Närling wrote:
> Now I did some small modifcations to my interfaces so I created a sample
> service with a method declared like:
> @WebMethod(operationName = "doAdd")
> String doAdd(
> @WebParam(name = "a") String a,
> @WebParam(name = "b") String b);
> 
> @WebMethod(operationName = "doAdd")
> @WebEndpoint(name="doAdd")
> Future<?> doAddAsync(
> String a,
> String b,
> AsyncHandler<String> handler);
> 
> 
> The server implements this (with an empty stub for the async call) and
> publishes simply with:
> 
> AdderService service = new AdderService();
> Endpoint.publish("http://localhost:8989/adder", service);
> 
> The client simply creates the interface connection with:
> AdderInterface adder;
> 
> JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
> factory.setServiceClass(AdderInterface.class);
> factory.setAddress("http://localhost:8989/adder");
> adder = (AdderInterface)factory.create();
> 
> Now, STILL, if I call the async method I get:
> "javax.xml.ws.WebServiceException: Could not find wsdl:binding operation
> info for web method doAddAsync."
> 
> It seems to me that CXF thinks that the operation name on the server is
> "doAddAsync" despite that I explictly named it as "doAdd" in the annotation?
> 
> There should be a way to tell CXF through annotations that "for this method
> stub X, call SOAP method Y on the server"?
> Or am I missunderstanding what the problem is here?
> 
> I have a full sample code of the above if anyone is interested I can send
> it, I cannot get this to work and I am a bit stuck right now... :-(
> 
> On 18 August 2011 00:48, Kent Närling <ke...@seamless.se> wrote:
> > On 17 August 2011 23:21, Kent Närling <ke...@seamless.se> wrote:
> >> On 17 August 2011 18:08, Daniel Kulp <dk...@apache.org> wrote:
> >>> On Wednesday, August 17, 2011 4:17:58 PM Kent Närling wrote:
> >>> > I tried ad-hoc and just wrote the interface myself as:
> >>> > 
> >>> > @WebService
> >>> > 
> >>> > public interface MyService
> >>> > 
> >>> > {
> >>> > 
> >>> > @WebMethod(operationName = "doSomething")
> >>> > 
> >>> > Future<?> doSomething(
> >>> > 
> >>> > @WebParam(name = "someParam") String someParam,
> >>> > AsyncHandler<DoSomethingResult> asyncHandler);
> >>> > 
> >>> > }
> >>> > But with this I just god the error : "Could not find
> >>> > wsdl:binding
> >>> 
> >>> operation
> >>> 
> >>> > info for web method doSomething"
> >>> > 
> >>> > So I guess this means I would have to annotate some binding
> >>> 
> >>> information? or
> >>> 
> >>> > is this impossible to do with annotations?
> >>> 
> >>> You ALWAYS have to have the non-async versions there.   Thus, put
> >>> your
> >>> original method signature in there.   You can then optionally add
> >>> the
> >>> async
> >>> versions as needed and only for the methods you need.
> >>> 
> >>> Dan
> >>> 
> >>> 
> >>> 
> >>> Does this mean that the server side will have to implement the async
> >> 
> >> version as well?
> >> (would be a bit odd if the server has to implement the same method
> >> twice?
> >> 
> >> Since it has to implement the same interface then it has to implement
> >> the async version...
> >> 
> >> Also, can the method name & SOAP operation name be the same? or should
> >> the methods have different names?
> >> 
> >> 
> >> ie in the above you are saying that I  should declare an interface as:
> >> 
> >> @WebService
> >> 
> >> public interface MyService
> >> 
> >> {
> >> 
> >> @WebMethod(operationName = "doSomething")
> >> 
> >> DoSomethingResult doSomething(
> >> 
> >> @WebParam(name = "someParam") String someParam);
> >> 
> >> @WebMethod(operationName = "doSomething")
> >> 
> >> Future<?> doSomething(
> >> 
> >> @WebParam(name = "someParam") String someParam,
> >> 
> >> AsyncHandler<DoSomethingResult> handler);
> >> 
> >> }
> >> 
> >> 
> >> Or?
> > 
> > I tried to declare it as above, still get the same error as before:
> > "Could not find wsdl:binding operation info for web method doSomething"
> > 
> > Do I have to
-- 
Daniel Kulp
dkulp@apache.org
http://dankulp.com/blog
Talend - http://www.talend.com

Re: Making async interfaces manually with annotations etc?

Posted by Kent Närling <ke...@seamless.se>.
Now I did some small modifcations to my interfaces so I created a sample
service with a method declared like:
@WebMethod(operationName = "doAdd")
String doAdd(
@WebParam(name = "a") String a,
@WebParam(name = "b") String b);

@WebMethod(operationName = "doAdd")
@WebEndpoint(name="doAdd")
Future<?> doAddAsync(
String a,
String b,
AsyncHandler<String> handler);


The server implements this (with an empty stub for the async call) and
publishes simply with:

AdderService service = new AdderService();
Endpoint.publish("http://localhost:8989/adder", service);

The client simply creates the interface connection with:
AdderInterface adder;

JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
factory.setServiceClass(AdderInterface.class);
factory.setAddress("http://localhost:8989/adder");
adder = (AdderInterface)factory.create();

Now, STILL, if I call the async method I get:
"javax.xml.ws.WebServiceException: Could not find wsdl:binding operation
info for web method doAddAsync."

It seems to me that CXF thinks that the operation name on the server is
"doAddAsync" despite that I explictly named it as "doAdd" in the annotation?

There should be a way to tell CXF through annotations that "for this method
stub X, call SOAP method Y on the server"?
Or am I missunderstanding what the problem is here?

I have a full sample code of the above if anyone is interested I can send
it, I cannot get this to work and I am a bit stuck right now... :-(


On 18 August 2011 00:48, Kent Närling <ke...@seamless.se> wrote:

>
>
> On 17 August 2011 23:21, Kent Närling <ke...@seamless.se> wrote:
>
>>
>> On 17 August 2011 18:08, Daniel Kulp <dk...@apache.org> wrote:
>>
>>> On Wednesday, August 17, 2011 4:17:58 PM Kent Närling wrote:
>>> > I tried ad-hoc and just wrote the interface myself as:
>>> >
>>> > @WebService
>>> >
>>> > public interface MyService
>>> >
>>> > {
>>> >
>>> > @WebMethod(operationName = "doSomething")
>>> >
>>> > Future<?> doSomething(
>>> >
>>> > @WebParam(name = "someParam") String someParam,
>>> > AsyncHandler<DoSomethingResult> asyncHandler);
>>> >
>>> > }
>>> > But with this I just god the error : "Could not find wsdl:binding
>>> operation
>>> > info for web method doSomething"
>>> >
>>> > So I guess this means I would have to annotate some binding
>>> information? or
>>> > is this impossible to do with annotations?
>>>
>>> You ALWAYS have to have the non-async versions there.   Thus, put your
>>> original method signature in there.   You can then optionally add the
>>> async
>>> versions as needed and only for the methods you need.
>>>
>>> Dan
>>>
>>>
>>>
>>> Does this mean that the server side will have to implement the async
>> version as well?
>> (would be a bit odd if the server has to implement the same method twice?
>>
>> Since it has to implement the same interface then it has to implement the
>> async version...
>>
>> Also, can the method name & SOAP operation name be the same? or should the
>> methods have different names?
>>
>>
>> ie in the above you are saying that I  should declare an interface as:
>>
>> @WebService
>>
>> public interface MyService
>>
>> {
>>
>> @WebMethod(operationName = "doSomething")
>>
>> DoSomethingResult doSomething(
>>
>> @WebParam(name = "someParam") String someParam);
>>
>> @WebMethod(operationName = "doSomething")
>>
>> Future<?> doSomething(
>>
>> @WebParam(name = "someParam") String someParam,
>>
>> AsyncHandler<DoSomethingResult> handler);
>>
>> }
>>
>>
>> Or?
>>
> I tried to declare it as above, still get the same error as before:
> "Could not find wsdl:binding operation info for web method doSomething"
>
> Do I have to
>

Re: Making async interfaces manually with annotations etc?

Posted by Kent Närling <ke...@seamless.se>.
On 17 August 2011 23:21, Kent Närling <ke...@seamless.se> wrote:

>
> On 17 August 2011 18:08, Daniel Kulp <dk...@apache.org> wrote:
>
>> On Wednesday, August 17, 2011 4:17:58 PM Kent Närling wrote:
>> > I tried ad-hoc and just wrote the interface myself as:
>> >
>> > @WebService
>> >
>> > public interface MyService
>> >
>> > {
>> >
>> > @WebMethod(operationName = "doSomething")
>> >
>> > Future<?> doSomething(
>> >
>> > @WebParam(name = "someParam") String someParam,
>> > AsyncHandler<DoSomethingResult> asyncHandler);
>> >
>> > }
>> > But with this I just god the error : "Could not find wsdl:binding
>> operation
>> > info for web method doSomething"
>> >
>> > So I guess this means I would have to annotate some binding information?
>> or
>> > is this impossible to do with annotations?
>>
>> You ALWAYS have to have the non-async versions there.   Thus, put your
>> original method signature in there.   You can then optionally add the
>> async
>> versions as needed and only for the methods you need.
>>
>> Dan
>>
>>
>>
>> Does this mean that the server side will have to implement the async
> version as well?
> (would be a bit odd if the server has to implement the same method twice?
>
> Since it has to implement the same interface then it has to implement the
> async version...
>
> Also, can the method name & SOAP operation name be the same? or should the
> methods have different names?
>
>
> ie in the above you are saying that I  should declare an interface as:
>
> @WebService
>
> public interface MyService
>
> {
>
> @WebMethod(operationName = "doSomething")
>
> DoSomethingResult doSomething(
>
> @WebParam(name = "someParam") String someParam);
>
> @WebMethod(operationName = "doSomething")
>
> Future<?> doSomething(
>
> @WebParam(name = "someParam") String someParam,
>
> AsyncHandler<DoSomethingResult> handler);
>
> }
>
>
> Or?
>
I tried to declare it as above, still get the same error as before:
"Could not find wsdl:binding operation info for web method doSomething"

Do I have to

Re: Making async interfaces manually with annotations etc?

Posted by Daniel Kulp <dk...@apache.org>.
On Wednesday, August 17, 2011 4:17:58 PM Kent Närling wrote:
> I tried ad-hoc and just wrote the interface myself as:
> 
> @WebService
> 
> public interface MyService
> 
> {
> 
> @WebMethod(operationName = "doSomething")
> 
> Future<?> doSomething(
> 
> @WebParam(name = "someParam") String someParam,
> AsyncHandler<DoSomethingResult> asyncHandler);
> 
> }
> But with this I just god the error : "Could not find wsdl:binding operation
> info for web method doSomething"
> 
> So I guess this means I would have to annotate some binding information? or
> is this impossible to do with annotations?

You ALWAYS have to have the non-async versions there.   Thus, put your 
original method signature in there.   You can then optionally add the async 
versions as needed and only for the methods you need.

Dan



> 
> On 17 August 2011 10:23, Kent Närling <ke...@seamless.se> wrote:
> > Hi!
> > 
> > We declare our SOAP interfaces in java and then build the WSDL:s from
> > the
> > java code since 99% of our clients are in java and to make it most
> > convenient for them we have decided to follow this path.
> > 
> > eg we might have a sample service declared like:
> > 
> > @WebService
> > 
> > public interface MyService
> > 
> > {
> > 
> > @WebMethod(operationName = "doSomething")
> > 
> > DoSomethingResult doSomething(
> > 
> >  @WebParam(name = "someParam") String someParam);
> > 
> > }
> > 
> > 
> > Now, we could like to be able to call this using the async way with
> > callbacks, is there some way we can declare this manually with
> > annotations? (ie without generating the code from wsdl)
> > 
> > And would it then be possible to JUST declare the callback variations,
> > since we know we won't use the polling approach etc?
> > 
> > Thanks
> > /Kent
-- 
Daniel Kulp
dkulp@apache.org
http://dankulp.com/blog
Talend - http://www.talend.com

Re: Making async interfaces manually with annotations etc?

Posted by Kent Närling <ke...@seamless.se>.
I tried ad-hoc and just wrote the interface myself as:

@WebService

public interface MyService

{

@WebMethod(operationName = "doSomething")

Future<?> doSomething(

@WebParam(name = "someParam") String someParam,
AsyncHandler<DoSomethingResult> asyncHandler);

}
But with this I just god the error : "Could not find wsdl:binding operation
info for web method doSomething"

So I guess this means I would have to annotate some binding information? or
is this impossible to do with annotations?


On 17 August 2011 10:23, Kent Närling <ke...@seamless.se> wrote:

> Hi!
>
> We declare our SOAP interfaces in java and then build the WSDL:s from the
> java code since 99% of our clients are in java and to make it most
> convenient for them we have decided to follow this path.
>
> eg we might have a sample service declared like:
>
> @WebService
>
> public interface MyService
>
> {
>
> @WebMethod(operationName = "doSomething")
>
> DoSomethingResult doSomething(
>
>  @WebParam(name = "someParam") String someParam);
>
> }
>
>
> Now, we could like to be able to call this using the async way with
> callbacks, is there some way we can declare this manually with annotations?
> (ie without generating the code from wsdl)
>
> And would it then be possible to JUST declare the callback variations,
> since we know we won't use the polling approach etc?
>
> Thanks
> /Kent
>