You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Kiren Pillay <ki...@gmail.com> on 2011/09/28 16:42:48 UTC
Marshalling REST Query Parameter directly into Integer Array
Hi
This is an old problem, but I can't seem to find a solution posted
anywhere. I want to marshall a comma-separated list of integers
directly into an Integer [].
1. Service:
public Response getCounters(
@QueryParam("msisdn") Long msisdn,
@QueryParam("counters") Integer [] counters,
@QueryParam("subscriberIdType") String subscriberIdType)
2. I've written a ParameterHandler for this :
public class IntegerArrayParameterHandler implements
ParameterHandler<Integer[]> {
@Override
public Integer[] fromString(String arg0) {
3. The parameter handler is registered, however its not picked up when
I do the query:
<detail>[I cannot be cast to [Ljava.lang.Object;
org.apache.cxf.jaxrs.utils.InjectionUtils.addToCollectionValues(InjectionUtils.java:752)
org.apache.cxf.jaxrs.utils.InjectionUtils.injectIntoCollectionOrArray(InjectionUtils.java:740)
org.apache.cxf.jaxrs.utils.InjectionUtils.createParameterObject(InjectionUtils.java:807)
org.apache.cxf.jaxrs.utils.JAXRSUtils.readQueryString(JAXRSUtils.java:947)
org.apache.cxf.jaxrs.utils.JAXRSUtils.createHttpParameterValue(JAXRSUtils.java:649)
Is there a way to get this to work?
4. I've Registered the Provider:
----
<ref bean="integerArrayParameterHandler" />
</jaxrs:providers>
The easiest solution is to just use the String value and parse it
inside my code,( which is probably why there are not many posts on
this:).
Regards
Kiren
Re: Marshalling REST Query Parameter directly into Integer Array
Posted by Sergey Beryozkin <sb...@gmail.com>.
See comments inline
On 04/10/11 09:33, Kiren Pillay wrote:
> Thanks Sergei, I was on the wrong track, but thanks to your testcase I
> can see now that I should pass in array variables as:
> http://localhost:8080/testMyRest/time?index=1&index=2&index=3
>
> and I was trying to achieve this kind of request (more human/tester friendly)
> http://localhost:8080/testMyRest/time?index=1,2,3
>
Right, see why would one want to get ParameterHandler<List<Integer>>
working.
I think
> http://localhost:8080/testMyRest/time?i=1&i=2&i=3
is reasonable too and is generally better supported. Besides, in many
cases humans don't type those queries manually, forms/scripts/code does
that :-)
One thing you may want to do, if you'd like to support
?index=1,2,3 and List<Integer>, is to get a RequestHandler registered
instead which would
get Message.QUERY_STRING from the current CXF Message, such as
'index=1,2,3' and convert it into "index=1&index=2&index=3" and reset on
the same Message, it will be computationally very cheap and will
help with avoiding parsing "1,2,3" in the actual application code
One other thing, have a look at
http://cxf.apache.org/docs/jax-rs-advanced-features.html#JAX-RSAdvancedFeatures-FIQLsearchqueries
That feature really needs to get more attention again as IMHO it can
become a very useful one...
Cheers, Sergey
> Regards
> Kiren
> On Mon, Oct 3, 2011 at 5:11 PM, Sergey Beryozkin<sb...@gmail.com> wrote:
>> That works exactly the way I described :-), but you can easily double-check
>> it by havubg a breakpoint in
>> org.apache.cxf.jaxrs.utils.JAXRSUtils.processParameter and you can see what
>> happens by running most of JAXRSUtilsTest, testCustomerParameter is one of
>> them
>> Sergey
>>
>> On 03/10/11 15:25, Kiren Pillay wrote:
>>>
>>> Okay, can you send me the name of a test case in the code where I can
>>> see how this works please?
>>>
>>> Regards
>>> Kiren
>>>
>>>
>>> On Mon, Oct 3, 2011 at 10:35 AM, Sergey Beryozkin<sb...@gmail.com>
>>> wrote:
>>>>
>>>> Hi
>>>>
>>>> When we have List<SomeType>, it is the runtime that manages the
>>>> instantiation of List and it would look for ParameterHandler<SomeType>
>>>> only if SomeType does not have a suitable constructor or factory method.
>>>> It
>>>> will also be checked as a last resort if SomeType(String) constructor
>>>> throws
>>>> an exception, ex, Date(String) is problematic...
>>>>
>>>> Cheers, Sergey
>>>>
>>>> On 02/10/11 18:39, Kiren Pillay wrote:
>>>>>
>>>>> Hi Sergey,
>>>>>
>>>>> Apologies, I didn't test my app correctly. It looks like the
>>>>> ParameterHandler isn't working as it should.
>>>>>
>>>>> When I use a parameter of 1 for example, then it works. If I use a
>>>>> comma-separated list ("1,2,3") it fails saying:
>>>>> "02 Oct 2011 7:19:18 PM org.apache.cxf.jaxrs.utils.InjectionUtils
>>>>> handleParameter
>>>>> SEVERE: Class java.lang.Integer can not be instantiated using a
>>>>> constructor with a single String argument"
>>>>>
>>>>> When debugging, I notice that my custom ParameterHandler is not hit,
>>>>> maybe my ParameterHandler is not registered correctly?
>>>>>
>>>>> Here's my bean config snippet:
>>>>> --
>>>>>
>>>>> <import resource="classpath:META-INF/cxf/cxf.xml"/>
>>>>> <context:component-scan base-package="za.co.kiren"/>
>>>>>
>>>>> <bean id="integerListParameterHandler"
>>>>> class="za.co.vodacom.pams.core.common.cxf.IntegerListParameterHandler"
>>>>> />
>>>>>
>>>>>
>>>>> <jaxrs:server id="restContainer" address="/">
>>>>> <jaxrs:serviceBeans>
>>>>> <ref bean="timeService"/>
>>>>> </jaxrs:serviceBeans>
>>>>> <jaxrs:providers>
>>>>> <ref bean="integerListParameterHandler" />
>>>>>
>>>>> </jaxrs:providers>
>>>>> </jaxrs:server>
>>>>> </beans>
>>>>>
>>>>>
>>>>> Class:
>>>>>
>>>>> package za.co.kiren.testMyRest;
>>>>>
>>>>> import org.springframework.format.datetime.DateFormatter;
>>>>> import org.springframework.stereotype.Component;
>>>>> import org.springframework.stereotype.Service;
>>>>>
>>>>> import java.util.Calendar;
>>>>> import java.util.List;
>>>>> import java.util.Locale;
>>>>>
>>>>> import javax.ws.rs.GET;
>>>>> import javax.ws.rs.Path;
>>>>> import javax.ws.rs.Produces;
>>>>> import javax.ws.rs.QueryParam;
>>>>>
>>>>> @Component
>>>>> @Service("timeService")
>>>>> public class TimeService {
>>>>> @GET
>>>>> @Produces("text/plain")
>>>>> @Path("/time")
>>>>> public String getDateTime(@QueryParam("index") List<Integer>
>>>>> list)
>>>>> {
>>>>> String tmp = list.toString();
>>>>> /*
>>>>> * for (Integer integer : list) { tmp+=":"+integer; }
>>>>> */
>>>>>
>>>>> DateFormatter formatter = new DateFormatter("dd/MM/yyyy
>>>>> hh:mm:ss");
>>>>>
>>>>> return tmp
>>>>> +
>>>>> formatter.print(Calendar.getInstance().getTime(),
>>>>> Locale.getDefault());
>>>>> }
>>>>> }
>>>>>
>>>>>
>>>>> On Fri, Sep 30, 2011 at 4:47 PM, Kiren Pillay<ki...@gmail.com>
>>>>> wrote:
>>>>>>
>>>>>> Hi Sergery,
>>>>>>
>>>>>> List<Integer> works well, thanks for your help:)
>>>>>>
>>>>>> Moved to 2.4.2 also.
>>>>>>
>>>>>> Regards
>>>>>> Kiren
>>>>>>
>>>>>> On Thu, Sep 29, 2011 at 2:33 PM, Sergey Beryozkin<sb...@gmail.com>
>>>>>> wrote:
>>>>>>>
>>>>>>> Hi
>>>>>>>
>>>>>>> There was a minor issue to do with handling arrays such as Integer[],
>>>>>>> but I
>>>>>>> can see no problems with List<Integer>. I committed a test involving
>>>>>>> List<Integer> & Integer[].
>>>>>>> Not sure why you see a problem with List<Integer>
>>>>>>> Can you try 2.4.2 please ?
>>>>>>> Sergey
>>>>>>>
>>>>>>> On 28/09/11 17:34, Kiren Pillay wrote:
>>>>>>>>
>>>>>>>> Hi Sergey!
>>>>>>>>
>>>>>>>> Tried int[], got the same error.
>>>>>>>>
>>>>>>>> <detail>[I cannot be cast to [Ljava.lang.Object;
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> org.apache.cxf.jaxrs.utils.InjectionUtils.addToCollectionValues(InjectionUtils.java:752)
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> org.apache.cxf.jaxrs.utils.InjectionUtils.injectIntoCollectionOrArray(InjectionUtils.java:740)
>>>>>>>>
>>>>>>>>
>>>>>>>> I also tried List<Integer> but that also failed with the same
>>>>>>>> error.
>>>>>>>>
>>>>>>>> Is there anything special with the provider configuration maybe?
>>>>>>>> (using
>>>>>>>> 2.4.1).
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> On Wed, Sep 28, 2011 at 5:41 PM, Sergey
>>>>>>>> Beryozkin<sb...@gmail.com>
>>>>>>>> wrote:
>>>>>>>>>
>>>>>>>>> Hi
>>>>>>>>>
>>>>>>>>> List<Integer> must be supported, I'll add a test for Integer[],
>>>>>>>>> have you
>>>>>>>>> tried int[] ?
>>>>>>>>>
>>>>>>>>> Cheers, Sergey
>>>>>>>>>
>>>>>>>>> On 28/09/11 15:42, Kiren Pillay wrote:
>>>>>>>>>>
>>>>>>>>>> Hi
>>>>>>>>>>
>>>>>>>>>> This is an old problem, but I can't seem to find a solution posted
>>>>>>>>>> anywhere. I want to marshall a comma-separated list of integers
>>>>>>>>>> directly into an Integer [].
>>>>>>>>>>
>>>>>>>>>> 1. Service:
>>>>>>>>>>
>>>>>>>>>> public Response getCounters(
>>>>>>>>>> @QueryParam("msisdn") Long msisdn,
>>>>>>>>>> @QueryParam("counters") Integer [] counters,
>>>>>>>>>> @QueryParam("subscriberIdType") String
>>>>>>>>>> subscriberIdType)
>>>>>>>>>>
>>>>>>>>>> 2. I've written a ParameterHandler for this :
>>>>>>>>>>
>>>>>>>>>> public class IntegerArrayParameterHandler implements
>>>>>>>>>> ParameterHandler<Integer[]> {
>>>>>>>>>> @Override
>>>>>>>>>> public Integer[] fromString(String arg0) {
>>>>>>>>>>
>>>>>>>>>> 3. The parameter handler is registered, however its not picked up
>>>>>>>>>> when
>>>>>>>>>> I do the query:
>>>>>>>>>>
>>>>>>>>>> <detail>[I cannot be cast to [Ljava.lang.Object;
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> org.apache.cxf.jaxrs.utils.InjectionUtils.addToCollectionValues(InjectionUtils.java:752)
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> org.apache.cxf.jaxrs.utils.InjectionUtils.injectIntoCollectionOrArray(InjectionUtils.java:740)
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> org.apache.cxf.jaxrs.utils.InjectionUtils.createParameterObject(InjectionUtils.java:807)
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> org.apache.cxf.jaxrs.utils.JAXRSUtils.readQueryString(JAXRSUtils.java:947)
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> org.apache.cxf.jaxrs.utils.JAXRSUtils.createHttpParameterValue(JAXRSUtils.java:649)
>>>>>>>>>>
>>>>>>>>>> Is there a way to get this to work?
>>>>>>>>>>
>>>>>>>>>> 4. I've Registered the Provider:
>>>>>>>>>> ----
>>>>>>>>>> <ref bean="integerArrayParameterHandler" />
>>>>>>>>>> </jaxrs:providers>
>>>>>>>>>>
>>>>>>>>>> The easiest solution is to just use the String value and parse it
>>>>>>>>>> inside my code,( which is probably why there are not many posts on
>>>>>>>>>> this:).
>>>>>>>>>>
>>>>>>>>>> Regards
>>>>>>>>>> Kiren
>>>>>>>>>
>>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>
>>>>
>>>>
>>
>>
Re: Marshalling REST Query Parameter directly into Integer Array
Posted by Kiren Pillay <ki...@gmail.com>.
Thanks Sergei, I was on the wrong track, but thanks to your testcase I
can see now that I should pass in array variables as:
http://localhost:8080/testMyRest/time?index=1&index=2&index=3
and I was trying to achieve this kind of request (more human/tester friendly)
http://localhost:8080/testMyRest/time?index=1,2,3
Regards
Kiren
On Mon, Oct 3, 2011 at 5:11 PM, Sergey Beryozkin <sb...@gmail.com> wrote:
> That works exactly the way I described :-), but you can easily double-check
> it by havubg a breakpoint in
> org.apache.cxf.jaxrs.utils.JAXRSUtils.processParameter and you can see what
> happens by running most of JAXRSUtilsTest, testCustomerParameter is one of
> them
> Sergey
>
> On 03/10/11 15:25, Kiren Pillay wrote:
>>
>> Okay, can you send me the name of a test case in the code where I can
>> see how this works please?
>>
>> Regards
>> Kiren
>>
>>
>> On Mon, Oct 3, 2011 at 10:35 AM, Sergey Beryozkin<sb...@gmail.com>
>> wrote:
>>>
>>> Hi
>>>
>>> When we have List<SomeType>, it is the runtime that manages the
>>> instantiation of List and it would look for ParameterHandler<SomeType>
>>> only if SomeType does not have a suitable constructor or factory method.
>>> It
>>> will also be checked as a last resort if SomeType(String) constructor
>>> throws
>>> an exception, ex, Date(String) is problematic...
>>>
>>> Cheers, Sergey
>>>
>>> On 02/10/11 18:39, Kiren Pillay wrote:
>>>>
>>>> Hi Sergey,
>>>>
>>>> Apologies, I didn't test my app correctly. It looks like the
>>>> ParameterHandler isn't working as it should.
>>>>
>>>> When I use a parameter of 1 for example, then it works. If I use a
>>>> comma-separated list ("1,2,3") it fails saying:
>>>> "02 Oct 2011 7:19:18 PM org.apache.cxf.jaxrs.utils.InjectionUtils
>>>> handleParameter
>>>> SEVERE: Class java.lang.Integer can not be instantiated using a
>>>> constructor with a single String argument"
>>>>
>>>> When debugging, I notice that my custom ParameterHandler is not hit,
>>>> maybe my ParameterHandler is not registered correctly?
>>>>
>>>> Here's my bean config snippet:
>>>> --
>>>>
>>>> <import resource="classpath:META-INF/cxf/cxf.xml"/>
>>>> <context:component-scan base-package="za.co.kiren"/>
>>>>
>>>> <bean id="integerListParameterHandler"
>>>> class="za.co.vodacom.pams.core.common.cxf.IntegerListParameterHandler"
>>>> />
>>>>
>>>>
>>>> <jaxrs:server id="restContainer" address="/">
>>>> <jaxrs:serviceBeans>
>>>> <ref bean="timeService"/>
>>>> </jaxrs:serviceBeans>
>>>> <jaxrs:providers>
>>>> <ref bean="integerListParameterHandler" />
>>>>
>>>> </jaxrs:providers>
>>>> </jaxrs:server>
>>>> </beans>
>>>>
>>>>
>>>> Class:
>>>>
>>>> package za.co.kiren.testMyRest;
>>>>
>>>> import org.springframework.format.datetime.DateFormatter;
>>>> import org.springframework.stereotype.Component;
>>>> import org.springframework.stereotype.Service;
>>>>
>>>> import java.util.Calendar;
>>>> import java.util.List;
>>>> import java.util.Locale;
>>>>
>>>> import javax.ws.rs.GET;
>>>> import javax.ws.rs.Path;
>>>> import javax.ws.rs.Produces;
>>>> import javax.ws.rs.QueryParam;
>>>>
>>>> @Component
>>>> @Service("timeService")
>>>> public class TimeService {
>>>> @GET
>>>> @Produces("text/plain")
>>>> @Path("/time")
>>>> public String getDateTime(@QueryParam("index") List<Integer>
>>>> list)
>>>> {
>>>> String tmp = list.toString();
>>>> /*
>>>> * for (Integer integer : list) { tmp+=":"+integer; }
>>>> */
>>>>
>>>> DateFormatter formatter = new DateFormatter("dd/MM/yyyy
>>>> hh:mm:ss");
>>>>
>>>> return tmp
>>>> +
>>>> formatter.print(Calendar.getInstance().getTime(),
>>>> Locale.getDefault());
>>>> }
>>>> }
>>>>
>>>>
>>>> On Fri, Sep 30, 2011 at 4:47 PM, Kiren Pillay<ki...@gmail.com>
>>>> wrote:
>>>>>
>>>>> Hi Sergery,
>>>>>
>>>>> List<Integer> works well, thanks for your help:)
>>>>>
>>>>> Moved to 2.4.2 also.
>>>>>
>>>>> Regards
>>>>> Kiren
>>>>>
>>>>> On Thu, Sep 29, 2011 at 2:33 PM, Sergey Beryozkin<sb...@gmail.com>
>>>>> wrote:
>>>>>>
>>>>>> Hi
>>>>>>
>>>>>> There was a minor issue to do with handling arrays such as Integer[],
>>>>>> but I
>>>>>> can see no problems with List<Integer>. I committed a test involving
>>>>>> List<Integer> & Integer[].
>>>>>> Not sure why you see a problem with List<Integer>
>>>>>> Can you try 2.4.2 please ?
>>>>>> Sergey
>>>>>>
>>>>>> On 28/09/11 17:34, Kiren Pillay wrote:
>>>>>>>
>>>>>>> Hi Sergey!
>>>>>>>
>>>>>>> Tried int[], got the same error.
>>>>>>>
>>>>>>> <detail>[I cannot be cast to [Ljava.lang.Object;
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> org.apache.cxf.jaxrs.utils.InjectionUtils.addToCollectionValues(InjectionUtils.java:752)
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> org.apache.cxf.jaxrs.utils.InjectionUtils.injectIntoCollectionOrArray(InjectionUtils.java:740)
>>>>>>>
>>>>>>>
>>>>>>> I also tried List<Integer> but that also failed with the same
>>>>>>> error.
>>>>>>>
>>>>>>> Is there anything special with the provider configuration maybe?
>>>>>>> (using
>>>>>>> 2.4.1).
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> On Wed, Sep 28, 2011 at 5:41 PM, Sergey
>>>>>>> Beryozkin<sb...@gmail.com>
>>>>>>> wrote:
>>>>>>>>
>>>>>>>> Hi
>>>>>>>>
>>>>>>>> List<Integer> must be supported, I'll add a test for Integer[],
>>>>>>>> have you
>>>>>>>> tried int[] ?
>>>>>>>>
>>>>>>>> Cheers, Sergey
>>>>>>>>
>>>>>>>> On 28/09/11 15:42, Kiren Pillay wrote:
>>>>>>>>>
>>>>>>>>> Hi
>>>>>>>>>
>>>>>>>>> This is an old problem, but I can't seem to find a solution posted
>>>>>>>>> anywhere. I want to marshall a comma-separated list of integers
>>>>>>>>> directly into an Integer [].
>>>>>>>>>
>>>>>>>>> 1. Service:
>>>>>>>>>
>>>>>>>>> public Response getCounters(
>>>>>>>>> @QueryParam("msisdn") Long msisdn,
>>>>>>>>> @QueryParam("counters") Integer [] counters,
>>>>>>>>> @QueryParam("subscriberIdType") String
>>>>>>>>> subscriberIdType)
>>>>>>>>>
>>>>>>>>> 2. I've written a ParameterHandler for this :
>>>>>>>>>
>>>>>>>>> public class IntegerArrayParameterHandler implements
>>>>>>>>> ParameterHandler<Integer[]> {
>>>>>>>>> @Override
>>>>>>>>> public Integer[] fromString(String arg0) {
>>>>>>>>>
>>>>>>>>> 3. The parameter handler is registered, however its not picked up
>>>>>>>>> when
>>>>>>>>> I do the query:
>>>>>>>>>
>>>>>>>>> <detail>[I cannot be cast to [Ljava.lang.Object;
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> org.apache.cxf.jaxrs.utils.InjectionUtils.addToCollectionValues(InjectionUtils.java:752)
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> org.apache.cxf.jaxrs.utils.InjectionUtils.injectIntoCollectionOrArray(InjectionUtils.java:740)
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> org.apache.cxf.jaxrs.utils.InjectionUtils.createParameterObject(InjectionUtils.java:807)
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> org.apache.cxf.jaxrs.utils.JAXRSUtils.readQueryString(JAXRSUtils.java:947)
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> org.apache.cxf.jaxrs.utils.JAXRSUtils.createHttpParameterValue(JAXRSUtils.java:649)
>>>>>>>>>
>>>>>>>>> Is there a way to get this to work?
>>>>>>>>>
>>>>>>>>> 4. I've Registered the Provider:
>>>>>>>>> ----
>>>>>>>>> <ref bean="integerArrayParameterHandler" />
>>>>>>>>> </jaxrs:providers>
>>>>>>>>>
>>>>>>>>> The easiest solution is to just use the String value and parse it
>>>>>>>>> inside my code,( which is probably why there are not many posts on
>>>>>>>>> this:).
>>>>>>>>>
>>>>>>>>> Regards
>>>>>>>>> Kiren
>>>>>>>>
>>>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>
>>>
>
>
Re: Marshalling REST Query Parameter directly into Integer Array
Posted by Sergey Beryozkin <sb...@gmail.com>.
That works exactly the way I described :-), but you can easily
double-check it by havubg a breakpoint in
org.apache.cxf.jaxrs.utils.JAXRSUtils.processParameter and you can see
what happens by running most of JAXRSUtilsTest, testCustomerParameter is
one of them
Sergey
On 03/10/11 15:25, Kiren Pillay wrote:
> Okay, can you send me the name of a test case in the code where I can
> see how this works please?
>
> Regards
> Kiren
>
>
> On Mon, Oct 3, 2011 at 10:35 AM, Sergey Beryozkin<sb...@gmail.com> wrote:
>> Hi
>>
>> When we have List<SomeType>, it is the runtime that manages the
>> instantiation of List and it would look for ParameterHandler<SomeType>
>> only if SomeType does not have a suitable constructor or factory method. It
>> will also be checked as a last resort if SomeType(String) constructor throws
>> an exception, ex, Date(String) is problematic...
>>
>> Cheers, Sergey
>>
>> On 02/10/11 18:39, Kiren Pillay wrote:
>>>
>>> Hi Sergey,
>>>
>>> Apologies, I didn't test my app correctly. It looks like the
>>> ParameterHandler isn't working as it should.
>>>
>>> When I use a parameter of 1 for example, then it works. If I use a
>>> comma-separated list ("1,2,3") it fails saying:
>>> "02 Oct 2011 7:19:18 PM org.apache.cxf.jaxrs.utils.InjectionUtils
>>> handleParameter
>>> SEVERE: Class java.lang.Integer can not be instantiated using a
>>> constructor with a single String argument"
>>>
>>> When debugging, I notice that my custom ParameterHandler is not hit,
>>> maybe my ParameterHandler is not registered correctly?
>>>
>>> Here's my bean config snippet:
>>> --
>>>
>>> <import resource="classpath:META-INF/cxf/cxf.xml"/>
>>> <context:component-scan base-package="za.co.kiren"/>
>>>
>>> <bean id="integerListParameterHandler"
>>> class="za.co.vodacom.pams.core.common.cxf.IntegerListParameterHandler"
>>> />
>>>
>>>
>>> <jaxrs:server id="restContainer" address="/">
>>> <jaxrs:serviceBeans>
>>> <ref bean="timeService"/>
>>> </jaxrs:serviceBeans>
>>> <jaxrs:providers>
>>> <ref bean="integerListParameterHandler" />
>>>
>>> </jaxrs:providers>
>>> </jaxrs:server>
>>> </beans>
>>>
>>>
>>> Class:
>>>
>>> package za.co.kiren.testMyRest;
>>>
>>> import org.springframework.format.datetime.DateFormatter;
>>> import org.springframework.stereotype.Component;
>>> import org.springframework.stereotype.Service;
>>>
>>> import java.util.Calendar;
>>> import java.util.List;
>>> import java.util.Locale;
>>>
>>> import javax.ws.rs.GET;
>>> import javax.ws.rs.Path;
>>> import javax.ws.rs.Produces;
>>> import javax.ws.rs.QueryParam;
>>>
>>> @Component
>>> @Service("timeService")
>>> public class TimeService {
>>> @GET
>>> @Produces("text/plain")
>>> @Path("/time")
>>> public String getDateTime(@QueryParam("index") List<Integer> list)
>>> {
>>> String tmp = list.toString();
>>> /*
>>> * for (Integer integer : list) { tmp+=":"+integer; }
>>> */
>>>
>>> DateFormatter formatter = new DateFormatter("dd/MM/yyyy
>>> hh:mm:ss");
>>>
>>> return tmp
>>> +
>>> formatter.print(Calendar.getInstance().getTime(),
>>> Locale.getDefault());
>>> }
>>> }
>>>
>>>
>>> On Fri, Sep 30, 2011 at 4:47 PM, Kiren Pillay<ki...@gmail.com>
>>> wrote:
>>>>
>>>> Hi Sergery,
>>>>
>>>> List<Integer> works well, thanks for your help:)
>>>>
>>>> Moved to 2.4.2 also.
>>>>
>>>> Regards
>>>> Kiren
>>>>
>>>> On Thu, Sep 29, 2011 at 2:33 PM, Sergey Beryozkin<sb...@gmail.com>
>>>> wrote:
>>>>>
>>>>> Hi
>>>>>
>>>>> There was a minor issue to do with handling arrays such as Integer[],
>>>>> but I
>>>>> can see no problems with List<Integer>. I committed a test involving
>>>>> List<Integer> & Integer[].
>>>>> Not sure why you see a problem with List<Integer>
>>>>> Can you try 2.4.2 please ?
>>>>> Sergey
>>>>>
>>>>> On 28/09/11 17:34, Kiren Pillay wrote:
>>>>>>
>>>>>> Hi Sergey!
>>>>>>
>>>>>> Tried int[], got the same error.
>>>>>>
>>>>>> <detail>[I cannot be cast to [Ljava.lang.Object;
>>>>>>
>>>>>>
>>>>>> org.apache.cxf.jaxrs.utils.InjectionUtils.addToCollectionValues(InjectionUtils.java:752)
>>>>>>
>>>>>>
>>>>>> org.apache.cxf.jaxrs.utils.InjectionUtils.injectIntoCollectionOrArray(InjectionUtils.java:740)
>>>>>>
>>>>>>
>>>>>> I also tried List<Integer> but that also failed with the same error.
>>>>>>
>>>>>> Is there anything special with the provider configuration maybe? (using
>>>>>> 2.4.1).
>>>>>>
>>>>>>
>>>>>>
>>>>>> On Wed, Sep 28, 2011 at 5:41 PM, Sergey Beryozkin<sb...@gmail.com>
>>>>>> wrote:
>>>>>>>
>>>>>>> Hi
>>>>>>>
>>>>>>> List<Integer> must be supported, I'll add a test for Integer[],
>>>>>>> have you
>>>>>>> tried int[] ?
>>>>>>>
>>>>>>> Cheers, Sergey
>>>>>>>
>>>>>>> On 28/09/11 15:42, Kiren Pillay wrote:
>>>>>>>>
>>>>>>>> Hi
>>>>>>>>
>>>>>>>> This is an old problem, but I can't seem to find a solution posted
>>>>>>>> anywhere. I want to marshall a comma-separated list of integers
>>>>>>>> directly into an Integer [].
>>>>>>>>
>>>>>>>> 1. Service:
>>>>>>>>
>>>>>>>> public Response getCounters(
>>>>>>>> @QueryParam("msisdn") Long msisdn,
>>>>>>>> @QueryParam("counters") Integer [] counters,
>>>>>>>> @QueryParam("subscriberIdType") String subscriberIdType)
>>>>>>>>
>>>>>>>> 2. I've written a ParameterHandler for this :
>>>>>>>>
>>>>>>>> public class IntegerArrayParameterHandler implements
>>>>>>>> ParameterHandler<Integer[]> {
>>>>>>>> @Override
>>>>>>>> public Integer[] fromString(String arg0) {
>>>>>>>>
>>>>>>>> 3. The parameter handler is registered, however its not picked up
>>>>>>>> when
>>>>>>>> I do the query:
>>>>>>>>
>>>>>>>> <detail>[I cannot be cast to [Ljava.lang.Object;
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> org.apache.cxf.jaxrs.utils.InjectionUtils.addToCollectionValues(InjectionUtils.java:752)
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> org.apache.cxf.jaxrs.utils.InjectionUtils.injectIntoCollectionOrArray(InjectionUtils.java:740)
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> org.apache.cxf.jaxrs.utils.InjectionUtils.createParameterObject(InjectionUtils.java:807)
>>>>>>>>
>>>>>>>>
>>>>>>>> org.apache.cxf.jaxrs.utils.JAXRSUtils.readQueryString(JAXRSUtils.java:947)
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> org.apache.cxf.jaxrs.utils.JAXRSUtils.createHttpParameterValue(JAXRSUtils.java:649)
>>>>>>>>
>>>>>>>> Is there a way to get this to work?
>>>>>>>>
>>>>>>>> 4. I've Registered the Provider:
>>>>>>>> ----
>>>>>>>> <ref bean="integerArrayParameterHandler" />
>>>>>>>> </jaxrs:providers>
>>>>>>>>
>>>>>>>> The easiest solution is to just use the String value and parse it
>>>>>>>> inside my code,( which is probably why there are not many posts on
>>>>>>>> this:).
>>>>>>>>
>>>>>>>> Regards
>>>>>>>> Kiren
>>>>>>>
>>>>>>>
>>>>>
>>>>>
>>>>
>>
>>
Re: Marshalling REST Query Parameter directly into Integer Array
Posted by Kiren Pillay <ki...@gmail.com>.
Okay, can you send me the name of a test case in the code where I can
see how this works please?
Regards
Kiren
On Mon, Oct 3, 2011 at 10:35 AM, Sergey Beryozkin <sb...@gmail.com> wrote:
> Hi
>
> When we have List<SomeType>, it is the runtime that manages the
> instantiation of List and it would look for ParameterHandler<SomeType>
> only if SomeType does not have a suitable constructor or factory method. It
> will also be checked as a last resort if SomeType(String) constructor throws
> an exception, ex, Date(String) is problematic...
>
> Cheers, Sergey
>
> On 02/10/11 18:39, Kiren Pillay wrote:
>>
>> Hi Sergey,
>>
>> Apologies, I didn't test my app correctly. It looks like the
>> ParameterHandler isn't working as it should.
>>
>> When I use a parameter of 1 for example, then it works. If I use a
>> comma-separated list ("1,2,3") it fails saying:
>> "02 Oct 2011 7:19:18 PM org.apache.cxf.jaxrs.utils.InjectionUtils
>> handleParameter
>> SEVERE: Class java.lang.Integer can not be instantiated using a
>> constructor with a single String argument"
>>
>> When debugging, I notice that my custom ParameterHandler is not hit,
>> maybe my ParameterHandler is not registered correctly?
>>
>> Here's my bean config snippet:
>> --
>>
>> <import resource="classpath:META-INF/cxf/cxf.xml"/>
>> <context:component-scan base-package="za.co.kiren"/>
>>
>> <bean id="integerListParameterHandler"
>> class="za.co.vodacom.pams.core.common.cxf.IntegerListParameterHandler"
>> />
>>
>>
>> <jaxrs:server id="restContainer" address="/">
>> <jaxrs:serviceBeans>
>> <ref bean="timeService"/>
>> </jaxrs:serviceBeans>
>> <jaxrs:providers>
>> <ref bean="integerListParameterHandler" />
>>
>> </jaxrs:providers>
>> </jaxrs:server>
>> </beans>
>>
>>
>> Class:
>>
>> package za.co.kiren.testMyRest;
>>
>> import org.springframework.format.datetime.DateFormatter;
>> import org.springframework.stereotype.Component;
>> import org.springframework.stereotype.Service;
>>
>> import java.util.Calendar;
>> import java.util.List;
>> import java.util.Locale;
>>
>> import javax.ws.rs.GET;
>> import javax.ws.rs.Path;
>> import javax.ws.rs.Produces;
>> import javax.ws.rs.QueryParam;
>>
>> @Component
>> @Service("timeService")
>> public class TimeService {
>> @GET
>> @Produces("text/plain")
>> @Path("/time")
>> public String getDateTime(@QueryParam("index") List<Integer> list)
>> {
>> String tmp = list.toString();
>> /*
>> * for (Integer integer : list) { tmp+=":"+integer; }
>> */
>>
>> DateFormatter formatter = new DateFormatter("dd/MM/yyyy
>> hh:mm:ss");
>>
>> return tmp
>> +
>> formatter.print(Calendar.getInstance().getTime(),
>> Locale.getDefault());
>> }
>> }
>>
>>
>> On Fri, Sep 30, 2011 at 4:47 PM, Kiren Pillay<ki...@gmail.com>
>> wrote:
>>>
>>> Hi Sergery,
>>>
>>> List<Integer> works well, thanks for your help:)
>>>
>>> Moved to 2.4.2 also.
>>>
>>> Regards
>>> Kiren
>>>
>>> On Thu, Sep 29, 2011 at 2:33 PM, Sergey Beryozkin<sb...@gmail.com>
>>> wrote:
>>>>
>>>> Hi
>>>>
>>>> There was a minor issue to do with handling arrays such as Integer[],
>>>> but I
>>>> can see no problems with List<Integer>. I committed a test involving
>>>> List<Integer> & Integer[].
>>>> Not sure why you see a problem with List<Integer>
>>>> Can you try 2.4.2 please ?
>>>> Sergey
>>>>
>>>> On 28/09/11 17:34, Kiren Pillay wrote:
>>>>>
>>>>> Hi Sergey!
>>>>>
>>>>> Tried int[], got the same error.
>>>>>
>>>>> <detail>[I cannot be cast to [Ljava.lang.Object;
>>>>>
>>>>>
>>>>> org.apache.cxf.jaxrs.utils.InjectionUtils.addToCollectionValues(InjectionUtils.java:752)
>>>>>
>>>>>
>>>>> org.apache.cxf.jaxrs.utils.InjectionUtils.injectIntoCollectionOrArray(InjectionUtils.java:740)
>>>>>
>>>>>
>>>>> I also tried List<Integer> but that also failed with the same error.
>>>>>
>>>>> Is there anything special with the provider configuration maybe? (using
>>>>> 2.4.1).
>>>>>
>>>>>
>>>>>
>>>>> On Wed, Sep 28, 2011 at 5:41 PM, Sergey Beryozkin<sb...@gmail.com>
>>>>> wrote:
>>>>>>
>>>>>> Hi
>>>>>>
>>>>>> List<Integer> must be supported, I'll add a test for Integer[],
>>>>>> have you
>>>>>> tried int[] ?
>>>>>>
>>>>>> Cheers, Sergey
>>>>>>
>>>>>> On 28/09/11 15:42, Kiren Pillay wrote:
>>>>>>>
>>>>>>> Hi
>>>>>>>
>>>>>>> This is an old problem, but I can't seem to find a solution posted
>>>>>>> anywhere. I want to marshall a comma-separated list of integers
>>>>>>> directly into an Integer [].
>>>>>>>
>>>>>>> 1. Service:
>>>>>>>
>>>>>>> public Response getCounters(
>>>>>>> @QueryParam("msisdn") Long msisdn,
>>>>>>> @QueryParam("counters") Integer [] counters,
>>>>>>> @QueryParam("subscriberIdType") String subscriberIdType)
>>>>>>>
>>>>>>> 2. I've written a ParameterHandler for this :
>>>>>>>
>>>>>>> public class IntegerArrayParameterHandler implements
>>>>>>> ParameterHandler<Integer[]> {
>>>>>>> @Override
>>>>>>> public Integer[] fromString(String arg0) {
>>>>>>>
>>>>>>> 3. The parameter handler is registered, however its not picked up
>>>>>>> when
>>>>>>> I do the query:
>>>>>>>
>>>>>>> <detail>[I cannot be cast to [Ljava.lang.Object;
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> org.apache.cxf.jaxrs.utils.InjectionUtils.addToCollectionValues(InjectionUtils.java:752)
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> org.apache.cxf.jaxrs.utils.InjectionUtils.injectIntoCollectionOrArray(InjectionUtils.java:740)
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> org.apache.cxf.jaxrs.utils.InjectionUtils.createParameterObject(InjectionUtils.java:807)
>>>>>>>
>>>>>>>
>>>>>>> org.apache.cxf.jaxrs.utils.JAXRSUtils.readQueryString(JAXRSUtils.java:947)
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> org.apache.cxf.jaxrs.utils.JAXRSUtils.createHttpParameterValue(JAXRSUtils.java:649)
>>>>>>>
>>>>>>> Is there a way to get this to work?
>>>>>>>
>>>>>>> 4. I've Registered the Provider:
>>>>>>> ----
>>>>>>> <ref bean="integerArrayParameterHandler" />
>>>>>>> </jaxrs:providers>
>>>>>>>
>>>>>>> The easiest solution is to just use the String value and parse it
>>>>>>> inside my code,( which is probably why there are not many posts on
>>>>>>> this:).
>>>>>>>
>>>>>>> Regards
>>>>>>> Kiren
>>>>>>
>>>>>>
>>>>
>>>>
>>>
>
>
Re: Marshalling REST Query Parameter directly into Integer Array
Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi
When we have List<SomeType>, it is the runtime that manages the
instantiation of List and it would look for ParameterHandler<SomeType>
only if SomeType does not have a suitable constructor or factory method.
It will also be checked as a last resort if SomeType(String) constructor
throws an exception, ex, Date(String) is problematic...
Cheers, Sergey
On 02/10/11 18:39, Kiren Pillay wrote:
> Hi Sergey,
>
> Apologies, I didn't test my app correctly. It looks like the
> ParameterHandler isn't working as it should.
>
> When I use a parameter of 1 for example, then it works. If I use a
> comma-separated list ("1,2,3") it fails saying:
> "02 Oct 2011 7:19:18 PM org.apache.cxf.jaxrs.utils.InjectionUtils
> handleParameter
> SEVERE: Class java.lang.Integer can not be instantiated using a
> constructor with a single String argument"
>
> When debugging, I notice that my custom ParameterHandler is not hit,
> maybe my ParameterHandler is not registered correctly?
>
> Here's my bean config snippet:
> --
>
> <import resource="classpath:META-INF/cxf/cxf.xml"/>
> <context:component-scan base-package="za.co.kiren"/>
>
> <bean id="integerListParameterHandler"
> class="za.co.vodacom.pams.core.common.cxf.IntegerListParameterHandler"
> />
>
>
> <jaxrs:server id="restContainer" address="/">
> <jaxrs:serviceBeans>
> <ref bean="timeService"/>
> </jaxrs:serviceBeans>
> <jaxrs:providers>
> <ref bean="integerListParameterHandler" />
>
> </jaxrs:providers>
> </jaxrs:server>
> </beans>
>
>
> Class:
>
> package za.co.kiren.testMyRest;
>
> import org.springframework.format.datetime.DateFormatter;
> import org.springframework.stereotype.Component;
> import org.springframework.stereotype.Service;
>
> import java.util.Calendar;
> import java.util.List;
> import java.util.Locale;
>
> import javax.ws.rs.GET;
> import javax.ws.rs.Path;
> import javax.ws.rs.Produces;
> import javax.ws.rs.QueryParam;
>
> @Component
> @Service("timeService")
> public class TimeService {
> @GET
> @Produces("text/plain")
> @Path("/time")
> public String getDateTime(@QueryParam("index") List<Integer> list) {
> String tmp = list.toString();
> /*
> * for (Integer integer : list) { tmp+=":"+integer; }
> */
>
> DateFormatter formatter = new DateFormatter("dd/MM/yyyy hh:mm:ss");
>
> return tmp
> + formatter.print(Calendar.getInstance().getTime(),
> Locale.getDefault());
> }
> }
>
>
> On Fri, Sep 30, 2011 at 4:47 PM, Kiren Pillay<ki...@gmail.com> wrote:
>> Hi Sergery,
>>
>> List<Integer> works well, thanks for your help:)
>>
>> Moved to 2.4.2 also.
>>
>> Regards
>> Kiren
>>
>> On Thu, Sep 29, 2011 at 2:33 PM, Sergey Beryozkin<sb...@gmail.com> wrote:
>>> Hi
>>>
>>> There was a minor issue to do with handling arrays such as Integer[], but I
>>> can see no problems with List<Integer>. I committed a test involving
>>> List<Integer> & Integer[].
>>> Not sure why you see a problem with List<Integer>
>>> Can you try 2.4.2 please ?
>>> Sergey
>>>
>>> On 28/09/11 17:34, Kiren Pillay wrote:
>>>>
>>>> Hi Sergey!
>>>>
>>>> Tried int[], got the same error.
>>>>
>>>> <detail>[I cannot be cast to [Ljava.lang.Object;
>>>>
>>>> org.apache.cxf.jaxrs.utils.InjectionUtils.addToCollectionValues(InjectionUtils.java:752)
>>>>
>>>> org.apache.cxf.jaxrs.utils.InjectionUtils.injectIntoCollectionOrArray(InjectionUtils.java:740)
>>>>
>>>>
>>>> I also tried List<Integer> but that also failed with the same error.
>>>>
>>>> Is there anything special with the provider configuration maybe? (using
>>>> 2.4.1).
>>>>
>>>>
>>>>
>>>> On Wed, Sep 28, 2011 at 5:41 PM, Sergey Beryozkin<sb...@gmail.com>
>>>> wrote:
>>>>>
>>>>> Hi
>>>>>
>>>>> List<Integer> must be supported, I'll add a test for Integer[], have you
>>>>> tried int[] ?
>>>>>
>>>>> Cheers, Sergey
>>>>>
>>>>> On 28/09/11 15:42, Kiren Pillay wrote:
>>>>>>
>>>>>> Hi
>>>>>>
>>>>>> This is an old problem, but I can't seem to find a solution posted
>>>>>> anywhere. I want to marshall a comma-separated list of integers
>>>>>> directly into an Integer [].
>>>>>>
>>>>>> 1. Service:
>>>>>>
>>>>>> public Response getCounters(
>>>>>> @QueryParam("msisdn") Long msisdn,
>>>>>> @QueryParam("counters") Integer [] counters,
>>>>>> @QueryParam("subscriberIdType") String subscriberIdType)
>>>>>>
>>>>>> 2. I've written a ParameterHandler for this :
>>>>>>
>>>>>> public class IntegerArrayParameterHandler implements
>>>>>> ParameterHandler<Integer[]> {
>>>>>> @Override
>>>>>> public Integer[] fromString(String arg0) {
>>>>>>
>>>>>> 3. The parameter handler is registered, however its not picked up when
>>>>>> I do the query:
>>>>>>
>>>>>> <detail>[I cannot be cast to [Ljava.lang.Object;
>>>>>>
>>>>>>
>>>>>> org.apache.cxf.jaxrs.utils.InjectionUtils.addToCollectionValues(InjectionUtils.java:752)
>>>>>>
>>>>>>
>>>>>> org.apache.cxf.jaxrs.utils.InjectionUtils.injectIntoCollectionOrArray(InjectionUtils.java:740)
>>>>>>
>>>>>>
>>>>>> org.apache.cxf.jaxrs.utils.InjectionUtils.createParameterObject(InjectionUtils.java:807)
>>>>>>
>>>>>> org.apache.cxf.jaxrs.utils.JAXRSUtils.readQueryString(JAXRSUtils.java:947)
>>>>>>
>>>>>>
>>>>>> org.apache.cxf.jaxrs.utils.JAXRSUtils.createHttpParameterValue(JAXRSUtils.java:649)
>>>>>>
>>>>>> Is there a way to get this to work?
>>>>>>
>>>>>> 4. I've Registered the Provider:
>>>>>> ----
>>>>>> <ref bean="integerArrayParameterHandler" />
>>>>>> </jaxrs:providers>
>>>>>>
>>>>>> The easiest solution is to just use the String value and parse it
>>>>>> inside my code,( which is probably why there are not many posts on
>>>>>> this:).
>>>>>>
>>>>>> Regards
>>>>>> Kiren
>>>>>
>>>>>
>>>
>>>
>>
Re: Marshalling REST Query Parameter directly into Integer Array
Posted by Kiren Pillay <ki...@gmail.com>.
Hi Sergey,
Apologies, I didn't test my app correctly. It looks like the
ParameterHandler isn't working as it should.
When I use a parameter of 1 for example, then it works. If I use a
comma-separated list ("1,2,3") it fails saying:
"02 Oct 2011 7:19:18 PM org.apache.cxf.jaxrs.utils.InjectionUtils
handleParameter
SEVERE: Class java.lang.Integer can not be instantiated using a
constructor with a single String argument"
When debugging, I notice that my custom ParameterHandler is not hit,
maybe my ParameterHandler is not registered correctly?
Here's my bean config snippet:
--
<import resource="classpath:META-INF/cxf/cxf.xml"/>
<context:component-scan base-package="za.co.kiren"/>
<bean id="integerListParameterHandler"
class="za.co.vodacom.pams.core.common.cxf.IntegerListParameterHandler"
/>
<jaxrs:server id="restContainer" address="/">
<jaxrs:serviceBeans>
<ref bean="timeService"/>
</jaxrs:serviceBeans>
<jaxrs:providers>
<ref bean="integerListParameterHandler" />
</jaxrs:providers>
</jaxrs:server>
</beans>
Class:
package za.co.kiren.testMyRest;
import org.springframework.format.datetime.DateFormatter;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import java.util.Calendar;
import java.util.List;
import java.util.Locale;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
@Component
@Service("timeService")
public class TimeService {
@GET
@Produces("text/plain")
@Path("/time")
public String getDateTime(@QueryParam("index") List<Integer> list) {
String tmp = list.toString();
/*
* for (Integer integer : list) { tmp+=":"+integer; }
*/
DateFormatter formatter = new DateFormatter("dd/MM/yyyy hh:mm:ss");
return tmp
+ formatter.print(Calendar.getInstance().getTime(),
Locale.getDefault());
}
}
On Fri, Sep 30, 2011 at 4:47 PM, Kiren Pillay <ki...@gmail.com> wrote:
> Hi Sergery,
>
> List<Integer> works well, thanks for your help:)
>
> Moved to 2.4.2 also.
>
> Regards
> Kiren
>
> On Thu, Sep 29, 2011 at 2:33 PM, Sergey Beryozkin <sb...@gmail.com> wrote:
>> Hi
>>
>> There was a minor issue to do with handling arrays such as Integer[], but I
>> can see no problems with List<Integer>. I committed a test involving
>> List<Integer> & Integer[].
>> Not sure why you see a problem with List<Integer>
>> Can you try 2.4.2 please ?
>> Sergey
>>
>> On 28/09/11 17:34, Kiren Pillay wrote:
>>>
>>> Hi Sergey!
>>>
>>> Tried int[], got the same error.
>>>
>>> <detail>[I cannot be cast to [Ljava.lang.Object;
>>>
>>> org.apache.cxf.jaxrs.utils.InjectionUtils.addToCollectionValues(InjectionUtils.java:752)
>>>
>>> org.apache.cxf.jaxrs.utils.InjectionUtils.injectIntoCollectionOrArray(InjectionUtils.java:740)
>>>
>>>
>>> I also tried List<Integer> but that also failed with the same error.
>>>
>>> Is there anything special with the provider configuration maybe? (using
>>> 2.4.1).
>>>
>>>
>>>
>>> On Wed, Sep 28, 2011 at 5:41 PM, Sergey Beryozkin<sb...@gmail.com>
>>> wrote:
>>>>
>>>> Hi
>>>>
>>>> List<Integer> must be supported, I'll add a test for Integer[], have you
>>>> tried int[] ?
>>>>
>>>> Cheers, Sergey
>>>>
>>>> On 28/09/11 15:42, Kiren Pillay wrote:
>>>>>
>>>>> Hi
>>>>>
>>>>> This is an old problem, but I can't seem to find a solution posted
>>>>> anywhere. I want to marshall a comma-separated list of integers
>>>>> directly into an Integer [].
>>>>>
>>>>> 1. Service:
>>>>>
>>>>> public Response getCounters(
>>>>> @QueryParam("msisdn") Long msisdn,
>>>>> @QueryParam("counters") Integer [] counters,
>>>>> @QueryParam("subscriberIdType") String subscriberIdType)
>>>>>
>>>>> 2. I've written a ParameterHandler for this :
>>>>>
>>>>> public class IntegerArrayParameterHandler implements
>>>>> ParameterHandler<Integer[]> {
>>>>> @Override
>>>>> public Integer[] fromString(String arg0) {
>>>>>
>>>>> 3. The parameter handler is registered, however its not picked up when
>>>>> I do the query:
>>>>>
>>>>> <detail>[I cannot be cast to [Ljava.lang.Object;
>>>>>
>>>>>
>>>>> org.apache.cxf.jaxrs.utils.InjectionUtils.addToCollectionValues(InjectionUtils.java:752)
>>>>>
>>>>>
>>>>> org.apache.cxf.jaxrs.utils.InjectionUtils.injectIntoCollectionOrArray(InjectionUtils.java:740)
>>>>>
>>>>>
>>>>> org.apache.cxf.jaxrs.utils.InjectionUtils.createParameterObject(InjectionUtils.java:807)
>>>>>
>>>>> org.apache.cxf.jaxrs.utils.JAXRSUtils.readQueryString(JAXRSUtils.java:947)
>>>>>
>>>>>
>>>>> org.apache.cxf.jaxrs.utils.JAXRSUtils.createHttpParameterValue(JAXRSUtils.java:649)
>>>>>
>>>>> Is there a way to get this to work?
>>>>>
>>>>> 4. I've Registered the Provider:
>>>>> ----
>>>>> <ref bean="integerArrayParameterHandler" />
>>>>> </jaxrs:providers>
>>>>>
>>>>> The easiest solution is to just use the String value and parse it
>>>>> inside my code,( which is probably why there are not many posts on
>>>>> this:).
>>>>>
>>>>> Regards
>>>>> Kiren
>>>>
>>>>
>>
>>
>
Re: Marshalling REST Query Parameter directly into Integer Array
Posted by Kiren Pillay <ki...@gmail.com>.
Hi Sergery,
List<Integer> works well, thanks for your help:)
Moved to 2.4.2 also.
Regards
Kiren
On Thu, Sep 29, 2011 at 2:33 PM, Sergey Beryozkin <sb...@gmail.com> wrote:
> Hi
>
> There was a minor issue to do with handling arrays such as Integer[], but I
> can see no problems with List<Integer>. I committed a test involving
> List<Integer> & Integer[].
> Not sure why you see a problem with List<Integer>
> Can you try 2.4.2 please ?
> Sergey
>
> On 28/09/11 17:34, Kiren Pillay wrote:
>>
>> Hi Sergey!
>>
>> Tried int[], got the same error.
>>
>> <detail>[I cannot be cast to [Ljava.lang.Object;
>>
>> org.apache.cxf.jaxrs.utils.InjectionUtils.addToCollectionValues(InjectionUtils.java:752)
>>
>> org.apache.cxf.jaxrs.utils.InjectionUtils.injectIntoCollectionOrArray(InjectionUtils.java:740)
>>
>>
>> I also tried List<Integer> but that also failed with the same error.
>>
>> Is there anything special with the provider configuration maybe? (using
>> 2.4.1).
>>
>>
>>
>> On Wed, Sep 28, 2011 at 5:41 PM, Sergey Beryozkin<sb...@gmail.com>
>> wrote:
>>>
>>> Hi
>>>
>>> List<Integer> must be supported, I'll add a test for Integer[], have you
>>> tried int[] ?
>>>
>>> Cheers, Sergey
>>>
>>> On 28/09/11 15:42, Kiren Pillay wrote:
>>>>
>>>> Hi
>>>>
>>>> This is an old problem, but I can't seem to find a solution posted
>>>> anywhere. I want to marshall a comma-separated list of integers
>>>> directly into an Integer [].
>>>>
>>>> 1. Service:
>>>>
>>>> public Response getCounters(
>>>> @QueryParam("msisdn") Long msisdn,
>>>> @QueryParam("counters") Integer [] counters,
>>>> @QueryParam("subscriberIdType") String subscriberIdType)
>>>>
>>>> 2. I've written a ParameterHandler for this :
>>>>
>>>> public class IntegerArrayParameterHandler implements
>>>> ParameterHandler<Integer[]> {
>>>> @Override
>>>> public Integer[] fromString(String arg0) {
>>>>
>>>> 3. The parameter handler is registered, however its not picked up when
>>>> I do the query:
>>>>
>>>> <detail>[I cannot be cast to [Ljava.lang.Object;
>>>>
>>>>
>>>> org.apache.cxf.jaxrs.utils.InjectionUtils.addToCollectionValues(InjectionUtils.java:752)
>>>>
>>>>
>>>> org.apache.cxf.jaxrs.utils.InjectionUtils.injectIntoCollectionOrArray(InjectionUtils.java:740)
>>>>
>>>>
>>>> org.apache.cxf.jaxrs.utils.InjectionUtils.createParameterObject(InjectionUtils.java:807)
>>>>
>>>> org.apache.cxf.jaxrs.utils.JAXRSUtils.readQueryString(JAXRSUtils.java:947)
>>>>
>>>>
>>>> org.apache.cxf.jaxrs.utils.JAXRSUtils.createHttpParameterValue(JAXRSUtils.java:649)
>>>>
>>>> Is there a way to get this to work?
>>>>
>>>> 4. I've Registered the Provider:
>>>> ----
>>>> <ref bean="integerArrayParameterHandler" />
>>>> </jaxrs:providers>
>>>>
>>>> The easiest solution is to just use the String value and parse it
>>>> inside my code,( which is probably why there are not many posts on
>>>> this:).
>>>>
>>>> Regards
>>>> Kiren
>>>
>>>
>
>
Re: Marshalling REST Query Parameter directly into Integer Array
Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi
There was a minor issue to do with handling arrays such as Integer[],
but I can see no problems with List<Integer>. I committed a test
involving List<Integer> & Integer[].
Not sure why you see a problem with List<Integer>
Can you try 2.4.2 please ?
Sergey
On 28/09/11 17:34, Kiren Pillay wrote:
> Hi Sergey!
>
> Tried int[], got the same error.
>
> <detail>[I cannot be cast to [Ljava.lang.Object;
> org.apache.cxf.jaxrs.utils.InjectionUtils.addToCollectionValues(InjectionUtils.java:752)
> org.apache.cxf.jaxrs.utils.InjectionUtils.injectIntoCollectionOrArray(InjectionUtils.java:740)
>
>
> I also tried List<Integer> but that also failed with the same error.
>
> Is there anything special with the provider configuration maybe? (using 2.4.1).
>
>
>
> On Wed, Sep 28, 2011 at 5:41 PM, Sergey Beryozkin<sb...@gmail.com> wrote:
>> Hi
>>
>> List<Integer> must be supported, I'll add a test for Integer[], have you
>> tried int[] ?
>>
>> Cheers, Sergey
>>
>> On 28/09/11 15:42, Kiren Pillay wrote:
>>>
>>> Hi
>>>
>>> This is an old problem, but I can't seem to find a solution posted
>>> anywhere. I want to marshall a comma-separated list of integers
>>> directly into an Integer [].
>>>
>>> 1. Service:
>>>
>>> public Response getCounters(
>>> @QueryParam("msisdn") Long msisdn,
>>> @QueryParam("counters") Integer [] counters,
>>> @QueryParam("subscriberIdType") String subscriberIdType)
>>>
>>> 2. I've written a ParameterHandler for this :
>>>
>>> public class IntegerArrayParameterHandler implements
>>> ParameterHandler<Integer[]> {
>>> @Override
>>> public Integer[] fromString(String arg0) {
>>>
>>> 3. The parameter handler is registered, however its not picked up when
>>> I do the query:
>>>
>>> <detail>[I cannot be cast to [Ljava.lang.Object;
>>>
>>> org.apache.cxf.jaxrs.utils.InjectionUtils.addToCollectionValues(InjectionUtils.java:752)
>>>
>>> org.apache.cxf.jaxrs.utils.InjectionUtils.injectIntoCollectionOrArray(InjectionUtils.java:740)
>>>
>>> org.apache.cxf.jaxrs.utils.InjectionUtils.createParameterObject(InjectionUtils.java:807)
>>> org.apache.cxf.jaxrs.utils.JAXRSUtils.readQueryString(JAXRSUtils.java:947)
>>>
>>> org.apache.cxf.jaxrs.utils.JAXRSUtils.createHttpParameterValue(JAXRSUtils.java:649)
>>>
>>> Is there a way to get this to work?
>>>
>>> 4. I've Registered the Provider:
>>> ----
>>> <ref bean="integerArrayParameterHandler" />
>>> </jaxrs:providers>
>>>
>>> The easiest solution is to just use the String value and parse it
>>> inside my code,( which is probably why there are not many posts on
>>> this:).
>>>
>>> Regards
>>> Kiren
>>
>>
Re: Marshalling REST Query Parameter directly into Integer Array
Posted by Kiren Pillay <ki...@gmail.com>.
Hi Sergey!
Tried int[], got the same error.
<detail>[I cannot be cast to [Ljava.lang.Object;
org.apache.cxf.jaxrs.utils.InjectionUtils.addToCollectionValues(InjectionUtils.java:752)
org.apache.cxf.jaxrs.utils.InjectionUtils.injectIntoCollectionOrArray(InjectionUtils.java:740)
I also tried List<Integer> but that also failed with the same error.
Is there anything special with the provider configuration maybe? (using 2.4.1).
On Wed, Sep 28, 2011 at 5:41 PM, Sergey Beryozkin <sb...@gmail.com> wrote:
> Hi
>
> List<Integer> must be supported, I'll add a test for Integer[], have you
> tried int[] ?
>
> Cheers, Sergey
>
> On 28/09/11 15:42, Kiren Pillay wrote:
>>
>> Hi
>>
>> This is an old problem, but I can't seem to find a solution posted
>> anywhere. I want to marshall a comma-separated list of integers
>> directly into an Integer [].
>>
>> 1. Service:
>>
>> public Response getCounters(
>> @QueryParam("msisdn") Long msisdn,
>> @QueryParam("counters") Integer [] counters,
>> @QueryParam("subscriberIdType") String subscriberIdType)
>>
>> 2. I've written a ParameterHandler for this :
>>
>> public class IntegerArrayParameterHandler implements
>> ParameterHandler<Integer[]> {
>> @Override
>> public Integer[] fromString(String arg0) {
>>
>> 3. The parameter handler is registered, however its not picked up when
>> I do the query:
>>
>> <detail>[I cannot be cast to [Ljava.lang.Object;
>>
>> org.apache.cxf.jaxrs.utils.InjectionUtils.addToCollectionValues(InjectionUtils.java:752)
>>
>> org.apache.cxf.jaxrs.utils.InjectionUtils.injectIntoCollectionOrArray(InjectionUtils.java:740)
>>
>> org.apache.cxf.jaxrs.utils.InjectionUtils.createParameterObject(InjectionUtils.java:807)
>> org.apache.cxf.jaxrs.utils.JAXRSUtils.readQueryString(JAXRSUtils.java:947)
>>
>> org.apache.cxf.jaxrs.utils.JAXRSUtils.createHttpParameterValue(JAXRSUtils.java:649)
>>
>> Is there a way to get this to work?
>>
>> 4. I've Registered the Provider:
>> ----
>> <ref bean="integerArrayParameterHandler" />
>> </jaxrs:providers>
>>
>> The easiest solution is to just use the String value and parse it
>> inside my code,( which is probably why there are not many posts on
>> this:).
>>
>> Regards
>> Kiren
>
>
RE: Question about web services
Posted by David Sills <DS...@datasourceinc.com>.
Perhaps I'm just being slow, but if so, it still doesn't mean that no
one can even answer me. At least let me know I'm asking a dumb question
and point me to some place where all this is clearly explicated.
Thanks!
David
-----Original Message-----
From: David Sills [mailto:DSills@datasourceinc.com]
Sent: Friday, September 30, 2011 7:42 AM
To: users@cxf.apache.org
Subject: RE: Question about web services
All:
I didn't get an answer to my original question, but still need one -
just asking. The documentation for how to make a web service that is
only accessible using HTTPS is, in any case, pretty thin. I'm happy to
add to it if someone can point me in the right direction.
One thing I'm also confused about, does the soap:address location
attribute have to specify "https" as the protocol? If so, how can I do
this with CXF annotations? I can find nothing in the documentation about
this, though perhaps I'm just missing something.
David Sills
-----Original Message-----
From: David Sills [mailto:DSills@datasourceinc.com]
Sent: Wednesday, September 28, 2011 12:04 PM
To: users@cxf.apache.org
Subject: Question about web services
All:
I have a question I can't seem to get a ready answer to. I see some
potentially useful attributes on the jaxws:endpoint element, but I'm not
sure how to use them.
I have a report-writing service implemented on a Tomcat server in
Windows using the CXF Spring configuration. While doing this, however, I
left myself room to easily implement other web services on the same
server by simply dropping in a JAR file into WEB-INF/lib with a Spring
configuration in a known location within the JAR file and adding a
single line to the master Spring configuration file. Happy to share if
that sounds interesting to anyone.
However, now I'm faced with a new challenge. My services up till now
have been and need to remain HTTP. A new service has been requested,
however, that must use HTTPS. Setting up Tomcat for HTTPS is its own
problem, of course, but that's not what I'm asking.
How do I mark a particular service to use HTTPS, even though other
services may be using HTTP?
Many, many thanks for any advice and ideas.
David Sills
RE: Question about web services
Posted by David Sills <DS...@datasourceinc.com>.
All:
I didn't get an answer to my original question, but still need one -
just asking. The documentation for how to make a web service that is
only accessible using HTTPS is, in any case, pretty thin. I'm happy to
add to it if someone can point me in the right direction.
One thing I'm also confused about, does the soap:address location
attribute have to specify "https" as the protocol? If so, how can I do
this with CXF annotations? I can find nothing in the documentation about
this, though perhaps I'm just missing something.
David Sills
-----Original Message-----
From: David Sills [mailto:DSills@datasourceinc.com]
Sent: Wednesday, September 28, 2011 12:04 PM
To: users@cxf.apache.org
Subject: Question about web services
All:
I have a question I can't seem to get a ready answer to. I see some
potentially useful attributes on the jaxws:endpoint element, but I'm not
sure how to use them.
I have a report-writing service implemented on a Tomcat server in
Windows using the CXF Spring configuration. While doing this, however, I
left myself room to easily implement other web services on the same
server by simply dropping in a JAR file into WEB-INF/lib with a Spring
configuration in a known location within the JAR file and adding a
single line to the master Spring configuration file. Happy to share if
that sounds interesting to anyone.
However, now I'm faced with a new challenge. My services up till now
have been and need to remain HTTP. A new service has been requested,
however, that must use HTTPS. Setting up Tomcat for HTTPS is its own
problem, of course, but that's not what I'm asking.
How do I mark a particular service to use HTTPS, even though other
services may be using HTTP?
Many, many thanks for any advice and ideas.
David Sills
Re: Question about web services
Posted by Glen Mazza <gm...@talend.com>.
Unless you're doing a standalone web service (embedded Jetty using
Endpoint.publish()), that will be marked in the web.xml for the WAR
hosting your web service provider:
http://www.jroller.com/gmazza/entry/ssl_for_web_services
You might be able to do the same thing you're doing below if you host
your SSL-enabled services in a different WAR (with the web.xml change
mentioned above).
Glen
On 09/28/2011 12:04 PM, David Sills wrote:
> All:
>
> I have a question I can't seem to get a ready answer to. I see some
> potentially useful attributes on the jaxws:endpoint element, but I'm not
> sure how to use them.
>
> I have a report-writing service implemented on a Tomcat server in
> Windows using the CXF Spring configuration. While doing this, however, I
> left myself room to easily implement other web services on the same
> server by simply dropping in a JAR file into WEB-INF/lib with a Spring
> configuration in a known location within the JAR file and adding a
> single line to the master Spring configuration file. Happy to share if
> that sounds interesting to anyone.
>
> However, now I'm faced with a new challenge. My services up till now
> have been and need to remain HTTP. A new service has been requested,
> however, that must use HTTPS. Setting up Tomcat for HTTPS is its own
> problem, of course, but that's not what I'm asking.
>
> How do I mark a particular service to use HTTPS, even though other
> services may be using HTTP?
>
> Many, many thanks for any advice and ideas.
>
> David Sills
--
Glen Mazza
Talend - http://www.talend.com/products/tsf
Blog - http://www.jroller.com/gmazza
Twitter - glenmazza
Question about web services
Posted by David Sills <DS...@datasourceinc.com>.
All:
I have a question I can't seem to get a ready answer to. I see some
potentially useful attributes on the jaxws:endpoint element, but I'm not
sure how to use them.
I have a report-writing service implemented on a Tomcat server in
Windows using the CXF Spring configuration. While doing this, however, I
left myself room to easily implement other web services on the same
server by simply dropping in a JAR file into WEB-INF/lib with a Spring
configuration in a known location within the JAR file and adding a
single line to the master Spring configuration file. Happy to share if
that sounds interesting to anyone.
However, now I'm faced with a new challenge. My services up till now
have been and need to remain HTTP. A new service has been requested,
however, that must use HTTPS. Setting up Tomcat for HTTPS is its own
problem, of course, but that's not what I'm asking.
How do I mark a particular service to use HTTPS, even though other
services may be using HTTP?
Many, many thanks for any advice and ideas.
David Sills
Re: Marshalling REST Query Parameter directly into Integer Array
Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi
List<Integer> must be supported, I'll add a test for Integer[], have you
tried int[] ?
Cheers, Sergey
On 28/09/11 15:42, Kiren Pillay wrote:
> Hi
>
> This is an old problem, but I can't seem to find a solution posted
> anywhere. I want to marshall a comma-separated list of integers
> directly into an Integer [].
>
> 1. Service:
>
> public Response getCounters(
> @QueryParam("msisdn") Long msisdn,
> @QueryParam("counters") Integer [] counters,
> @QueryParam("subscriberIdType") String subscriberIdType)
>
> 2. I've written a ParameterHandler for this :
>
> public class IntegerArrayParameterHandler implements
> ParameterHandler<Integer[]> {
> @Override
> public Integer[] fromString(String arg0) {
>
> 3. The parameter handler is registered, however its not picked up when
> I do the query:
>
> <detail>[I cannot be cast to [Ljava.lang.Object;
> org.apache.cxf.jaxrs.utils.InjectionUtils.addToCollectionValues(InjectionUtils.java:752)
> org.apache.cxf.jaxrs.utils.InjectionUtils.injectIntoCollectionOrArray(InjectionUtils.java:740)
> org.apache.cxf.jaxrs.utils.InjectionUtils.createParameterObject(InjectionUtils.java:807)
> org.apache.cxf.jaxrs.utils.JAXRSUtils.readQueryString(JAXRSUtils.java:947)
> org.apache.cxf.jaxrs.utils.JAXRSUtils.createHttpParameterValue(JAXRSUtils.java:649)
>
> Is there a way to get this to work?
>
> 4. I've Registered the Provider:
> ----
> <ref bean="integerArrayParameterHandler" />
> </jaxrs:providers>
>
> The easiest solution is to just use the String value and parse it
> inside my code,( which is probably why there are not many posts on
> this:).
>
> Regards
> Kiren