You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Zoltán Balogh <zo...@freemail.hu> on 2019/07/09 11:32:50 UTC
CxfRsProducer nullpo exception if @QueryParam is null
Hi,
why the cxfrs producer not accept null query params? Should I set an
additional parameter to pass null value?
My route:
from("cxfrs:http://localhost:8080/tua"
+ "?resourceClasses="
+ "hu.fornax.tua.kodtar.protocol.rest.KodtarREST"
+ "&loggingFeatureEnabled=true"
+ "&providers=#jsonProvider")
.removeHeader("Content-Type")
.setHeader("CamelCxfRsUsingHttpAPI", constant("false"))
.log(ESBLog.ESB + "REST request: ${headers}")
.to("cxfrs:http://localhost:8080/tua-kodtar/rest"
+
"?resourceClasses=hu.fornax.tua.kodtar.protocol.rest.KodtarREST&throwExceptionOnFailure=false&loggingFeatureEnabled=true&providers=#jsonProvider")
.otherwise()
The rest interface:
@Path("/{type}")
public List<KodtarDto> getKodtarElemListByType(@PathParam("type")
KodtarType type, @QueryParam("id") Long id);
If I call the consumer (cxfrs://http://localhost:8080/tua) to proxy the request:
13:23:34,882 ERROR [org.apache.camel.processor.DefaultErrorHandler]
(default task-2) Failed delivery for (MessageId:
ID-DESKTOP-A2U86J9-59663-1562671187095-11-1 on ExchangeId:
ID-DESKTOP-A2U86J9-59663-1562671187095-11-2). Exhausted after delivery
attempt: 1 caught: java.lang.NullPointerException
Message History
---------------------------------------------------------------------------------------------------------------------------------------
RouteId ProcessorId Processor
Elapsed (ms)
[route15 ] [route15 ]
[cxfrs://http://localhost:8080/tua?loggingFeatureEnabled=true&providers=%23json]
[ 65]
[route15 ] [removeHeader1 ] [removeHeader[Content-Type]
] [ 1]
[route15 ] [setHeader3 ]
[setHeader[CamelCxfRsUsingHttpAPI]
] [ 0]
[route15 ] [log31 ] [log
] [ 3]
[route15 ] [log32 ] [log
] [ 1]
[route15 ] [choice3 ]
[when[{header{header(CamelHttpUri)} contains
/tua/api/file}]choice[when[{header] [ 54]
[route15 ] [to8 ]
[cxfrs:http://localhost:8080/tua-kodtar/rest?resourceClasses=hu.fornax.tua.kodt]
[ 49]
Stacktrace
---------------------------------------------------------------------------------------------------------------------------------------:
java.lang.NullPointerException
at org.apache.camel.component.cxf.jaxrs.CxfRsProducer.getParameterTypes(CxfRsProducer.java:524)
at org.apache.camel.component.cxf.jaxrs.CxfRsProducer.invokeProxyClient(CxfRsProducer.java:430)
at org.apache.camel.component.cxf.jaxrs.CxfRsProducer.process(CxfRsProducer.java:103)
at org.apache.camel.impl.SynchronousDelegateProducer.process(SynchronousDelegateProducer.java:62)
at org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61)
at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:145)
at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77)
at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:541)
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:198)
at org.apache.camel.processor.ChoiceProcessor.process(ChoiceProcessor.java:117)
at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77)
at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:541)
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:198)
at org.apache.camel.processor.Pipeline.process(Pipeline.java:120)
at org.apache.camel.processor.Pipeline.process(Pipeline.java:83)
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:198)
at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:97)
at org.apache.camel.component.cxf.jaxrs.CxfRsInvoker.syncInvoke(CxfRsInvoker.java:139)
at org.apache.camel.component.cxf.jaxrs.CxfRsInvoker.performInvocation(CxfRsInvoker.java:72)
If the queryparam is set with value that is not null the route works
and calling the service consumer directly without adding "id" it works
as well (cxfrs:http://localhost:8080/tua-kodtar/rest)....
If I want to proxy the request getting NullPointerException.
env: WildFly-Camel 4.9.0
Thanks for your help!
Topicfun
CDi bean call from cxfrs resource class
Posted by Zoltán Balogh <zo...@freemail.hu>.
Hi,
possible to call a CDI bean from a cxfrs resourceclass or register the
resource class as CDI bean? (Wildfly Camel 4.9.0)
from("cxfrs:http://localhost:8080/tua-kodtar/rest?resourceClasses=hu.fornax.tua.kodtar.rest.KodtarRESTImpl&performInvocation=true)
@Named("kodtarRESTImpl")
public class KodtarRESTImpl implements KodtarREST {
@Inject
private KodtarService kodtarService;
calling the rest endpoint getting NPE because the injected
kodtarService is null.
tried in this way :
@Inject
@Named("kodtarRESTImpl")
KodtarRESTImpl kodtarRESTImpl;
@Override
public void configure() throws Exception {
from("cxfrs:http://localhost:8080/tua-kodtar/restresourceClasses=#kodtarRESTImpl&performInvocation=true")
at the deploy:
Caused by: java.lang.ClassNotFoundException: #kodtarRESTImpl
Thanks,
Topicfun
Re: CxfRsProducer nullpo exception if @QueryParam is null
Posted by Zoltán Balogh <zo...@freemail.hu>.
Hi,
the @POST seems to be work, what I have done:
- set synchronous=true
- configure Jackson with FAIL_ON_EMPTY_BEANS
One thing that I can't solve it calling @POST method the payload not
return to the client! It returns to producer but only the response
code returns to client...
17:33:20,684 INFO [org.apache.cxf.interceptor.LoggingInInterceptor]
(default task-55) Inbound Message
----------------------------
ID: 82
Response-Code: 201
Encoding: ISO-8859-1
Content-Type: application/json
Headers: {connection=[keep-alive], content-type=[application/json],
Date=[Tue, 16 Jul 2019 15:33:20 GMT], Server=[WildFly/10],
transfer-encoding=[chunked], X-Powered-By=[Undertow/1]}
Payload: {"id":1010,"parentId":null,"name":"kecske","type":"HATOSAGI_UGY_TIPUS","sorrend":null}
--------------------------------------
17:33:20,686 INFO [org.apache.cxf.interceptor.LoggingOutInterceptor]
(default task-55) Outbound Message
---------------------------
ID: 81
Response-Code: 201
Content-Type: application/json
Headers: {connection=[keep-alive], content-type=[application/json],
Date=[Tue, 16 Jul 2019 15:33:20 GMT], Server=[WildFly/10],
transfer-encoding=[chunked], X-Powered-By=[Undertow/1],
Content-Type=[application/json]}
Payload: {}
--------------------------------------
In case of calling @GET method the payload getting on the client...
I have shared the project :
https://gitlab.com/topicfun/cxfrs-put/tree/master
The important classes, resources are:
- cxfrs-put/blob/master/tua-esb/src/main/java/hu/fornax/tua/esb/route/RestRouteBuilder.java
=> rest proxy
- cxfrs-put/blob/master/tua-esb/src/main/webapp/WEB-INF/jboss-deployment-structure.xml
- cxfrs-put/blob/master/tua-kodtar/src/main/java/hu/fornax/tua/kodtar/route/KodtarRoute.java
=> rest service
- cxfrs-put/blob/master/tua-kodtar-protocol/src/main/java/hu/fornax/tua/kodtar/protocol/rest/KodtarREST.java
=> REST interface
and the full log calling @POST method:
https://gitlab.com/topicfun/cxfrs-put/blob/master/createPUT.log
Thanks in advance!
Topicfun
Freeman Fang <fr...@gmail.com> ezt írta (időpont: 2019. júl.
10., Sze, 20:44):
>
> Hi,
>
> Could you please append a reproducer project so that I can take a close look?
>
> Freeman
> -------------
> Freeman(Yue) Fang
>
> Red Hat, Inc.
>
>
>
>
>
> > On Jul 10, 2019, at 3:06 AM, Zoltán Balogh <zo...@freemail.hu> wrote:
> >
> > thanks for your answer but now I'm totally confused...
> > If I set CamelCxfRsUsingHttpAPI to true the getKodtarElemListByType
> > works properly.
> > But in this case I got exception for
> > @POST
> > public Response createKodtarElem(KodtarDto dto);
> >
> > 08:49:11,874 SEVERE [org.apache.cxf.jaxrs.utils.JAXRSUtils] (default
> > task-10) No message body writer has been found for class
> > hu.fornax.tua.kodtar.dto.KodtarDto, ContentType: application/xml
> > 08:49:11,875 WARNING [org.apache.cxf.phase.PhaseInterceptorChain]
> > (default task-10) Interceptor for
> > {http://localhost:8080/tua-kodtar/rest}WebClient has thrown exception,
> > unwinding now: org.apache.cxf.interceptor.Fault: No message body
> > writer has been found for class hu.fornax.tua.kodtar.dto.KodtarDto,
> > ContentType: application/xml
> >
> > The json provider is set (&providers=#jsonProvider), I have tried with
> > JacksonJaxbJsonProvider and with JacksonJsonProvider as well
> >
> > If I set CamelCxfRsUsingHttpAPI to false the @Post works. Otherwise
> > getting NPE to the @GET as I wrote in my first mail.
> >
> > I want only to proxy rest request to an other service where a cxfrs
> > rest endpoint consume, please help me how I can solve it?
> >
> > Thanks again your support!
> >
> >
> >
> >
> >
> >
> >
> > Freeman Fang <fr...@gmail.com> ezt írta (időpont: 2019. júl.
> > 9., K, 19:33):
> >>
> >> Hi,
> >>
> >> The difference with camel-cxf proxy is that you have setHeader("CamelCxfRsUsingHttpAPI", constant("false”)) in the route, which means you will use proxy client to invoke the RS server, so the para types must match the one in resourceClasses, without camel-cxf proxy you actually use http client. If you have setHeader("CamelCxfRsUsingHttpAPI", constant(“true”)) in your router the behaviour should be same with or without proxy.
> >>
> >> So if you have setHeader("CamelCxfRsUsingHttpAPI", constant("false”)) , ensure you have all parameters available in the payload.
> >>
> >> I think we probably can enhance here a bit, instead of throw NPE, throwing NoSuchMethodException if can’t find match method in the client proxy.
> >> -------------
> >> Freeman(Yue) Fang
> >>
> >> Red Hat, Inc.
> >>
> >>
> >>
> >>
> >>
> >>> On Jul 9, 2019, at 7:32 AM, Zoltán Balogh <zo...@freemail.hu> wrote:
> >>>
> >>> Hi,
> >>>
> >>> why the cxfrs producer not accept null query params? Should I set an
> >>> additional parameter to pass null value?
> >>>
> >>> My route:
> >>> from("cxfrs:http://localhost:8080/tua"
> >>> + "?resourceClasses="
> >>> + "hu.fornax.tua.kodtar.protocol.rest.KodtarREST"
> >>> + "&loggingFeatureEnabled=true"
> >>> + "&providers=#jsonProvider")
> >>> .removeHeader("Content-Type")
> >>> .setHeader("CamelCxfRsUsingHttpAPI", constant("false"))
> >>> .log(ESBLog.ESB + "REST request: ${headers}")
> >>> .to("cxfrs:http://localhost:8080/tua-kodtar/rest"
> >>> +
> >>> "?resourceClasses=hu.fornax.tua.kodtar.protocol.rest.KodtarREST&throwExceptionOnFailure=false&loggingFeatureEnabled=true&providers=#jsonProvider")
> >>> .otherwise()
> >>>
> >>> The rest interface:
> >>>
> >>> @Path("/{type}")
> >>> public List<KodtarDto> getKodtarElemListByType(@PathParam("type")
> >>> KodtarType type, @QueryParam("id") Long id);
> >>>
> >>> If I call the consumer (cxfrs://http://localhost:8080/tua) to proxy the request:
> >>>
> >>> 13:23:34,882 ERROR [org.apache.camel.processor.DefaultErrorHandler]
> >>> (default task-2) Failed delivery for (MessageId:
> >>> ID-DESKTOP-A2U86J9-59663-1562671187095-11-1 on ExchangeId:
> >>> ID-DESKTOP-A2U86J9-59663-1562671187095-11-2). Exhausted after delivery
> >>> attempt: 1 caught: java.lang.NullPointerException
> >>>
> >>> Message History
> >>> ---------------------------------------------------------------------------------------------------------------------------------------
> >>> RouteId ProcessorId Processor
> >>> Elapsed (ms)
> >>> [route15 ] [route15 ]
> >>> [cxfrs://http://localhost:8080/tua?loggingFeatureEnabled=true&providers=%23json]
> >>> [ 65]
> >>> [route15 ] [removeHeader1 ] [removeHeader[Content-Type]
> >>> ] [ 1]
> >>> [route15 ] [setHeader3 ]
> >>> [setHeader[CamelCxfRsUsingHttpAPI]
> >>> ] [ 0]
> >>> [route15 ] [log31 ] [log
> >>> ] [ 3]
> >>> [route15 ] [log32 ] [log
> >>> ] [ 1]
> >>> [route15 ] [choice3 ]
> >>> [when[{header{header(CamelHttpUri)} contains
> >>> /tua/api/file}]choice[when[{header] [ 54]
> >>> [route15 ] [to8 ]
> >>> [cxfrs:http://localhost:8080/tua-kodtar/rest?resourceClasses=hu.fornax.tua.kodt]
> >>> [ 49]
> >>>
> >>> Stacktrace
> >>> ---------------------------------------------------------------------------------------------------------------------------------------:
> >>> java.lang.NullPointerException
> >>> at org.apache.camel.component.cxf.jaxrs.CxfRsProducer.getParameterTypes(CxfRsProducer.java:524)
> >>> at org.apache.camel.component.cxf.jaxrs.CxfRsProducer.invokeProxyClient(CxfRsProducer.java:430)
> >>> at org.apache.camel.component.cxf.jaxrs.CxfRsProducer.process(CxfRsProducer.java:103)
> >>> at org.apache.camel.impl.SynchronousDelegateProducer.process(SynchronousDelegateProducer.java:62)
> >>> at org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61)
> >>> at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:145)
> >>> at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77)
> >>> at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:541)
> >>> at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:198)
> >>> at org.apache.camel.processor.ChoiceProcessor.process(ChoiceProcessor.java:117)
> >>> at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77)
> >>> at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:541)
> >>> at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:198)
> >>> at org.apache.camel.processor.Pipeline.process(Pipeline.java:120)
> >>> at org.apache.camel.processor.Pipeline.process(Pipeline.java:83)
> >>> at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:198)
> >>> at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:97)
> >>> at org.apache.camel.component.cxf.jaxrs.CxfRsInvoker.syncInvoke(CxfRsInvoker.java:139)
> >>> at org.apache.camel.component.cxf.jaxrs.CxfRsInvoker.performInvocation(CxfRsInvoker.java:72)
> >>>
> >>>
> >>> If the queryparam is set with value that is not null the route works
> >>> and calling the service consumer directly without adding "id" it works
> >>> as well (cxfrs:http://localhost:8080/tua-kodtar/rest)....
> >>> If I want to proxy the request getting NullPointerException.
> >>> env: WildFly-Camel 4.9.0
> >>>
> >>> Thanks for your help!
> >>> Topicfun
> >>
>
Re: CxfRsProducer nullpo exception if @QueryParam is null
Posted by Freeman Fang <fr...@gmail.com>.
Hi,
Could you please append a reproducer project so that I can take a close look?
Freeman
-------------
Freeman(Yue) Fang
Red Hat, Inc.
> On Jul 10, 2019, at 3:06 AM, Zoltán Balogh <zo...@freemail.hu> wrote:
>
> thanks for your answer but now I'm totally confused...
> If I set CamelCxfRsUsingHttpAPI to true the getKodtarElemListByType
> works properly.
> But in this case I got exception for
> @POST
> public Response createKodtarElem(KodtarDto dto);
>
> 08:49:11,874 SEVERE [org.apache.cxf.jaxrs.utils.JAXRSUtils] (default
> task-10) No message body writer has been found for class
> hu.fornax.tua.kodtar.dto.KodtarDto, ContentType: application/xml
> 08:49:11,875 WARNING [org.apache.cxf.phase.PhaseInterceptorChain]
> (default task-10) Interceptor for
> {http://localhost:8080/tua-kodtar/rest}WebClient has thrown exception,
> unwinding now: org.apache.cxf.interceptor.Fault: No message body
> writer has been found for class hu.fornax.tua.kodtar.dto.KodtarDto,
> ContentType: application/xml
>
> The json provider is set (&providers=#jsonProvider), I have tried with
> JacksonJaxbJsonProvider and with JacksonJsonProvider as well
>
> If I set CamelCxfRsUsingHttpAPI to false the @Post works. Otherwise
> getting NPE to the @GET as I wrote in my first mail.
>
> I want only to proxy rest request to an other service where a cxfrs
> rest endpoint consume, please help me how I can solve it?
>
> Thanks again your support!
>
>
>
>
>
>
>
> Freeman Fang <fr...@gmail.com> ezt írta (időpont: 2019. júl.
> 9., K, 19:33):
>>
>> Hi,
>>
>> The difference with camel-cxf proxy is that you have setHeader("CamelCxfRsUsingHttpAPI", constant("false”)) in the route, which means you will use proxy client to invoke the RS server, so the para types must match the one in resourceClasses, without camel-cxf proxy you actually use http client. If you have setHeader("CamelCxfRsUsingHttpAPI", constant(“true”)) in your router the behaviour should be same with or without proxy.
>>
>> So if you have setHeader("CamelCxfRsUsingHttpAPI", constant("false”)) , ensure you have all parameters available in the payload.
>>
>> I think we probably can enhance here a bit, instead of throw NPE, throwing NoSuchMethodException if can’t find match method in the client proxy.
>> -------------
>> Freeman(Yue) Fang
>>
>> Red Hat, Inc.
>>
>>
>>
>>
>>
>>> On Jul 9, 2019, at 7:32 AM, Zoltán Balogh <zo...@freemail.hu> wrote:
>>>
>>> Hi,
>>>
>>> why the cxfrs producer not accept null query params? Should I set an
>>> additional parameter to pass null value?
>>>
>>> My route:
>>> from("cxfrs:http://localhost:8080/tua"
>>> + "?resourceClasses="
>>> + "hu.fornax.tua.kodtar.protocol.rest.KodtarREST"
>>> + "&loggingFeatureEnabled=true"
>>> + "&providers=#jsonProvider")
>>> .removeHeader("Content-Type")
>>> .setHeader("CamelCxfRsUsingHttpAPI", constant("false"))
>>> .log(ESBLog.ESB + "REST request: ${headers}")
>>> .to("cxfrs:http://localhost:8080/tua-kodtar/rest"
>>> +
>>> "?resourceClasses=hu.fornax.tua.kodtar.protocol.rest.KodtarREST&throwExceptionOnFailure=false&loggingFeatureEnabled=true&providers=#jsonProvider")
>>> .otherwise()
>>>
>>> The rest interface:
>>>
>>> @Path("/{type}")
>>> public List<KodtarDto> getKodtarElemListByType(@PathParam("type")
>>> KodtarType type, @QueryParam("id") Long id);
>>>
>>> If I call the consumer (cxfrs://http://localhost:8080/tua) to proxy the request:
>>>
>>> 13:23:34,882 ERROR [org.apache.camel.processor.DefaultErrorHandler]
>>> (default task-2) Failed delivery for (MessageId:
>>> ID-DESKTOP-A2U86J9-59663-1562671187095-11-1 on ExchangeId:
>>> ID-DESKTOP-A2U86J9-59663-1562671187095-11-2). Exhausted after delivery
>>> attempt: 1 caught: java.lang.NullPointerException
>>>
>>> Message History
>>> ---------------------------------------------------------------------------------------------------------------------------------------
>>> RouteId ProcessorId Processor
>>> Elapsed (ms)
>>> [route15 ] [route15 ]
>>> [cxfrs://http://localhost:8080/tua?loggingFeatureEnabled=true&providers=%23json]
>>> [ 65]
>>> [route15 ] [removeHeader1 ] [removeHeader[Content-Type]
>>> ] [ 1]
>>> [route15 ] [setHeader3 ]
>>> [setHeader[CamelCxfRsUsingHttpAPI]
>>> ] [ 0]
>>> [route15 ] [log31 ] [log
>>> ] [ 3]
>>> [route15 ] [log32 ] [log
>>> ] [ 1]
>>> [route15 ] [choice3 ]
>>> [when[{header{header(CamelHttpUri)} contains
>>> /tua/api/file}]choice[when[{header] [ 54]
>>> [route15 ] [to8 ]
>>> [cxfrs:http://localhost:8080/tua-kodtar/rest?resourceClasses=hu.fornax.tua.kodt]
>>> [ 49]
>>>
>>> Stacktrace
>>> ---------------------------------------------------------------------------------------------------------------------------------------:
>>> java.lang.NullPointerException
>>> at org.apache.camel.component.cxf.jaxrs.CxfRsProducer.getParameterTypes(CxfRsProducer.java:524)
>>> at org.apache.camel.component.cxf.jaxrs.CxfRsProducer.invokeProxyClient(CxfRsProducer.java:430)
>>> at org.apache.camel.component.cxf.jaxrs.CxfRsProducer.process(CxfRsProducer.java:103)
>>> at org.apache.camel.impl.SynchronousDelegateProducer.process(SynchronousDelegateProducer.java:62)
>>> at org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61)
>>> at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:145)
>>> at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77)
>>> at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:541)
>>> at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:198)
>>> at org.apache.camel.processor.ChoiceProcessor.process(ChoiceProcessor.java:117)
>>> at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77)
>>> at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:541)
>>> at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:198)
>>> at org.apache.camel.processor.Pipeline.process(Pipeline.java:120)
>>> at org.apache.camel.processor.Pipeline.process(Pipeline.java:83)
>>> at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:198)
>>> at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:97)
>>> at org.apache.camel.component.cxf.jaxrs.CxfRsInvoker.syncInvoke(CxfRsInvoker.java:139)
>>> at org.apache.camel.component.cxf.jaxrs.CxfRsInvoker.performInvocation(CxfRsInvoker.java:72)
>>>
>>>
>>> If the queryparam is set with value that is not null the route works
>>> and calling the service consumer directly without adding "id" it works
>>> as well (cxfrs:http://localhost:8080/tua-kodtar/rest)....
>>> If I want to proxy the request getting NullPointerException.
>>> env: WildFly-Camel 4.9.0
>>>
>>> Thanks for your help!
>>> Topicfun
>>
Re: CxfRsProducer nullpo exception if @QueryParam is null
Posted by Zoltán Balogh <zo...@freemail.hu>.
thanks for your answer but now I'm totally confused...
If I set CamelCxfRsUsingHttpAPI to true the getKodtarElemListByType
works properly.
But in this case I got exception for
@POST
public Response createKodtarElem(KodtarDto dto);
08:49:11,874 SEVERE [org.apache.cxf.jaxrs.utils.JAXRSUtils] (default
task-10) No message body writer has been found for class
hu.fornax.tua.kodtar.dto.KodtarDto, ContentType: application/xml
08:49:11,875 WARNING [org.apache.cxf.phase.PhaseInterceptorChain]
(default task-10) Interceptor for
{http://localhost:8080/tua-kodtar/rest}WebClient has thrown exception,
unwinding now: org.apache.cxf.interceptor.Fault: No message body
writer has been found for class hu.fornax.tua.kodtar.dto.KodtarDto,
ContentType: application/xml
The json provider is set (&providers=#jsonProvider), I have tried with
JacksonJaxbJsonProvider and with JacksonJsonProvider as well
If I set CamelCxfRsUsingHttpAPI to false the @Post works. Otherwise
getting NPE to the @GET as I wrote in my first mail.
I want only to proxy rest request to an other service where a cxfrs
rest endpoint consume, please help me how I can solve it?
Thanks again your support!
Freeman Fang <fr...@gmail.com> ezt írta (időpont: 2019. júl.
9., K, 19:33):
>
> Hi,
>
> The difference with camel-cxf proxy is that you have setHeader("CamelCxfRsUsingHttpAPI", constant("false”)) in the route, which means you will use proxy client to invoke the RS server, so the para types must match the one in resourceClasses, without camel-cxf proxy you actually use http client. If you have setHeader("CamelCxfRsUsingHttpAPI", constant(“true”)) in your router the behaviour should be same with or without proxy.
>
> So if you have setHeader("CamelCxfRsUsingHttpAPI", constant("false”)) , ensure you have all parameters available in the payload.
>
> I think we probably can enhance here a bit, instead of throw NPE, throwing NoSuchMethodException if can’t find match method in the client proxy.
> -------------
> Freeman(Yue) Fang
>
> Red Hat, Inc.
>
>
>
>
>
> > On Jul 9, 2019, at 7:32 AM, Zoltán Balogh <zo...@freemail.hu> wrote:
> >
> > Hi,
> >
> > why the cxfrs producer not accept null query params? Should I set an
> > additional parameter to pass null value?
> >
> > My route:
> > from("cxfrs:http://localhost:8080/tua"
> > + "?resourceClasses="
> > + "hu.fornax.tua.kodtar.protocol.rest.KodtarREST"
> > + "&loggingFeatureEnabled=true"
> > + "&providers=#jsonProvider")
> > .removeHeader("Content-Type")
> > .setHeader("CamelCxfRsUsingHttpAPI", constant("false"))
> > .log(ESBLog.ESB + "REST request: ${headers}")
> > .to("cxfrs:http://localhost:8080/tua-kodtar/rest"
> > +
> > "?resourceClasses=hu.fornax.tua.kodtar.protocol.rest.KodtarREST&throwExceptionOnFailure=false&loggingFeatureEnabled=true&providers=#jsonProvider")
> > .otherwise()
> >
> > The rest interface:
> >
> > @Path("/{type}")
> > public List<KodtarDto> getKodtarElemListByType(@PathParam("type")
> > KodtarType type, @QueryParam("id") Long id);
> >
> > If I call the consumer (cxfrs://http://localhost:8080/tua) to proxy the request:
> >
> > 13:23:34,882 ERROR [org.apache.camel.processor.DefaultErrorHandler]
> > (default task-2) Failed delivery for (MessageId:
> > ID-DESKTOP-A2U86J9-59663-1562671187095-11-1 on ExchangeId:
> > ID-DESKTOP-A2U86J9-59663-1562671187095-11-2). Exhausted after delivery
> > attempt: 1 caught: java.lang.NullPointerException
> >
> > Message History
> > ---------------------------------------------------------------------------------------------------------------------------------------
> > RouteId ProcessorId Processor
> > Elapsed (ms)
> > [route15 ] [route15 ]
> > [cxfrs://http://localhost:8080/tua?loggingFeatureEnabled=true&providers=%23json]
> > [ 65]
> > [route15 ] [removeHeader1 ] [removeHeader[Content-Type]
> > ] [ 1]
> > [route15 ] [setHeader3 ]
> > [setHeader[CamelCxfRsUsingHttpAPI]
> > ] [ 0]
> > [route15 ] [log31 ] [log
> > ] [ 3]
> > [route15 ] [log32 ] [log
> > ] [ 1]
> > [route15 ] [choice3 ]
> > [when[{header{header(CamelHttpUri)} contains
> > /tua/api/file}]choice[when[{header] [ 54]
> > [route15 ] [to8 ]
> > [cxfrs:http://localhost:8080/tua-kodtar/rest?resourceClasses=hu.fornax.tua.kodt]
> > [ 49]
> >
> > Stacktrace
> > ---------------------------------------------------------------------------------------------------------------------------------------:
> > java.lang.NullPointerException
> > at org.apache.camel.component.cxf.jaxrs.CxfRsProducer.getParameterTypes(CxfRsProducer.java:524)
> > at org.apache.camel.component.cxf.jaxrs.CxfRsProducer.invokeProxyClient(CxfRsProducer.java:430)
> > at org.apache.camel.component.cxf.jaxrs.CxfRsProducer.process(CxfRsProducer.java:103)
> > at org.apache.camel.impl.SynchronousDelegateProducer.process(SynchronousDelegateProducer.java:62)
> > at org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61)
> > at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:145)
> > at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77)
> > at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:541)
> > at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:198)
> > at org.apache.camel.processor.ChoiceProcessor.process(ChoiceProcessor.java:117)
> > at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77)
> > at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:541)
> > at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:198)
> > at org.apache.camel.processor.Pipeline.process(Pipeline.java:120)
> > at org.apache.camel.processor.Pipeline.process(Pipeline.java:83)
> > at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:198)
> > at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:97)
> > at org.apache.camel.component.cxf.jaxrs.CxfRsInvoker.syncInvoke(CxfRsInvoker.java:139)
> > at org.apache.camel.component.cxf.jaxrs.CxfRsInvoker.performInvocation(CxfRsInvoker.java:72)
> >
> >
> > If the queryparam is set with value that is not null the route works
> > and calling the service consumer directly without adding "id" it works
> > as well (cxfrs:http://localhost:8080/tua-kodtar/rest)....
> > If I want to proxy the request getting NullPointerException.
> > env: WildFly-Camel 4.9.0
> >
> > Thanks for your help!
> > Topicfun
>
Re: CxfRsProducer nullpo exception if @QueryParam is null
Posted by Freeman Fang <fr...@gmail.com>.
Hi,
The difference with camel-cxf proxy is that you have setHeader("CamelCxfRsUsingHttpAPI", constant("false”)) in the route, which means you will use proxy client to invoke the RS server, so the para types must match the one in resourceClasses, without camel-cxf proxy you actually use http client. If you have setHeader("CamelCxfRsUsingHttpAPI", constant(“true”)) in your router the behaviour should be same with or without proxy.
So if you have setHeader("CamelCxfRsUsingHttpAPI", constant("false”)) , ensure you have all parameters available in the payload.
I think we probably can enhance here a bit, instead of throw NPE, throwing NoSuchMethodException if can’t find match method in the client proxy.
-------------
Freeman(Yue) Fang
Red Hat, Inc.
> On Jul 9, 2019, at 7:32 AM, Zoltán Balogh <zo...@freemail.hu> wrote:
>
> Hi,
>
> why the cxfrs producer not accept null query params? Should I set an
> additional parameter to pass null value?
>
> My route:
> from("cxfrs:http://localhost:8080/tua"
> + "?resourceClasses="
> + "hu.fornax.tua.kodtar.protocol.rest.KodtarREST"
> + "&loggingFeatureEnabled=true"
> + "&providers=#jsonProvider")
> .removeHeader("Content-Type")
> .setHeader("CamelCxfRsUsingHttpAPI", constant("false"))
> .log(ESBLog.ESB + "REST request: ${headers}")
> .to("cxfrs:http://localhost:8080/tua-kodtar/rest"
> +
> "?resourceClasses=hu.fornax.tua.kodtar.protocol.rest.KodtarREST&throwExceptionOnFailure=false&loggingFeatureEnabled=true&providers=#jsonProvider")
> .otherwise()
>
> The rest interface:
>
> @Path("/{type}")
> public List<KodtarDto> getKodtarElemListByType(@PathParam("type")
> KodtarType type, @QueryParam("id") Long id);
>
> If I call the consumer (cxfrs://http://localhost:8080/tua) to proxy the request:
>
> 13:23:34,882 ERROR [org.apache.camel.processor.DefaultErrorHandler]
> (default task-2) Failed delivery for (MessageId:
> ID-DESKTOP-A2U86J9-59663-1562671187095-11-1 on ExchangeId:
> ID-DESKTOP-A2U86J9-59663-1562671187095-11-2). Exhausted after delivery
> attempt: 1 caught: java.lang.NullPointerException
>
> Message History
> ---------------------------------------------------------------------------------------------------------------------------------------
> RouteId ProcessorId Processor
> Elapsed (ms)
> [route15 ] [route15 ]
> [cxfrs://http://localhost:8080/tua?loggingFeatureEnabled=true&providers=%23json]
> [ 65]
> [route15 ] [removeHeader1 ] [removeHeader[Content-Type]
> ] [ 1]
> [route15 ] [setHeader3 ]
> [setHeader[CamelCxfRsUsingHttpAPI]
> ] [ 0]
> [route15 ] [log31 ] [log
> ] [ 3]
> [route15 ] [log32 ] [log
> ] [ 1]
> [route15 ] [choice3 ]
> [when[{header{header(CamelHttpUri)} contains
> /tua/api/file}]choice[when[{header] [ 54]
> [route15 ] [to8 ]
> [cxfrs:http://localhost:8080/tua-kodtar/rest?resourceClasses=hu.fornax.tua.kodt]
> [ 49]
>
> Stacktrace
> ---------------------------------------------------------------------------------------------------------------------------------------:
> java.lang.NullPointerException
> at org.apache.camel.component.cxf.jaxrs.CxfRsProducer.getParameterTypes(CxfRsProducer.java:524)
> at org.apache.camel.component.cxf.jaxrs.CxfRsProducer.invokeProxyClient(CxfRsProducer.java:430)
> at org.apache.camel.component.cxf.jaxrs.CxfRsProducer.process(CxfRsProducer.java:103)
> at org.apache.camel.impl.SynchronousDelegateProducer.process(SynchronousDelegateProducer.java:62)
> at org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61)
> at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:145)
> at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77)
> at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:541)
> at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:198)
> at org.apache.camel.processor.ChoiceProcessor.process(ChoiceProcessor.java:117)
> at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77)
> at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:541)
> at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:198)
> at org.apache.camel.processor.Pipeline.process(Pipeline.java:120)
> at org.apache.camel.processor.Pipeline.process(Pipeline.java:83)
> at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:198)
> at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:97)
> at org.apache.camel.component.cxf.jaxrs.CxfRsInvoker.syncInvoke(CxfRsInvoker.java:139)
> at org.apache.camel.component.cxf.jaxrs.CxfRsInvoker.performInvocation(CxfRsInvoker.java:72)
>
>
> If the queryparam is set with value that is not null the route works
> and calling the service consumer directly without adding "id" it works
> as well (cxfrs:http://localhost:8080/tua-kodtar/rest)....
> If I want to proxy the request getting NullPointerException.
> env: WildFly-Camel 4.9.0
>
> Thanks for your help!
> Topicfun