You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by geecxf <am...@ge.com> on 2013/04/04 17:32:40 UTC

Question on org.apache.cxf.rs.provider

According to the documentation located at
https://cxf.apache.org/distributed-osgi-reference.html, there are three ways
one can specify org.apache.cxf.rs.provider: as a string, string[], or list.

However, I am seeing different behavior when I use one vs. the other. For
example: I can specify the property like so:

"org.apache.cxf.rs.security.saml.SamlHeaderInHandler,org.codehaus.jackson.jaxrs.JacksonJsonProvider"

and in this case it seems like both providers affect service behavior. I
know this because:
1. The debugger breaks into SamlHeaderInHandler
2. The returned JSON does not include the root object which is different
than the behavior I see if I don't use JacksonJsonProvider (and
coincidentally, the reason I need to use it).

On the other hand if I specify the property as a list:

List providers = new ArrayList();
providers.add("org.apache.cxf.rs.security.saml.SamlHeaderInHandler");
providers.add("org.codehaus.jackson.jaxrs.JacksonJsonProvider");

or

List<String> providers = new ArrayList<String>();
providers.add("org.apache.cxf.rs.security.saml.SamlHeaderInHandler");
providers.add("org.codehaus.jackson.jaxrs.JacksonJsonProvider");

or

providers.toArray(); // From a List<String>

I get an entirely different behavior. In fact, the behavior I see is that
neither providers are applied to the service.

Is this expected behavior? It would seem that either I am doing something
wrong or the documentation is wrong? Or maybe both?

Constructing a comma delimited string would be OK except for the fact that
in some situation we would like to pass an object as a provider. Maybe we're
asking for too much flexibility?

Thanks



--
View this message in context: http://cxf.547215.n5.nabble.com/Question-on-org-apache-cxf-rs-provider-tp5725851.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: Question on org.apache.cxf.rs.provider

Posted by Sergey Beryozkin <sb...@gmail.com>.
On 05/04/13 18:23, geecxf wrote:
> I can confirm that String[] works. I thought it didn't at first, but then I
> realized that toArray() produces an Object[] even when the type is
> ArrayList<String>  (stupid Java).
>
> While using String[] works, it's still not ideal for us because we also need
> the ability to pass an object as well. Is there a JIRA issue for this?
>
Yes, please watch
https://issues.apache.org/jira/browse/DOSGI-166

Sergey

> Thanks,
>
> D
>
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/Question-on-org-apache-cxf-rs-provider-tp5725851p5725917.html
> Sent from the cxf-user mailing list archive at Nabble.com.

Re: Question on org.apache.cxf.rs.provider

Posted by geecxf <am...@ge.com>.
I can confirm that String[] works. I thought it didn't at first, but then I
realized that toArray() produces an Object[] even when the type is
ArrayList<String> (stupid Java).

While using String[] works, it's still not ideal for us because we also need
the ability to pass an object as well. Is there a JIRA issue for this?

Thanks,

D



--
View this message in context: http://cxf.547215.n5.nabble.com/Question-on-org-apache-cxf-rs-provider-tp5725851p5725917.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: Question on org.apache.cxf.rs.provider

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi,
On 05/04/13 00:29, geecxf wrote:
> Thank for pointing out that class. That was very helpful in debugging.
> Unfortunately, the behavior is still the same only more baffling than
> before!
>
> Here's what I'm doing:
>
> List providers = new ArrayList();
> providers.add(new org.apache.cxf.rs.security.saml.SamlHeaderInHandler());
> providers.add(new org.codehaus.jackson.jaxrs.JacksonJsonProvider());
>
> And the result is still the same. Neither is applied. However, if I step
> through the code ClassUtil code the return value of loadProviderClasses()
> seems the same as when I use a comma delimited string. I can't see any
> difference. In each case a List of objects with an instance of
> SamlHeaderInHandler and JacksonJsonProvider are created. However, only when
> I use the comma delimited string do I get the correct behavior.
>
> What could possibly be going on to explain this behavior?
> Are you sure the property is not being used in some other bit of code?

