We have a simple camel route "from->to":
<from uri="cxf:bean:testServiceProvider?loggingFeatureEnabled=true" />
<to uri="cxf:bean:testServiceClient?loggingFeatureEnabled=true" />
This route acts like a router or proxy for a third party's web service:
Clients use it as endpoint.
Adds WSS headers to Soap message.
Route requests to real endpoint.
Service and client in this proxy are created with cxf beans.
The endpoint's web service seems to require Content-Length HTTP header, but cxf requests to endpoint does not contain this header by default. All the requests done by this proxy receive the same response:
HTTP response '411: Length required' when communicating with https://host:port/testService
We tried to add this header with an OutInterceptor, adding it to PROTOCOL_HEADERS:
Map<String, List> headers = (Map<String, List>) message.get(Message.PROTOCOL_HEADERS);
headers.put("Content-Length", Collections.singletonList(String.valueOf(messageLength)));
Two questions:
How to know the value of messageLength?
Is there an easier way to do this?
Thanks!
You can try with http:conduit, disabling AllowChunking. This will force cxf to include Content-Length header in the request. By default cxf behaviour is to allow chunking, so it can be generating the problem you're facing, even specifying the Content-length header.
<http:conduit name="{http://namespace}WebService.http-conduit">
<http:client AllowChunking="false" CacheControl="No-Cache"
ContentType="text/xml;charset=UTF-8" ConnectionTimeout="900000"
ReceiveTimeout="900000" Connection="Keep-Alive" />
</http:conduit>
Looking at the CXF documentation you may be able to use the relayHeaders functionality to propogate headers from the "from" endpoint to the "to" endpoint.
CXF Bean Docs
Alternatively you could copy the value of the content-length from the inbound message as suggested here...
"If you want to keep those headers in the old version of camel, you need
to put the headers into a map and put this map into message header with
the key "org.apache.cxf.message.PROTOCOL_HEADERS"."
Copy headers
Related
I am creating a simple and lightweight reverse HTTP proxy and using com.sun.net.httpserver.httpserver for it.
Once the proxy is done with its work it should add few headers in request headers and forward the request to actual service, however when i add anything in request headers i get UnsupportedOperationException because it is using UnmodifiableHeaders.
Can someone tell me how to configure com.sun.net.httpserver.httpserver to use modifiable headers?
Or is there any other better yet super lightweight HTTP server which supports this?
java.lang.UnsupportedOperationException: unsupported operation
at jdk.httpserver/sun.net.httpserver.UnmodifiableHeaders.add(UnmodifiableHeaders.java:65)
at com.example.SampleFilter.lambda$addValuesInRequestHeader$1(SampleFilter.java:80)
There is no way to add/edit headers but we can use httpExchange.setAttribute() and httpExchange.getAttribute() methods to pass additional information when hopping between filters.
For adding headers to the request that we want to forward to service, we create a new http request from the original one and include attributes in headers
I'm just started with Undertow.
I would like to add the header filter that only allows the request with RequestProperty like below code.
con.setRequestProperty("X-Client-Token", TOKEN);
con.setRequestProperty("X-Client-Secret", SECRET);
I have been written the method to check the header after receiving the request by using HttpServerExchange exchange after implement io.undertow.server.HttpHandler. But I need to use this method for each request after receiving.
So. It's there any other way to check and filter the header parameters in undertow without using Wildfly server. And how to do it.
Thank you.
I have used Spring Amqp Outbound Gateway integration to send request to a third party web service. Below shown is my gateway interface.
public interface AccountManagerGateway {
public RetrieveAccountResponse retrieveAccount(RetrieveAccountRequest request);
}
I need to know how to send custom Message Headers with the gateway call.
Ex:- "AccountID" in the header
I did some google searches but couldn't find a solution. May be I'm doing the search in a wrong context or a wrong direction. I'm expecting your kind support on this.
Please let me know if you need more info. I didn't post my integration-context xml in here because then the post will get lengthy.
Thanks.
See the documentation about gateways.
For example:
public RetrieveAccountResponse retrieveAccount(RetrieveAccountRequest request,
#Header("AccountId") String accountId);
By default, user-defined headers are not sent over AMQP so you need to configure the mapped-request-headers on the outbound gateway; something like
mapped-request-headers="STANDARD_REQUEST_HEADERS,AccountId"
Again, refer to the documentation.
I need to access a HTTPS Resource which is using Basic Authentication and It is a GET Resource. I have written a code in java using URIBuilder and adding the username, password etc as Headers to the URIBuilder and using Apache HTTPClient to access the resource and it is working well.
Now my requirement is to implement the same functionality using Apache Camel, Well I tried using Camel HTTP component and by using Java DSL.
The problem is I am just able to provide the URI. But how can I add various Headers to this URI ?.
I suggest you use the http4 component as a way to consume this secure resource. From reading the docs of the component you can see it's possible to set the query parameters, path and even uri at runtime.
In answer to your specific question, the headers on the exchange at the point it reaches the .to() will be sent as headers in the HTTP request so you may want to define a header filter strategy. It has support for http basic auth and you can set your credentials via the authUsername and authPassword headers. You may need to provide a custom HttpContext because you're authenticating via https as it suggests at the bottom of the docs. For example:
from("direct:in")
.process(new Processor() {
public void process(Exchange exchange) {
//These headers you set here will get sent with the http request in the to() after this processor
exchange.getIn().setHeader("authUsername", "username");
exchange.getIn().setHeader("authPassword", "password");
}
})
.to("https4://uri.com);
Use the simple language to add headers if you are using blueprint or the java dsl if its pure java. Simple example:
from("direct:start")
.setHeader(Exchange.HTTP_METHOD, constant(org.apache.camel.component.http4.HttpMethods.POST))
.to("http4://www.google.com")
.to("mock:results");
I am sending a xml from a seda queue to a JMS queue. I have some metadeta in exchange's header which I want to pass to the JMS queue.
Do I have to explicitly get the metadata from exchange object's header, Then set it to the xml? Or Is there anyway if Camel can do it out of the box?
"set it to the XML"? Camel will place the headers as camel exchange headers that will be converted automatically to JMS properties. There should be no XML involved. If you need the headers to be placed in the XML body, you need to do this manually.