You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by wildPengiun <Si...@gossinteractive.com> on 2008/10/30 09:33:02 UTC

Easy to Answer REST Interceptor Query

I've tried a couple of queries around the subject of REST and interceptors
but with no success. Has anyone actually been able to add their own
customized interceptor into the chain.

Thanks
-- 
View this message in context: http://www.nabble.com/Easy-to-Answer-REST-Interceptor-Query-tp20242642p20242642.html
Sent from the cxf-user mailing list archive at Nabble.com.


Re: Easy to Answer REST Interceptor Query

Posted by Gabo Manuel <km...@solegysystems.com>.
Hi,

Could you attach/paste here your service definition? i.e. beans.xml

Gabo

wildPengiun wrote:
> I've tried a couple of queries around the subject of REST and interceptors
> but with no success. Has anyone actually been able to add their own
> customized interceptor into the chain.
>
> Thanks
>   
> ------------------------------------------------------------------------
>
>
> No virus found in this incoming message.
> Checked by AVG - http://www.avg.com 
> Version: 8.0.175 / Virus Database: 270.8.5/1755 - Release Date: 10/29/2008 5:27 PM
>
>   

Re: Easy to Answer REST Interceptor Query

Posted by Sergey Beryozkin <se...@progress.com>.
Hi,

>
> Definitely sounds like the JAXRSInInterceptor needs to be moved a bit.

Which phase would you recommend ? Between RECEIVE and INVOKE phases we have these phases

Phase.PRE_STREAM (this is where JAXRSInInterceptor currently lives)
Phase.USER_STREAM
Phase.POST_STREAM
Phase.READ
Phase.PRE_PROTOCOL
Phase.USER_PROTOCOL
Phase.POST_PROTOCOL
Phase.UNMARSHAL
Phase.PRE_LOGICAL
Phase.USER_LOGICAL
Phase.POST_LOGICAL
Phase.PRE_INVOKE

I'd allocate it a phase such that if users where to add CXF interceptors before/after JAXRSInInterceptor does its job, they'd use 
the same phases they do when doing some custom pre/post processing with JAX-WS such that the same interceptor can be reused in both 
jaxrs and jaxws request paths, with the same phases involved.

I think Phase.PRE_LOGICAL should fit. Or Phase.UNMARSHAL given that the out JAXRSOutInterceptor sits on the Phase.MARSHAL. What do 
you think ?

>
> Actually, I'm wondering if it's possible to split it up into a couple smaller
> interceptors that can be distributed into the phases a bit better to make it
> closer to the way the normal processing works?   Do some work in one phase,
> allow users to throw some interceptors in, do some more work, etc...    That
> should definitely make it more flexible, but I'm not sure how hard it would
> be to do.

Sounds interesting.
JAXRSInInterceptor does these main tasks :

1. Preprocess uri (as per the 0.8 spec) - this requirement has been dropped but it'll stay in CXF
2. Select a root resource class
3. Invoke on request filters - filters can be blocking if they return a not-null Response or throw Exceptions
4. Select a method on the root resource class to be invoked

JAXRSInvoker proceeds from there, it invokes on a method and if this method is a subresource locator it continues invoking until the 
final method has been invoked. I'm not sure yet how users would want to customize the request say between 3 and 4. But in principle 
1&2 and 3&4 can be done in seperate input interceptors such that after 1&2 but before 3&4 a 'classical' CXF interceptor can be 
plugged in and do some work instead of JAXRS filters. Lets see if some users would find the current 'monolitic' JAXRSInInterceptor a 
bit inflexible. But the split is quite feasible.

About request filters. Once we update the JAXRSInInterceptor's phase users might be able to do some things JAXRS filters can do 
using CXF interceptors - say they'd be able to modify the message, use features to add GZIP (in filters one needs to explicitly 
replace an input stream in a message to do GZIP for ex - not difficult but a bit of etrra work in the code), etc. They will likely 
be able to reuse the same interceptors between JAXWS and JAXRS.

JAXRS pre/post filters are handy is that they're more JAXRS-friendly in that one can block by throwing an exception and combine it 
with a custom JAXRS ExceptionMapper, they can return a JAXRS Response and JAXRS field injection for things like UriInfo/etc, will be 
supported for them too. I can see users focused mainly on JAX-RS doing them more often then CXF interceptors but one never knows 
:-).


Cheers, Sergey

>
>
> Dan
>
>


Re: Easy to Answer REST Interceptor Query

Posted by Daniel Kulp <dk...@apache.org>.
Definitely sounds like the JAXRSInInterceptor needs to be moved a bit.

