Hi everyone,
I had an error a few days ago, and after investigations, here's what it was
I am calling an endpoint using cxfrs client with the http api. So I have
something like that in the DSL :
....
.setHeader(CxfConstants.CAMEL_CXF_RS_USING_HTTP_API, constant(true))
.setHeader(Exchange.HTTP_PATH, simple("/endpoint/${header.myHeader}"))
.setHeader(Exchange.HTTP_METHOD, constant(POST))
.to("cxfrs:bean:myClient")
....
This usually works fine.
I had a somewhat nasty error when someone did a copy paste of my server,
with the variable substitution style (something like /endpoint/{myVariable})
at that point, ${header.myHeader} resolved to {myVariable}, thus the url the
client will try to resolve is /endpoint/{myVariable}. When trying to parse
this URL, CXF will not be happy, since there is no value to replace what it
thinks to be a variable, and will throw an IllegalArgumentException with
message Unresolved variables; only 0 value(s) given for 1 unique
variable(s).
After looking a bit in the code, I understood better what happens.
In order to avoid that, it would be nice to use the mechanism of CXF to
replace variables in URI.
In the DSL, we would have something like :
....
.setHeader(CxfConstants.CAMEL_CXF_RS_USING_HTTP_API, constant(true))
.setHeader(CxfConstants.CAMEL_CXF_RS_VAR_VALUES,
simple("[${header.myHeader}]"))
.setHeader(Exchange.HTTP_PATH, constant("/endpoint/{myVariable}"))
.setHeader(Exchange.HTTP_METHOD, constant("POST"))
.to("cxfrs:bean:myClient")
....
This array would have to be retrieved in the CxfRsProducer#invokeHttpClient
(as it is done in the invokeProxyClient method) and passed all the way to
the UriBuilder in the WebClient.
What do you think of it ?
Best regards,
François
I had an error a few days ago, and after investigations, here's what it was
I am calling an endpoint using cxfrs client with the http api. So I have
something like that in the DSL :
....
.setHeader(CxfConstants.CAMEL_CXF_RS_USING_HTTP_API, constant(true))
.setHeader(Exchange.HTTP_PATH, simple("/endpoint/${header.myHeader}"))
.setHeader(Exchange.HTTP_METHOD, constant(POST))
.to("cxfrs:bean:myClient")
....
This usually works fine.
I had a somewhat nasty error when someone did a copy paste of my server,
with the variable substitution style (something like /endpoint/{myVariable})
at that point, ${header.myHeader} resolved to {myVariable}, thus the url the
client will try to resolve is /endpoint/{myVariable}. When trying to parse
this URL, CXF will not be happy, since there is no value to replace what it
thinks to be a variable, and will throw an IllegalArgumentException with
message Unresolved variables; only 0 value(s) given for 1 unique
variable(s).
After looking a bit in the code, I understood better what happens.
In order to avoid that, it would be nice to use the mechanism of CXF to
replace variables in URI.
In the DSL, we would have something like :
....
.setHeader(CxfConstants.CAMEL_CXF_RS_USING_HTTP_API, constant(true))
.setHeader(CxfConstants.CAMEL_CXF_RS_VAR_VALUES,
simple("[${header.myHeader}]"))
.setHeader(Exchange.HTTP_PATH, constant("/endpoint/{myVariable}"))
.setHeader(Exchange.HTTP_METHOD, constant("POST"))
.to("cxfrs:bean:myClient")
....
This array would have to be retrieved in the CxfRsProducer#invokeHttpClient
(as it is done in the invokeProxyClient method) and passed all the way to
the UriBuilder in the WebClient.
What do you think of it ?
Best regards,
François