Ok, I think I see where the problem is, the last branch within the "if 
(serviceProviders != null)" assumes that it is just an Object (I recall 
there was a request to support just that, a reference to a provider bean 
loaded in a Spring context), so I guess doing Arrays.asList on the 
actual List instance is what confuses the handler.
So the immediate workaround (referring to your original example where 
List<String> was used) is to use String[].
Support for List<Object> and indeed for List<String> would have to go 
1.4.1 (and I guess alongside with other fixes from Amichai Rothman), 
I'll open a JIRA to get this issue tracked

Thanks, Sergey


>
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/Question-on-org-apache-cxf-rs-provider-tp5725851p5725887.html
> Sent from the cxf-user mailing list archive at Nabble.com.



Re: Question on org.apache.cxf.rs.provider

Posted by geecxf <am...@ge.com>.
Thank for pointing out that class. That was very helpful in debugging.
Unfortunately, the behavior is still the same only more baffling than
before!

Here's what I'm doing:

List providers = new ArrayList();
providers.add(new org.apache.cxf.rs.security.saml.SamlHeaderInHandler());
providers.add(new org.codehaus.jackson.jaxrs.JacksonJsonProvider());

And the result is still the same. Neither is applied. However, if I step
through the code ClassUtil code the return value of loadProviderClasses()
seems the same as when I use a comma delimited string. I can't see any
difference. In each case a List of objects with an instance of
SamlHeaderInHandler and JacksonJsonProvider are created. However, only when
I use the comma delimited string do I get the correct behavior.

What could possibly be going on to explain this behavior?
Are you sure the property is not being used in some other bit of code?



--
View this message in context: http://cxf.547215.n5.nabble.com/Question-on-org-apache-cxf-rs-provider-tp5725851p5725887.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: Question on org.apache.cxf.rs.provider

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi
On 04/04/13 18:32, geecxf wrote:
> According to the documentation located at
> https://cxf.apache.org/distributed-osgi-reference.html, there are three ways
> one can specify org.apache.cxf.rs.provider: as a string, string[], or list.
>
> However, I am seeing different behavior when I use one vs. the other. For
> example: I can specify the property like so:
>
> "org.apache.cxf.rs.security.saml.SamlHeaderInHandler,org.codehaus.jackson.jaxrs.JacksonJsonProvider"
>
> and in this case it seems like both providers affect service behavior. I
> know this because:
> 1. The debugger breaks into SamlHeaderInHandler
> 2. The returned JSON does not include the root object which is different
> than the behavior I see if I don't use JacksonJsonProvider (and
> coincidentally, the reason I need to use it).
>
> On the other hand if I specify the property as a list:
>
> List providers = new ArrayList();
> providers.add("org.apache.cxf.rs.security.saml.SamlHeaderInHandler");
> providers.add("org.codehaus.jackson.jaxrs.JacksonJsonProvider");
>
> or
>
> List<String>  providers = new ArrayList<String>();
> providers.add("org.apache.cxf.rs.security.saml.SamlHeaderInHandler");
> providers.add("org.codehaus.jackson.jaxrs.JacksonJsonProvider");
>
> or
>
> providers.toArray(); // From a List<String>
>
> I get an entirely different behavior. In fact, the behavior I see is that
> neither providers are applied to the service.
>
> Is this expected behavior? It would seem that either I am doing something
> wrong or the documentation is wrong? Or maybe both?
>
> Constructing a comma delimited string would be OK except for the fact that
> in some situation we would like to pass an object as a provider. Maybe we're
> asking for too much flexibility?
>
Have a look at
http://svn.apache.org/repos/asf/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/util/ClassUtils.java

I think it has to be List<Object>, where the providers are already 
loaded; alternatively, it can be String[]

HTH, Sergey

> Thanks
>
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/Question-on-org-apache-cxf-rs-provider-tp5725851.html
> Sent from the cxf-user mailing list archive at Nabble.com.