Optional http headers as parameters of the methods
Issue
- Spring Boot standalone application with Fuse 7.5.
Issue: To invoke REST web services from camel using the CXFRS component.
The application invokes a simple REST web service Swagger Petstore(http://petstore.swagger.io/). To do that java classes are generated from specification using swagger-codegen-maven-plugin.
The application has a server
module which is a Spring Boot standalone application with Fuse 7.5.
@POST
@Path("/pet/{petId}")
@Consumes({ "application/x-www-form-urlencoded" })
@Produces({ "application/json", "application/xml" })
@ApiOperation(value = "Updates a pet in the store with form data", tags={ })
@ApiResponses(value = {
@ApiResponse(code = 405, message = "Invalid input") })
public void updatePetWithForm(@PathParam("petId") Long petId, @Multipart(value = "name", required = false) String name, @Multipart(value = "status", required = false) String status);
The form data has two OPTIONAL parameters ("name" and "status"). The expectation is to invoke the service with one parameter provided ("name") and not provide the second ("status" - because it's optional).
Case 1: its building request with all three parameters, but one of them ("status") is null.
.process(exchange ->
{ Object[] request = new Object[3]; request[0] = 15435006002310L; request[1] = "name"; request[2] = null; exchange.getIn().setBody(request); }
)
Received error:
java.lang.NullPointerException: null
at org.apache.camel.component.cxf.jaxrs.CxfRsProducer.getParameterTypes(CxfRsProducer.java:534) ~[camel-cxf-2.23.2.fuse-750029-redhat-00001.jar:2.23.2.fuse-750029-redhat-00001]
at org.apache.camel.component.cxf.jaxrs.CxfRsProducer.invokeAsyncProxyClient(CxfRsProducer.java:216) ~[camel-cxf-2.23.2.fuse-750029-redhat-00001.jar:2.23.2.fuse-750029-redhat-00001]
at org.apache.camel.component.cxf.jaxrs.CxfRsProducer.process(CxfRsProducer.java:118) ~[camel-cxf-2.23.2.fuse-750029-redhat-00001.jar:2.23.2.fuse-750029-redhat-00001]
........................
Case 2: its building request with two parameters, omitting the one they don't want to provide ("status").
.process(exchange ->
{ Object[] request = new Object[2]; request[0] = 7749969416216421L; request[1] = "name"; exchange.getIn().setBody(request); }
)
The error received is:
java.lang.NoSuchMethodException: Cannot find method with name: updatePetWithForm having parameters assignable from: [class java.lang.Long,class java.lang.String]
at org.apache.camel.component.cxf.jaxrs.CxfRsProducer.findRightMethod(CxfRsProducer.java:523) ~[camel-cxf-2.23.2.fuse-750029-redhat-00001.jar:2.23.2.fuse-750029-redhat-00001]
at org.apache.camel.component.cxf.jaxrs.CxfRsProducer.invokeAsyncProxyClient(CxfRsProducer.java:216) ~[camel-cxf-2.23.2.fuse-750029-redhat-00001.jar:2.23.2.fuse-750029-redhat-00001]
.................
Provide a way in camel-cxfrs invoke the service with Proxy-based client API without providing OPTIONAL parameters.
Environment
- Red Hat JBoss Fuse
- 7.5
Subscriber exclusive content
A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.