Camel CXF producer basic auth - authentication

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

Related

can't find my url service on jax-rs and wildfly

I have this service
#ApplicationPath("/services") public class MyRestEasyApplication extends Application {
Packeged package bitsexcel.ws.resteasy.services; My project is named RsJavaWeb and run in this url http://localhost:8080/RsJavaWeb/ on Wilfly Server
I have not web.xml descriptor with nothing except <welcome-file-list>
I can't find my service in any url
I tried with:
http://localhost:8080/RsJavaWeb/services/person/1
http://localhost:8080/RsJavaWeb/ ?
And ever more but I can't find the service
Find the context root of your application (you can see it from WildFly UI console).
Then you should send requests at http://localhost:8080/{context-root}/services/...

register server wide javax.ws.rs.client.ClientRequestFilter on JBoss EAP 7

Is it possible to register a javax.ws.rs.client.ClientRequestFilter server wide on JBoss EAP 7? I would like to intercept all outbound JAX-RS calls to dynamically add some context information in HTTP headers.
For JAX-WS calls I was able to do this with https://access.redhat.com/documentation/en-us/red_hat_jboss_enterprise_application_platform/7.0/html-single/developing_web_services_applications/#jax_ws_handler_chains. I can't find any documentation on a similar mechanism for JAX-RS.
Or alternatively, is there maybe another way to intercept outbound HTTP calls in general?
For a per server solution, according to Using HttpHandler class in Undertow "you need to package your handler(s) into a module, and configure custom-filter in undertow subsystem."
The module.xml example and undertow configuration has been given as well as filter source code!
Update
There's an example of using the HTTPExchange here though I dont really care much for that site. SO also has this slightly related example - it does look like it can work similarly to the JAX-WS Handlers/Interceptor How to properly read post request body in a handler
Another good example file upload using httphandler I know they're different that dealing with JAX-RS but still may apply.
I implemented it by creating a module with the following contents:
package be.fgov.kszbcss.tracer.jaxrs;
import org.jboss.resteasy.client.jaxrs.ResteasyClient;
import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder;
public class TracerResteasyClientBuilder extends ResteasyClientBuilder {
#Override
public ResteasyClient build() {
return super.build().register(TracerJaxRsClientRequestFilter.class);
}
}
/META-INF/services/javax.ws.rs.client.ClientBuilder
be.fgov.kszbcss.tracer.jaxrs.TracerResteasyClientBuilder
And registering it as a global module on JBoss EAP.

Mule: How to prevent WS Consumer generating headers in the request?

I'm using WS Consumer component to call an external Web Servcie and
I'm looking for a way to prevent generation of a SOAP header in the request.
I've found how to do this when using cxf component explicitly:
<cxf:configuration enableMuleSoapHeaders="false"/>
and then same in <cxf:jaxws-client ...
But I can't figure out how to achieve the same when using WS Consumer.
So, can someone pls advice?
Thank you,
Ok, I've found the answer by myself.
Basically, WS Consumer (v3.7) doesn't have an attribute similar to the enableMuleSoapHeaders from the cxf component.
So, you'll need to code the logic in java.
First, you need to code your own CXF interceptor that would go through the message and remove the unnecessary headers.
Then, you need to create a cxf configuration file (the default name is cxf.xml) and put it into the mule project classpath.
Once this is done, Mule will call the interceptor for every cxf message processed and remove the headers.
For more info about coding and configuring cxf interceptor look at the apache documentation here.

Apache Camel Restlet - Unable to set Authorization parameter in Header

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);

Mule 3.4.0 Get HTTPRequest object from http inbound endpoint

I have an http:inbound-endpoint. Is there any way to get a handle to HttpServletRequest object in a Filter/Interceptor? Is ObjectToHttpClientMethodRequest an answer? If so, could someone please provide a sample?
If you are running Mule in a servlet container, you need to use servlet:inbound-endpoint, not http:inbound-endpoint.
But even with that, I do not think Mule lets you access the underlying HttpServletRequest...