You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Carl-Erik Kopseng <ca...@gmail.com> on 2011/07/22 11:26:49 UTC

Registering interceptors through web.xml

I have been trying to get some interceptors registered without much
success. According to the documentation
(http://cxf.apache.org/docs/jaxrs-services-configuration.html#JAXRSServicesConfiguration-ConfiguringJAXRSendpointsprogrammaticallywithoutSpring)
I should be able to register my interceptors by doing some variation
of the following:

        <init-param>
            <param-name>jaxrs.inInterceptors</param-name>
            <param-value>org.apache.cxf.jaxrs.provider.jsonp.JsonpInInterceptor</param-value>
        </init-param>

I have tried doing this, but it does not seem to take effect when
adding the normal "...&_jsonp=myCallback" to my url. I set a
breakpoint in JsonpInInterceptor.handleMessage(), but it was never
called. Any clues?

There is also a outInterceptors parameter that need to be set, but I
need to specify two interceptors. Would this be correct?
        <init-param>
            <param-name>jaxrs.outInterceptors</param-name>
            <!--<param-value>org.apache.cxf.jaxrs.provider.jsonp.JsonpPreStreamInterceptor,
org.apache.cxf.jaxrs.provider.jsonp.JsonpPostStreamInterceptor</param-value>-->
            <param-value>org.apache.cxf.jaxrs.provider.jsonp.JsonpPreStreamInterceptor</param-value>
        </init-param>

I have only seen Spring examples for configuring these interceptors.
What (where) would be a good way of doing this? I have seen the use of
JAXRSServerFactoryBean to add interceptors, but I do not see where
JAXRSServerFactoryBean should go in the Application (it at all).

-- 
Carl-Erik

Re: Registering interceptors through web.xml

Posted by Carl-Erik Kopseng <ca...@gmail.com>.
> The values are space-separated,
>
> <init-param>
>           <param-name>jaxrs.outInterceptors</param-name>
>           <param-value>
>
> org.apache.cxf.jaxrs.provider.jsonp.JsonpPreStreamInterceptor
>
> org.apache.cxf.jaxrs.provider.jsonp.JsonpPostStreamInterceptor
>           </param-value>
> </init-param>
That was indeed the fix!

Re: Registering interceptors through web.xml

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi Carl-Erik
On 24/10/12 16:19, Carl-Erik Kopseng wrote:
>>>   As can be seen from the discussion below,
>>> interceptors can be injected by specifying them in web.xml, if one is
>>> not using Spring for setup. Today I tried out CXF 2.7.0 and I now got
>>> a ClassNotFoundException:
> (snip(
>>>
>>> As can be seen, the classname that was looked up was split over three
>>> lines, so this means that somehow, this logic has changed
>
> Found the problem by looking at the code revisions for
> CXFNonSpringJaxrsServlet
> (https://fisheye6.atlassian.com/browse/cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/servlet/CXFNonSpringJaxrsServlet.java?r2=1366746&r1=1359097)
>
> Turns out that the default parameter splitting character changed July
> 18 from using a default of " " (space) to "," (comma). This broke the
> configuration. By specifying class.parameter.split.char one can decide
> which character should do the splitting. The following would need to
> be added in order not to change the former configuration:
>
>          <init-param>
>              <param-name>class.parameter.split.char</param-name>
>              <param-value>  </param-value>
>          </init-param>
>          <init-param>
>
> Using comma is fine anyhow, so using that from now on.
>
I recall it now, there were issues with using " " by default when each 
of the interceptors had the additional properties set, example

"myInterceptor1(a=2,
b=3)

myInterceptor2(a=2,
b=3)"

etc, it was splitting it the wrong way so



"myInterceptor1(a=2
b=3)
,
myInterceptor2(a=2
b=3)"

works

Thanks, Sergey

> regards
> Carl-Erik


-- 
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/

Blog: http://sberyozkin.blogspot.com

Re: Registering interceptors through web.xml

Posted by Carl-Erik Kopseng <ca...@gmail.com>.
>>  As can be seen from the discussion below,
>> interceptors can be injected by specifying them in web.xml, if one is
>> not using Spring for setup. Today I tried out CXF 2.7.0 and I now got
>> a ClassNotFoundException:
(snip(
>>
>> As can be seen, the classname that was looked up was split over three
>> lines, so this means that somehow, this logic has changed

Found the problem by looking at the code revisions for
CXFNonSpringJaxrsServlet
(https://fisheye6.atlassian.com/browse/cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/servlet/CXFNonSpringJaxrsServlet.java?r2=1366746&r1=1359097)

Turns out that the default parameter splitting character changed July
18 from using a default of " " (space) to "," (comma). This broke the
configuration. By specifying class.parameter.split.char one can decide
which character should do the splitting. The following would need to
be added in order not to change the former configuration:

        <init-param>
            <param-name>class.parameter.split.char</param-name>
            <param-value> </param-value>
        </init-param>
        <init-param>

Using comma is fine anyhow, so using that from now on.

regards
Carl-Erik

Re: Registering interceptors through web.xml

Posted by Carl-Erik Kopseng <ca...@gmail.com>.
2012/10/24 Carl-Erik Kopseng <ca...@gmail.com>:
> Waking up a year old thread, as the problem at hand is more or less a
> direct followup - just with regards to problems with the newly
> released CXF 2.7.0. As can be seen from the discussion below,
> interceptors can be injected by specifying them in web.xml, if one is
> not using Spring for setup. Today I tried out CXF 2.7.0 and I now got
> a ClassNotFoundException:
>
> LifecycleException:  java.lang.ClassNotFoundException:
> org.apache.cxf.jaxrs.provider.jsonp.JsonpPostStreamInterceptor
>
>                 org.apache.cxf.jaxrs.provider.jsonp.JsonpPreStreamInterceptor
>         at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4979)
>         at org.apache.catalina.core.StandardContext.start(StandardContext.java:5376)
>         at com.sun.enterprise.web.WebModule.start(WebModule.java:345)
>
> As can be seen, the classname that was looked up was split over three
> lines, so this means that somehow, this logic has changed in 2.7.0.
> This works fine in 2.6.2. Is this an intentional change? I could not
> see anything explicit in the changelog.
>
> Using Glassfish 2.1.1, Java 1.6.0_37, OS X, CXF 2.7.0

Correction. This worked fine in 2.4.2, not 2.6.2. The problem is the same there.

Re: Registering interceptors through web.xml

Posted by Carl-Erik Kopseng <ca...@gmail.com>.
Waking up a year old thread, as the problem at hand is more or less a
direct followup - just with regards to problems with the newly
released CXF 2.7.0. As can be seen from the discussion below,
interceptors can be injected by specifying them in web.xml, if one is
not using Spring for setup. Today I tried out CXF 2.7.0 and I now got
a ClassNotFoundException:

LifecycleException:  java.lang.ClassNotFoundException:
org.apache.cxf.jaxrs.provider.jsonp.JsonpPostStreamInterceptor

                org.apache.cxf.jaxrs.provider.jsonp.JsonpPreStreamInterceptor
	at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4979)
	at org.apache.catalina.core.StandardContext.start(StandardContext.java:5376)
	at com.sun.enterprise.web.WebModule.start(WebModule.java:345)

As can be seen, the classname that was looked up was split over three
lines, so this means that somehow, this logic has changed in 2.7.0.
This works fine in 2.6.2. Is this an intentional change? I could not
see anything explicit in the changelog.

Using Glassfish 2.1.1, Java 1.6.0_37, OS X, CXF 2.7.0


>> The fixes in 2.4.2-SNAPSHOT (and trunk) now makes it possible to
>> register the interceptor using init-params, but I have two problems:
>>
>> 1. JSONP support demands two outinterceptors (in addition to the
>> ininterceptor); a pre-stream interceptor and a post-stream
>> interceptor. How can I specify multiple interceptors using init-param?
>> I have tried with
>> <init-param>
>>            <param-name>jaxrs.outInterceptors</param-name>
>>            <param-value>org.apache.cxf.jaxrs.provider.jsonp.JsonpPreStreamInterceptor,
>> org.apache.cxf.jaxrs.provider.jsonp.JsonpPostStreamInterceptor
>> </init-param>
>> , but it only picks up the last one, not both (reversing the two
>> outinterceptors above showes it).
>>
> The values are space-separated,
>
> <init-param>
>            <param-name>jaxrs.outInterceptors</param-name>
>            <param-value>
>
> org.apache.cxf.jaxrs.provider.jsonp.JsonpPreStreamInterceptor
>
> org.apache.cxf.jaxrs.provider.jsonp.JsonpPostStreamInterceptor
>            </param-value>
> </init-param>

-- 
Carl-Erik Kopseng

Re: Registering interceptors through web.xml

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

On Tue, Aug 2, 2011 at 12:18 PM, Carl-Erik Kopseng <ca...@gmail.com> wrote:
>>> That said, I have it fixed in on the trunk/branches
>>
>> Wonderful news. Thank you.
>
> The fixes in 2.4.2-SNAPSHOT (and trunk) now makes it possible to
> register the interceptor using init-params, but I have two problems:
>
> 1. JSONP support demands two outinterceptors (in addition to the
> ininterceptor); a pre-stream interceptor and a post-stream
> interceptor. How can I specify multiple interceptors using init-param?
> I have tried with
> <init-param>
>            <param-name>jaxrs.outInterceptors</param-name>
>            <param-value>org.apache.cxf.jaxrs.provider.jsonp.JsonpPreStreamInterceptor,
> org.apache.cxf.jaxrs.provider.jsonp.JsonpPostStreamInterceptor
> </init-param>
> , but it only picks up the last one, not both (reversing the two
> outinterceptors above showes it).
>
The values are space-separated,

<init-param>
           <param-name>jaxrs.outInterceptors</param-name>
           <param-value>

org.apache.cxf.jaxrs.provider.jsonp.JsonpPreStreamInterceptor

org.apache.cxf.jaxrs.provider.jsonp.JsonpPostStreamInterceptor
           </param-value>
</init-param>


> 2. How can I specify properties to the interceptors like featured on
> http://cxf.apache.org/docs/jax-rs-data-bindings.html#JAX-RSDataBindings-JSONWithPadding?
> For instance to change the mediatype that is set.
>
That is not possible right now. I've been thinking of creating a
light-weight version of beans.xml, for
some simple injection be supported, for users be able to create say
application.xml and reference it from init param and
get it resolved without using Spring but I could not prioritize it -
I'll try to get to it at some later stage...

Cheers, Sergey


> Regards
> Carl-Erik Kopseng
>



-- 
Sergey Beryozkin

http://sberyozkin.blogspot.com
Talend - http://www.talend.com

Re: Registering interceptors through web.xml

Posted by Carl-Erik Kopseng <ca...@gmail.com>.
>> That said, I have it fixed in on the trunk/branches
>
> Wonderful news. Thank you.

The fixes in 2.4.2-SNAPSHOT (and trunk) now makes it possible to
register the interceptor using init-params, but I have two problems:

1. JSONP support demands two outinterceptors (in addition to the
ininterceptor); a pre-stream interceptor and a post-stream
interceptor. How can I specify multiple interceptors using init-param?
I have tried with
<init-param>
            <param-name>jaxrs.outInterceptors</param-name>
            <param-value>org.apache.cxf.jaxrs.provider.jsonp.JsonpPreStreamInterceptor,
org.apache.cxf.jaxrs.provider.jsonp.JsonpPostStreamInterceptor
</init-param>
, but it only picks up the last one, not both (reversing the two
outinterceptors above showes it).

2. How can I specify properties to the interceptors like featured on
http://cxf.apache.org/docs/jax-rs-data-bindings.html#JAX-RSDataBindings-JSONWithPadding?
For instance to change the mediatype that is set.

Regards
Carl-Erik Kopseng

Re: Registering interceptors through web.xml

Posted by Carl-Erik Kopseng <ca...@gmail.com>.
> That said, I have it fixed in on the trunk/branches

Wonderful news. Thank you.

-- 
Carl-Erik Kopseng

(+47) 40065078
skype: carl.erik.kopseng
blogg: oligofren.wordpress.com
##########################
Ser ikke skogen for bare syntakstrær

Re: Registering interceptors through web.xml

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

On Fri, Jul 22, 2011 at 4:05 PM, Carl-Erik Kopseng <ca...@gmail.com> wrote:
>> See this section:
>> http://cxf.apache.org/docs/jaxrs-services-configuration.html#JAXRSServicesConfiguration-ConfiguringJAXRSservicesincontainerwithoutSpring
>>
>> At the moment, in/out interceptors will only be picked up if
>> jaxrs.serviceClasses and jaxrs.providers parameters are used instead of
>> javax.ws.rs.Application.
>>
>> It does make sense to get jaxrs.outInterceptors and jaxrs.inInterceptors
>> supported with Application as well
>
> I see that I cannot ATM configure the interceptors through web.xml,
You can if you use jaxrs.serviceClasses and jaxrs.providers, it's a
limitation/bug
that they are not picked up when Application is used - will try to fix it.

> but is there any way of programmatically adding the interceptors from
> my Application class?

Not really given that Application on its own is supposed to be a
portable construct

>I am unsure if I can go the route you linked to,
> as inject two EJBs into one service, and I am unsure of how that could
> be accomplished by just configuration.
>
>                /* Inserts the appropriate EJBs into the rest service.
>                MyService myService = new BudgetService();
>                try {
>                        myService.setTotalCalculator( (ITotalCalculator) getBean(
> "ITotalCalculator" ) );
>                        myService.setInfoStorage( (IInfoStorage) getBean( "IInfoStorage" ) );
>                } catch ( NamingException e ) {
>                        throw new RuntimeException( e );
>                }
>                singletons.add( myService );
>
If BudgetService only delegates to ITotalCalculator and IInfoStorage
then you can get two
root classes registered via jaxrs.serviceClasses. Example, if
BudgetService handles /path/calc  by just delegating to
ITotalCalculator and /path/info - to IInfoStorage then you can have 2
root resources wrapping  ITotalCalculator and  IInfoStorage and
listening on /path/calc and /path/info respectively.

The other workaround is to register a custom CXFNonSpringJaxrsServlet,
override createServerFromApplication() by copying the code from the
superclass and add a call to setInterceptors() just before bean.create
is called

That said, I have it fixed in on the trunk/branches

Cheers, Sergey
However - I'll try to get it fixed such as that interceptors are added
with Application too from web.xml.



> --
> Regards, Carl-Erik
>



-- 
Sergey Beryozkin

http://sberyozkin.blogspot.com
Talend - http://www.talend.com

Re: Registering interceptors through web.xml

Posted by Carl-Erik Kopseng <ca...@gmail.com>.
> See this section:
> http://cxf.apache.org/docs/jaxrs-services-configuration.html#JAXRSServicesConfiguration-ConfiguringJAXRSservicesincontainerwithoutSpring
>
> At the moment, in/out interceptors will only be picked up if
> jaxrs.serviceClasses and jaxrs.providers parameters are used instead of
> javax.ws.rs.Application.
>
> It does make sense to get jaxrs.outInterceptors and jaxrs.inInterceptors
> supported with Application as well

I see that I cannot ATM configure the interceptors through web.xml,
but is there any way of programmatically adding the interceptors from
my Application class? I am unsure if I can go the route you linked to,
as inject two EJBs into one service, and I am unsure of how that could
be accomplished by just configuration.

		/* Inserts the appropriate EJBs into the rest service.
		MyService myService = new BudgetService();
		try {
			myService.setTotalCalculator( (ITotalCalculator) getBean(
"ITotalCalculator" ) );
			myService.setInfoStorage( (IInfoStorage) getBean( "IInfoStorage" ) );
		} catch ( NamingException e ) {
			throw new RuntimeException( e );
		}
		singletons.add( myService );

--
Regards, Carl-Erik

Re: Registering interceptors through web.xml

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi,
> I have been trying to get some interceptors registered without much
> success. According to the documentation
> (http://cxf.apache.org/docs/jaxrs-services-configuration.html#JAXRSServicesConfiguration-ConfiguringJAXRSendpointsprogrammaticallywithoutSpring)
> I should be able to register my interceptors by doing some variation
> of the following:
> 
>         <init-param>
>             <param-name>jaxrs.inInterceptors</param-name>
>             <param-value>org.apache.cxf.jaxrs.provider.jsonp.JsonpInInterceptor</param-value>
>         </init-param>
> 
> I have tried doing this, but it does not seem to take effect when
> adding the normal "...&_jsonp=myCallback" to my url. I set a
> breakpoint in JsonpInInterceptor.handleMessage(), but it was never
> called. Any clues?
> 
> There is also a outInterceptors parameter that need to be set, but I
> need to specify two interceptors. Would this be correct?
>         <init-param>
>             <param-name>jaxrs.outInterceptors</param-name>
>             <!--<param-value>org.apache.cxf.jaxrs.provider.jsonp.JsonpPreStreamInterceptor,
> org.apache.cxf.jaxrs.provider.jsonp.JsonpPostStreamInterceptor</param-value>-->
>             <param-value>org.apache.cxf.jaxrs.provider.jsonp.JsonpPreStreamInterceptor</param-value>
>         </init-param>
> 
> I have only seen Spring examples for configuring these interceptors.
> What (where) would be a good way of doing this? I have seen the use of
> JAXRSServerFactoryBean to add interceptors, but I do not see where
> JAXRSServerFactoryBean should go in the Application (it at all).
> 

See this section:
http://cxf.apache.org/docs/jaxrs-services-configuration.html#JAXRSServicesConfiguration-ConfiguringJAXRSservicesincontainerwithoutSpring

At the moment, in/out interceptors will only be picked up if 
jaxrs.serviceClasses and jaxrs.providers parameters are used instead of
javax.ws.rs.Application.

It does make sense to get jaxrs.outInterceptors and jaxrs.inInterceptors 
supported with Application as well
Cheers, Sergey