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

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.

Related

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.

twisted.web.client HTTP logging

How can I log the HTTP requests and responses when using twisted.web.client? I've checked the docs and sources and didn't find anything but maybe it's possible using some custom agents or some such?
There is no built-in support for this, but you can implement your own IAgent, that does logging and delegates to another IAgent, perhaps using proxyForInterface.

Repeatedly calling a web service in mule

I am working on a mule studio application in which I am calling a soap web service for getting status of a particular process. If the status is PENDING, I have to call the same web service until the status become COMPLETED. What approach I have to take for implementing this scenario.
Thank You in advance.
Take a look at the until-successful router: http://www.mulesoft.org/documentation/display/current/Until+Successful+Scope
You can configure the failureExpression to check if the status is 'PENDING'.
As Ryan Carter said, you can use the Until Successful router in order to achieve this.
You need to configure the failureExpression attribute to return 'true' if you want to call the web service again.
Note also that you can configure the until successful to be "synchronous" instead of the default "asynchronous". The former configuration does not require an object store.

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...

Camel CXF producer basic auth

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