You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by liw <pa...@yahoo.com> on 2009/08/15 01:29:47 UTC

How to get the method info for rest service

Hi,

We are working on a project that exposes both soap and rest web services for
the same underlying interface and impl java classes

In the interface class, we define some annotations at both class and
interface level, which we need to apply business logic based on the
annotations.

e.g.

@WSMTMethod(productionGroup="Internal")
  public SampleCalcResponse calculate(SampleCalcParams calcParams ) throws
AppException;
	

For the soap, we have the following code to get the Method used for the soap
request.

   private Method getMethod(Message message) {
	    	Exchange ex = message.getExchange();
	    	BindingOperationInfo op =
(BindingOperationInfo)ex.get(BindingOperationInfo.class);
	    	if(op == null)
	    		return null; //found its null for jaxrs
	    	Service service = ex.get(Service.class);
	    	MethodDispatcher md =
(MethodDispatcher)service.get(MethodDispatcher.class.getName());
	        return md.getMethod(op);
	    }

However, this piece of code doesn't work for rest. For rest,
(BindingOperationInfo)ex.get(BindingOperationInfo.class) returns null.


How to get a handler of the underlying interface and impl class/methods
using jaxrs? If BindingOperationInfo is only for soap, what's the equivalent
class for rest?

Thanks in advance,

Li






-- 
View this message in context: http://www.nabble.com/How-to-get-the-method-info-for-rest-service-tp24980139p24980139.html
Sent from the cxf-user mailing list archive at Nabble.com.


Re: How to get the method info for rest service

Posted by Sergey Beryozkin <sb...@progress.com>.
Hi

Going forward, I think we should try to make the same code working in cases when both JAXRS & JAXWS are used, by detecting it 
somehow and converting JAXRS model info into WSDL-like info.
In meantime, you can get the name of the method to be invoked like this :

OperationResourceInfo ori = exchange.get(OperationResourceInfo.class);
ori.getMethodToInvoke().getName();

cheers, Sergey

----- Original Message ----- 
From: "liw" <pa...@yahoo.com>
To: <us...@cxf.apache.org>
Sent: Saturday, August 15, 2009 12:29 AM
Subject: How to get the method info for rest service


>
> Hi,
>
> We are working on a project that exposes both soap and rest web services for
> the same underlying interface and impl java classes
>
> In the interface class, we define some annotations at both class and
> interface level, which we need to apply business logic based on the
> annotations.
>
> e.g.
>
> @WSMTMethod(productionGroup="Internal")
>  public SampleCalcResponse calculate(SampleCalcParams calcParams ) throws
> AppException;
>
>
> For the soap, we have the following code to get the Method used for the soap
> request.
>
>   private Method getMethod(Message message) {
>     Exchange ex = message.getExchange();
>     BindingOperationInfo op =
> (BindingOperationInfo)ex.get(BindingOperationInfo.class);
>     if(op == null)
>     return null; //found its null for jaxrs
>     Service service = ex.get(Service.class);
>     MethodDispatcher md =
> (MethodDispatcher)service.get(MethodDispatcher.class.getName());
>         return md.getMethod(op);
>     }
>
> However, this piece of code doesn't work for rest. For rest,
> (BindingOperationInfo)ex.get(BindingOperationInfo.class) returns null.
>
>
> How to get a handler of the underlying interface and impl class/methods
> using jaxrs? If BindingOperationInfo is only for soap, what's the equivalent
> class for rest?
>
> Thanks in advance,
>
> Li
>
>
>
>
>
>
> -- 
> View this message in context: http://www.nabble.com/How-to-get-the-method-info-for-rest-service-tp24980139p24980139.html
> Sent from the cxf-user mailing list archive at Nabble.com.
> 


RE: How to get the method info for rest service

Posted by liw <pa...@yahoo.com>.
Hi Eamonn,

Yes, it helps. I am able to get it work for REST service.

Thanks a lot,

Li




