We are trying to initiate a REST webservice call Using Apache Camel Restlet Component and it was successful.
But we are not able to retrieve the Authorization header property value from request object which we have set in Apache Camel Exchange Header.
exchange.getIn().setHeader("Authorization", "abcde");
Actually we are making this REST call through Camel's Dynamic router.
Can someone suggest how to set the Authorization header in Apache Camel Exchange.
I have found a solution. It might help someone. For adding custom headers in restlet,
Map<String, Object> headers = new HashMap<>();
Series<Header> customHeaders = new Series<Header>(Header.class);
customHeaders.add(new Header("Authorization", "abcde"));
headers.put(HeaderConstants.ATTRIBUTE_HEADERS, customHeaders);
Related
I'm not finding any RestClient method to update its options, what I need to do is for example disable FollowRedirects for certain requests.
How do I do the following but with v107?
client.FollowRedirects = false;
Background: maybe a separate issue but current problem is that RestSharp is not following a redirect URL to Okta from a Location header of a response, it goes to the main Client URL instead. That is why I've decided to disable redirects to try following the redirect manually.
Most if not all of the properties in RestClientOptions are used to configure the HttpMessageHandler instance wrapped by RestClient. As each RestClient instance wraps a single HttpClient (and its handler), those options cannot be changed. It works the same way as configuring HttpClient, where you cannot change the AllowAutoRedirects property of the handler once it's configured.
That's why the documentation suggests using a specifically configured RestClient instance per remote API. Normally, the API uses a single convention and configuration requirement.
I have seen that some authentication endpoints require redirects, but most of the time the RestClient instance used to get the authorization token is not the one used to access the API itself with the retrieved token. So, the solution would be to have a separate instance for that purpose. Normally, it's only used once to get the token, then you can dispose it and reuse the token.
I keep posting the authenticator example from the docs https://restsharp.dev/usage.html#authenticator
Concerning RestSharp not following redirects properly, it's not what RestSharp does as it doesn't compose or execute HTTP calls physically. It just wraps HttpClient.
I am trying to carry out a test as like it explained here:
JMeter Alter HTTP Headers During Test.
Quote from above :
I'm attempting to test an HTTP service with JMeter. The HTTP service requires authentication through a simple bearer token mechanism. I'm trying to proceed as follows:
POST authentication request Store token as a variable
Set Authorization HTTP header to stored variable
Request protected resource(s)
Evaluate performance
When the POST occurs, I am not able to capture the bearer token. Its a header.
I tried the solution provided by Dmitri on that issue Or as Bennet tried with RegEx Extractor and HTTPs Manager.
I think I am doing something silly not to able to extract the token. Any thoughts how to extract the token?
Most likely your Regular Expression Extractor configuration is not correct, by default it:
uses response body as a source therefore you need to switch it to look into response headers (red rectangle)
looks up in main sample only, if your header is set after redirect it won't be processed (amber rectangle)
Example configuration:
You can double check ${bearer} variable value using Debug Sampler and View Results Tree listener combination.
I am using apimanger 1.9.
I read this already : Add header with username into request to backend in wso2 apimanager.
I am able to add and forward username to backend in wso2 apimanager for specific service; but I want this for all service. I am modifying admin--<api_name>_<version>.xml for all services(50 services), which is very much manual. Something it leads to manual error.
Is there a single place configuration where I can set this (forward username to backend endpoint) for all service?
One more question - if I create and publish the APIs using "Publisher API" feature, is there a way to post something to set up the add header for each API?
Modify the velocity_template.xml which decides the template of an API. Please read my answer given to a similar requirement. You need to modify the relevant section in the velocity_template.xml.
I am fairly new to Restlet and wrote small piece of code to make a HTTP call. It is working but I was wondering how can I add HTTP Connection pooling (apache) into it.
I am not able to find any tutorial or reference code for it.
Client client = new Client(Protocol.HTTP);
ChallengeResponse challengeResponse = new ChallengeResponse(
ChallengeScheme.HTTP_AZURE_SHAREDKEY,
acctName,
accKey);
String url = RestHelper.createRequestURI("CCC");
Request request = new Request(Method.GET, url);
request.setChallengeResponse(challengeResponse);
Response response = client.handle(request);
Any references or help will be appreciated.
In fact, Restlet internally manages a pool at the client connector level. Configuration of this pool can be done using the context of your client. The following example describes to configure it:
Client client = new Client(new Context(), Protocol.HTTP);
client.getContext().getParameters().add("maxConnectionsPerHost","5");
client.getContext().getParameters().add("maxTotalConnections","5");
You can notice that these parameters depend on the underlying client connector you use.
Here are some helpful links:
Doc related to connectors: http://restlet.com/technical-resources/restlet-framework/guide/2.3/core/base/connectors
Javadoc containing parameters for the HTTP client connector: http://restlet.com/technical-resources/restlet-framework/javadocs/2.3/jse/ext/org/restlet/ext/httpclient/HttpClientHelper.html
Notice that if you use ClientResource, you need to share the same client to have only one instance of the client connector under the hood. Otherwise a new one is instantiated for each request. See the way to implement this below:
Client client = new Client(new Context(), Protocol.HTTP);
ClientResource cr = new ClientResource("http://myurl");
cr.setNext(client);
Hope it helps,
Thierry
I'm new to Apache Camel and CXF, and I'm trying to create a route for querying a remote WS which requires Basic Authentication and to specify the SoapAction header. I achieved it with the spring-ws component but I was wondering if I could do the same with the cxf component.
My current configuration is:
RouteBuilder
from("file:src/test/resources/data?noop=true")
.to("xquery:transform/search.xquery")
.to("cxf:-----")
.to("log:TestApp");
I've read something about conduits but I don't know how to configure it in my current camel context.
CamelContext
<camel:camelContext xmlns="http://camel.apache.org/schema/spring">
<package>my.package</package>
</camel:camelContext>
Thanks in advance
You can accomplish this with the Camel HTTP component:
http://server.com?authMethod=Basic&authUsername=user&authPassword=password
However, you probably want to take advantage of the functionality that CXF offers.
You can set up a CXF bean in camel and then set up a HTTP conduit to provide the Basic Auth:
http://cxf.apache.org/docs/client-http-transport-including-ssl-support.html#ClientHTTPTransport%28includingSSLsupport%29-BasicAuthentication
<conduit name="https://localhost:.*""
xmlns:sec="http://cxf.apache.org/configuration/security"
xmlns="http://cxf.apache.org/transports/http/configuration">
<authorization>
<sec:UserName>myuser</sec:UserName>
<sec:Password>mypasswd</sec:Password>
<sec:AuthorizationType>Basic</sec:AuthorizationType>
</authorization>
</conduit>
The HTTP Conduit links to the Camel CXF bean using the 'name' parameter. You set it to a URL like I did above or check the documentation for setting it to a URI matching your service.
Thanks,
Yogesh