Actually, I'm wondering if it's possible to split it up into a couple smaller 
interceptors that can be distributed into the phases a bit better to make it 
closer to the way the normal processing works?   Do some work in one phase, 
allow users to throw some interceptors in, do some more work, etc...    That 
should definitely make it more flexible, but I'm not sure how hard it would 
be to do.


Dan



On Monday 03 November 2008 7:36:18 am Sergey Beryozkin wrote:
> Hi
>
> > Thanks for answering Gabo,
> >
> > I have noticed that the interceptors are fired for a web service as my
> > services are set up as both web services and rest services. So I'm
> > assuming there is nothing wrong with either the listener itself or the
> > phase that I'm using.
> >
> > Does anyone know how I can tell what Interceptors are in the chain for
> > the REST service ?
>
> There're only currently only two intereceptors in the input chain for
> (JAXRS) Restfuls service, the JAXRSInInterceptor and
> ServiceInvokerInterceptor.
>
> Now, JAXRSInInterceptor is invoked at the very early stage (PRE_STREAM),
> this stage was there from this interceptor's inception so I've never payed
> any attention to it - and I reckon this is the reason you're not seeing
> your own CXF interceptor being invoked. I think I may need to put
> JAXRSInInterceptor to some later stage, such that some custom interceptors
> can be added before and after the the JAXRSInInterceptor has been invoked.
> here're we're talking about the 'classical' CXF interceptors which use
> phases. Would you like your interceptor be invoked before or after
> JAXRSInInterceptor has been invoked ? What stage you're using ? Also, can
> you elaborate a bit more on how you specify interceptors using annotations
> ?
>
>
> If you're ok with your interceptor be invoked before JAXRSInInterceptor
> then you might want to consider using CXF JAX-RS input filters which 
> JAXRSInInterceptor invokes upon them *before* proceeding with handling the
> actual request.
>
> Cheers, Sergey
>
> > Thanks
> >
> > Gabo Manuel wrote:
> >> Hi,
> >>
> >>> Here's a copy of my beans.xml, I configure the interceptors via
> >>> annotations
> >>
> >> I haven't really tried adding interceptors via annotations. You might
> >> want to look up (http://cwiki.apache.org/CXF20DOC/interceptors.html). I
> >> am not sure if in addition to the annotations, you have to add the
> >> interceptor to some interceptor provider as well.
> >>
> >> Also, afaik the phase tells when the interceptor is meant to be given a
> >> chance/shot at the message. INVOKE phase means that the interceptor will
> >> be given the message context before/during method invocation. The link
> >> above lists down when each phase occurs.
> >>
> >> Others?
> >>
> >> Gabo
> >
> > --
> > View this message in context:
> > http://www.nabble.com/Easy-to-Answer-REST-Interceptor-Query-tp20242642p20
> >243179.html Sent from the cxf-user mailing list archive at Nabble.com.



-- 
Daniel Kulp
dkulp@apache.org
http://dankulp.com/blog

Re: Easy to Answer REST Interceptor Query

Posted by wildPengiun <Si...@gossinteractive.com>.
Hi Sergey

>Would you like your interceptor be invoked before or 
after JAXRSInInterceptor has been invoked ? 

After

>What stage you're using ?

Not sure

>Also, can you elaborate a bit more on how you specify interceptors using
annotations ?
This is the annotation for the class
@OutInterceptors(interceptors =
{"com.gossinteractive.webservices.CrossScriptInterceptor" })

I'm doing all this because I need to wrap the resulting JSON text in a bit
more text to allow for cross domain access to a extJS component.



Sergey Beryozkin-3 wrote:
> 
> Hi
> 
>>
>> Thanks for answering Gabo,
>>
>> I have noticed that the interceptors are fired for a web service as my
>> services are set up as both web services and rest services. So I'm
>> assuming
>> there is nothing wrong with either the listener itself or the phase that
>> I'm
>> using.
>>
>> Does anyone know how I can tell what Interceptors are in the chain for
>> the
>> REST service ?
> 
> There're only currently only two intereceptors in the input chain for
> (JAXRS) Restfuls service,
> the JAXRSInInterceptor and ServiceInvokerInterceptor.
> 
> Now, JAXRSInInterceptor is invoked at the very early stage (PRE_STREAM),
> this stage was there from this interceptor's inception so 
> I've never payed any attention to it - and I reckon this is the reason
> you're not seeing your own CXF interceptor being invoked. I 
> think I may need to put JAXRSInInterceptor to some later stage, such that
> some custom interceptors can be added before and after the 
> the JAXRSInInterceptor has been invoked.
> here're we're talking about the 'classical' CXF interceptors which use
> phases. Would you like your interceptor be invoked before or 
> after JAXRSInInterceptor has been invoked ? What stage you're using ?
> Also, can you elaborate a bit more on how you specify interceptors using
> annotations ?
> 
> 
> If you're ok with your interceptor be invoked before JAXRSInInterceptor
> then you might want to consider using CXF JAX-RS input 
> filters which  JAXRSInInterceptor invokes upon them *before* proceeding
> with handling the actual request.
> 
> Cheers, Sergey
> 
> 
> 
> 
>>
>> Thanks
>>
>>
>>
>> Gabo Manuel wrote:
>>>
>>> Hi,
>>>> Here's a copy of my beans.xml, I configure the interceptors via
>>>> annotations
>>>>
>>>
>>> I haven't really tried adding interceptors via annotations. You might
>>> want to look up (http://cwiki.apache.org/CXF20DOC/interceptors.html). I
>>> am not sure if in addition to the annotations, you have to add the
>>> interceptor to some interceptor provider as well.
>>>
>>> Also, afaik the phase tells when the interceptor is meant to be given a
>>> chance/shot at the message. INVOKE phase means that the interceptor will
>>> be given the message context before/during method invocation. The link
>>> above lists down when each phase occurs.
>>>
>>> Others?
>>>
>>> Gabo
>>>
>>>
>>>
>>
>> -- 
>> View this message in context:
>> http://www.nabble.com/Easy-to-Answer-REST-Interceptor-Query-tp20242642p20243179.html
>> Sent from the cxf-user mailing list archive at Nabble.com.
>> 
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Easy-to-Answer-REST-Interceptor-Query-tp20242642p20443678.html
Sent from the cxf-user mailing list archive at Nabble.com.


Re: Easy to Answer REST Interceptor Query

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

>
> Thanks for answering Gabo,
>
> I have noticed that the interceptors are fired for a web service as my
> services are set up as both web services and rest services. So I'm assuming
> there is nothing wrong with either the listener itself or the phase that I'm
> using.
>
> Does anyone know how I can tell what Interceptors are in the chain for the
> REST service ?

There're only currently only two intereceptors in the input chain for (JAXRS) Restfuls service,
the JAXRSInInterceptor and ServiceInvokerInterceptor.

Now, JAXRSInInterceptor is invoked at the very early stage (PRE_STREAM), this stage was there from this interceptor's inception so 
I've never payed any attention to it - and I reckon this is the reason you're not seeing your own CXF interceptor being invoked. I 
think I may need to put JAXRSInInterceptor to some later stage, such that some custom interceptors can be added before and after the 
the JAXRSInInterceptor has been invoked.
here're we're talking about the 'classical' CXF interceptors which use phases. Would you like your interceptor be invoked before or 
after JAXRSInInterceptor has been invoked ? What stage you're using ?
Also, can you elaborate a bit more on how you specify interceptors using annotations ?


If you're ok with your interceptor be invoked before JAXRSInInterceptor then you might want to consider using CXF JAX-RS input 
filters which  JAXRSInInterceptor invokes upon them *before* proceeding with handling the actual request.

Cheers, Sergey




>
> Thanks
>
>
>
> Gabo Manuel wrote:
>>
>> Hi,
>>> Here's a copy of my beans.xml, I configure the interceptors via
>>> annotations
>>>
>>
>> I haven't really tried adding interceptors via annotations. You might
>> want to look up (http://cwiki.apache.org/CXF20DOC/interceptors.html). I
>> am not sure if in addition to the annotations, you have to add the
>> interceptor to some interceptor provider as well.
>>
>> Also, afaik the phase tells when the interceptor is meant to be given a
>> chance/shot at the message. INVOKE phase means that the interceptor will
>> be given the message context before/during method invocation. The link
>> above lists down when each phase occurs.
>>
>> Others?
>>
>> Gabo
>>
>>
>>
>
> -- 
> View this message in context: http://www.nabble.com/Easy-to-Answer-REST-Interceptor-Query-tp20242642p20243179.html
> Sent from the cxf-user mailing list archive at Nabble.com.
> 


Re: Easy to Answer REST Interceptor Query

Posted by wildPengiun <Si...@gossinteractive.com>.
Thanks for answering Gabo,

I have noticed that the interceptors are fired for a web service as my
services are set up as both web services and rest services. So I'm assuming
there is nothing wrong with either the listener itself or the phase that I'm
using.

Does anyone know how I can tell what Interceptors are in the chain for the
REST service ?

Thanks



Gabo Manuel wrote:
> 
> Hi,
>> Here's a copy of my beans.xml, I configure the interceptors via
>> annotations
>>   
> 
> I haven't really tried adding interceptors via annotations. You might 
> want to look up (http://cwiki.apache.org/CXF20DOC/interceptors.html). I 
> am not sure if in addition to the annotations, you have to add the 
> interceptor to some interceptor provider as well.
> 
> Also, afaik the phase tells when the interceptor is meant to be given a 
> chance/shot at the message. INVOKE phase means that the interceptor will 
> be given the message context before/during method invocation. The link 
> above lists down when each phase occurs.
> 
> Others?
> 
> Gabo
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Easy-to-Answer-REST-Interceptor-Query-tp20242642p20243179.html
Sent from the cxf-user mailing list archive at Nabble.com.


Re: Easy to Answer REST Interceptor Query

Posted by Gabo Manuel <km...@solegysystems.com>.
Hi,
> Here's a copy of my beans.xml, I configure the interceptors via annotations
>   

I haven't really tried adding interceptors via annotations. You might 
want to look up (http://cwiki.apache.org/CXF20DOC/interceptors.html). I 
am not sure if in addition to the annotations, you have to add the 
interceptor to some interceptor provider as well.

Also, afaik the phase tells when the interceptor is meant to be given a 
chance/shot at the message. INVOKE phase means that the interceptor will 
be given the message context before/during method invocation. The link 
above lists down when each phase occurs.

Others?

Gabo


Re: Easy to Answer REST Interceptor Query

Posted by wildPengiun <Si...@gossinteractive.com>.
Here's a copy of my beans.xml, I configure the interceptors via annotations


<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:jaxrs="http://cxf.apache.org/jaxrs"
  xmlns:jaxws="http://cxf.apache.org/jaxws"
  xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxrs
http://cxf.apache.org/schemas/jaxrs.xsd
http://cxf.apache.org/jaxws
http://cxf.apache.org/schemas/jaxws.xsd">

  <import resource="classpath:META-INF/cxf/cxf.xml" />
  <import resource="classpath:META-INF/cxf/cxf-extension-jaxrs-binding.xml"
/>
  <import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
  <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml"/>
	<import resource="classpath:META-INF/cxf/cxf-extension-xml.xml"/>
  

  <!-- JAX-RS -->
  <jaxrs:server id="folderService" address="/rest">
    <jaxrs:serviceBeans>
      <ref bean="documentServicesFacadeBean" />
    </jaxrs:serviceBeans>
  </jaxrs:server>

  <!-- JAX-WS -->
    <jaxws:endpoint id="documentServiceWS" implementor=
"#documentServicesFacadeBean"      
		implementorClass="com.gossinteractive.webservices.DocumentFacade"
address="/services/DocumentService">
        <jaxws:serviceFactory>
            <ref bean="wsfactory"/>
        </jaxws:serviceFactory>
    </jaxws:endpoint>

	<bean id="wsfactory"
		class="org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean"
		scope="prototype">
        <property name="wrapped" value="true"/>
    </bean>
   
   <!-- Facade beans -->

	<bean id="documentServicesFacadeBean"
		class="com.gossinteractive.webservices.DocumentFacade" scope="singleton">
		
		<property name="administration">
			<ref bean="administrationBean" />
		</property>
		<property name="documents">
			<ref bean="documentsBean" />
		</property>
		
		
	</bean>

	<!-- import service bean -->
	<bean id="importServicesFacadeBean"
		class="com.gossinteractive.webservices.ImportXMLContentFacade"
scope="singleton">
		<lookup-method name="retrieveSession" bean="sessionBean" />
		<property name="importContentService">
			<ref bean="importContentServiceBean" />
		</property>
	</bean>

<!-- Server information beans -->

	<bean id="version"
	
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
scope="singleton">
		<property name="locations">
			<list>
				<value>/WEB-INF/classes/service.properties</value>
				<value>/WEB-INF/classes/license.properties</value>
			</list>
		</property>
	</bean> 
    
   </beans>

wildPengiun wrote:
> 
> I've tried a couple of queries around the subject of REST and interceptors
> but with no success. Has anyone actually been able to add their own
> customized interceptor into the chain.
> 
> Thanks
> 

-- 
View this message in context: http://www.nabble.com/Easy-to-Answer-REST-Interceptor-Query-tp20242642p20242885.html
Sent from the cxf-user mailing list archive at Nabble.com.