Eamonn Dwyer-2 wrote:
> 
> 
> Hi Li
> I think the following might help you to get the operation
> 
> OperationResourceInfo operationResourceInfo =
> ex.get(OperationResourceInfo.class);
> String operation = operationResourceInfo.getMethodToInvoke();
> 
> I think then to get the JAX rs service you need to use
> 
> Endpoint endpoint = ex.get(Endpoint.class);
> Service service = endpoint.getService(); 
> 
> 
> Hope this helps
> Eamonn
> 
>> Date: Fri, 14 Aug 2009 16:29:47 -0700
>> From: pattiewang@yahoo.com
>> To: users@cxf.apache.org
>> Subject: How to get the method info for rest service
>> 
>> 
>> Hi,
>> 
>> We are working on a project that exposes both soap and rest web services
>> for
>> the same underlying interface and impl java classes
>> 
>> In the interface class, we define some annotations at both class and
>> interface level, which we need to apply business logic based on the
>> annotations.
>> 
>> e.g.
>> 
>> @WSMTMethod(productionGroup="Internal")
>>   public SampleCalcResponse calculate(SampleCalcParams calcParams )
>> throws
>> AppException;
>> 	
>> 
>> For the soap, we have the following code to get the Method used for the
>> soap
>> request.
>> 
>>    private Method getMethod(Message message) {
>> 	    	Exchange ex = message.getExchange();
>> 	    	BindingOperationInfo op =
>> (BindingOperationInfo)ex.get(BindingOperationInfo.class);
>> 	    	if(op == null)
>> 	    		return null; //found its null for jaxrs
>> 	    	Service service = ex.get(Service.class);
>> 	    	MethodDispatcher md =
>> (MethodDispatcher)service.get(MethodDispatcher.class.getName());
>> 	        return md.getMethod(op);
>> 	    }
>> 
>> However, this piece of code doesn't work for rest. For rest,
>> (BindingOperationInfo)ex.get(BindingOperationInfo.class) returns null.
>> 
>> 
>> How to get a handler of the underlying interface and impl class/methods
>> using jaxrs? If BindingOperationInfo is only for soap, what's the
>> equivalent
>> class for rest?
>> 
>> Thanks in advance,
>> 
>> Li
>> 
>> 
>> 
>> 
>> 
>> 
>> -- 
>> View this message in context:
>> http://www.nabble.com/How-to-get-the-method-info-for-rest-service-tp24980139p24980139.html
>> Sent from the cxf-user mailing list archive at Nabble.com.
>> 
> 
> _________________________________________________________________
> See all the ways you can stay connected to friends and family
> http://www.microsoft.com/windows/windowslive/default.aspx
> 

-- 
View this message in context: http://www.nabble.com/How-to-get-the-method-info-for-rest-service-tp24980139p25019078.html
Sent from the cxf-user mailing list archive at Nabble.com.


RE: How to get the method info for rest service

Posted by Eamonn Dwyer <ea...@hotmail.com>.
Hi Li
I think the following might help you to get the operation

OperationResourceInfo operationResourceInfo = ex.get(OperationResourceInfo.class);
String operation = operationResourceInfo.getMethodToInvoke();

I think then to get the JAX rs service you need to use

Endpoint endpoint = ex.get(Endpoint.class);
Service service = endpoint.getService(); 


Hope this helps
Eamonn

> Date: Fri, 14 Aug 2009 16:29:47 -0700
> From: pattiewang@yahoo.com
> To: users@cxf.apache.org
> Subject: How to get the method info for rest service
> 
> 
> Hi,
> 
> We are working on a project that exposes both soap and rest web services for
> the same underlying interface and impl java classes
> 
> In the interface class, we define some annotations at both class and
> interface level, which we need to apply business logic based on the
> annotations.
> 
> e.g.
> 
> @WSMTMethod(productionGroup="Internal")
>   public SampleCalcResponse calculate(SampleCalcParams calcParams ) throws
> AppException;
> 	
> 
> For the soap, we have the following code to get the Method used for the soap
> request.
> 
>    private Method getMethod(Message message) {
> 	    	Exchange ex = message.getExchange();
> 	    	BindingOperationInfo op =
> (BindingOperationInfo)ex.get(BindingOperationInfo.class);
> 	    	if(op == null)
> 	    		return null; //found its null for jaxrs
> 	    	Service service = ex.get(Service.class);
> 	    	MethodDispatcher md =
> (MethodDispatcher)service.get(MethodDispatcher.class.getName());
> 	        return md.getMethod(op);
> 	    }
> 
> However, this piece of code doesn't work for rest. For rest,
> (BindingOperationInfo)ex.get(BindingOperationInfo.class) returns null.
> 
> 
> How to get a handler of the underlying interface and impl class/methods
> using jaxrs? If BindingOperationInfo is only for soap, what's the equivalent
> class for rest?
> 
> Thanks in advance,
> 
> Li
> 
> 
> 
> 
> 
> 
> -- 
> View this message in context: http://www.nabble.com/How-to-get-the-method-info-for-rest-service-tp24980139p24980139.html
> Sent from the cxf-user mailing list archive at Nabble.com.
> 

_________________________________________________________________
See all the ways you can stay connected to friends and family
http://www.microsoft.com/windows/windowslive/default.aspx