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");
Related
I'm trying to handle a redirect with a Spring WebClient, using an org.apache.hc.client5.http.impl.async.HttpAsyncClient under the hood, and forward the sensitive headers in the redirect request. I see examples in previous versions that there is a way using a .followRedirect(boolean followRedirect, Consumer<HttpClientRequest> redirectRequestConsumer) configuration, but that doesn't appear to exist in the current version.
My alternative is to turn off following redirect, grab the headers and cookies in the redirect response, and then send off a second request with that information, but that seems like more of a hack than a proper solution.
Thanks!
You set it in the builder
public RequestConfig.Builder setRedirectsEnabled(boolean redirectsEnabled)
And set your RequestConfig in your RequestBuilder
See also See setRedirectStrategy
I want to route requests based on some values in requestBody in spring cloud, for example:
if value of firstField in requestBody is chagre, I want to route this request to /chagre api
else if value of firstField in requestBody is package, I want to route this request to /package api
Any help would be appreciated.
Best practice is not to route according to request body, but use different attributes of the HTTP request instead. Spring Cloud Gateway includes many built-in route predicate factories based on those attributes.
The problem is request body can be read only once. moreover you need to know the object class it contains in order to properly read it.
In order to construct a solution to your question, we can use Spring Cloud Gateway ModifyRequestBody to rewrite the request body after you read it and before it send to the downstream.
Read more about ModifyRequestBody
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'm sure there is an easy answer for this, but I'm only finding JS/Node examples on Amazon's site.
I'm trying to get the full request from the Gateway to pass to the AWS Lambda. I know you can build your own POJO, and I've got that working for a simple app. It looks like I really want to be using Lambda proxy integration, but I can't figure out what Amazon classes the RequestHandler expects for the Request and Response if I use the proxy integration.
My questions are:
Am I going down the right path for getting the complete request using the Lambda proxy integration?
What Java classes should I be using in the RequestHandler?
Thanks!
You can use the following handler structure:
#Override
class Handler implements RequestHandler<Map<String,Object>, Map<String,Object>> {
public Map<String,Object> handleRequest(Map<String,Object> input, Context context) {
// ...
}
}
Your response object should be a Map with
statusCode: HTTP response code (e.g., 200)
headers: a Map of HTTP headers (e.g., "Content-type"="application/json")
body: the actual response content (described by the Content-Type header)
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.