Interceptor for all calls in servicemix - interceptor

What is the best way to add an interceptor to servicemix that would log all webservice calls (or calls to osgi components would also work)?
I know of the NMR interceptors, but these apparently don't work for CXF.
And I know about "jaxws:inInterceptors" but these need to be added to each endpoint manually.
I would like to intercept the calls to all endpoints (WS and RS) with a single configuration/interceptor, is this possible in servicemix?

you can just add CXF logging feature like this
<!-- adding the feature to the bus-->
<cxf:bus>
<cxf:features>
<cxf:logging/>
</cxf:features>
</cxf:bus>

Related

How to add an trailing slash to the camel http component of camel

Im am trying to call a rest post service from my Camel route.
The rest service is deployed at https://csp-verteileauftrag-camunda-v1-csp-ims-dev-az.apcn.osp4-preprod.hel.kko.ch/api/v1/verteileauftrag/.
Calling the Service from a Rest Client like VS Code works if there is a trailing slash (after verteileauftrag).
In my camel route I have configured the following:
restConfiguration().host("https://csp-verteileauftrag-camunda-v1-csp-ims-dev-az.apcn.osp4-preprod.hel.kko.ch/api/v1").component("http").bindingMode(RestBindingMode.json);
and in then later using the config:
.to("rest:post:verteileauftrag?outType=ch.helsana.csp.verteileauftrag.rest.model.apiadapter.ResponseType")
If I execute the code, I get a 404 HTTP Error from the Backend as the URL used is
https://csp-verteileauftrag-camunda-v1-csp-ims-dev-az.apcn.osp4-preprod.hel.kko.ch/api/v1/verteileauftrag. So without a trailing slash.
I have tried to add it like .to("rest:post:verteileauftrag/?outType=ch.helsana.csp.verteileauftrag.rest.model.apiadapter.ResponseType")
but no success.
Do you have any idea how to tell the http component in the rest configuration how to add the trailing slash?
Thank you very much.
Using redhat fuse 7_10_2.
Regards Michel
Based on a collegues example I reimplemented the Rest Service call with a normal .to("URL") configuration in the routebuilder with setting the appropriate Headers for HTTP Post and content type json. Would still be interessted in any answer, but not waiting on one.

No endpoint could be found for - Camel Http Integration

I'm trying to run a simple test with Apache Camel:
from("http://localhost:61554/api/v1/MyController/my-endpoint")
.to("direct:a")
.log("$({body}");
I'm getting the following error: "No endpoint could be found for: http://localhost:61554/api/v1/MyController/my-endpoint, please check your classpath contains the needed Camel component jar"
I'm very new to Camel and Java. Can someone please tell me why this error is coming up? Should I be using from("direct:x")... ? If, so where do I map my "direct" endpoints to concrete ones?
Thanks
You cannot use the http component as consumer (eg in from) - its a http client for calling HTTP servers (so its a producer, eg to).
Instead to have HTTP as consumer you can use camel-servlet, camel-jetty, camel-undertow, etc.

Adding Authorization Header with Camel restlet component

I've been using restlet camel component to communicate with endpoints fine for a couple of weeks now, but after I had the need to add an Authorization header to my requests, that's when I kept getting this warning:
WARNING: Addition of the standard header "Authorization" is not allowed. Please use the equivalent property in the Restlet API.
Which blocks the header from being added to the outgoing message.
I've seen solutions for this for using restlet, but I don't have the luxury when using it as a camel component.
I've tried using the org.restlet.http.headers attribute but still get the same message.
Any ideas how to make it send out my authorization header?
(I would rather not use the http component)
Note: I'm using Camel 2.19.2, same version for restlet
There is a ticket at Restlet to support this, however they have not implemented this: https://github.com/restlet/restlet-framework-java/issues/1198
There is also a Camel ticket: https://issues.apache.org/jira/browse/CAMEL-10665
As it seems Restlet takes forever to fix this on their side, we may have to bit the bullet and make a special fix in the camel-restlet component

Best way to implement ebXml/ebMs with apache camel

First of all, I haven't found any generic open source implementation for ebxml/ebms, for me it's somehow strange or maybe I have looked up the wrong stuff, but I haven't found here something rly usefull.
When I was looking for ebxml/ebms I have also found JAXM/SAAJ(JSR 67). It looks like this implementations never got to an end, all links regarding this are refering to the sun homepage which doesn't exist anymore. From the sun homepage you get redirected to the oracle homepage, and there I can't find something about JAXM or JSR 67.
This leads me to my question, how to implement an ebxml service in apache camel?
Should I create the ebxml SOAP message "manually" or are there some libs I've missed that are generating such an ebxml message for me?`
How to send such an ebXml SOAP message via apache camel? Cxf needs an wsdl, for the service we want to call there exists no wsdl.
How to recieve such ebXml messages? Cxf see above, maybe with an http consumer like netty-http or jetty?
A few years too late, but maybe valuable for others :)
There is an open source implementation available which supports the ebMS 2.0 spec.
This ebMS adapter can be deployed as a Mule ESB plugin or as a regular WAR application.
https://sourceforge.net/projects/muleebmsadapter/
Despite being on sourceforge, it is still being actively developed.
You can use velocity template to create the ebxml SOAP message manually, for example.
Template example:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
xmlns:ser="http://test/Service">
<soap:Header/>
<soap:Body>
<ser:insertRequest>
<ser:routingHeader>
<ser:operationType>${headers.OPERATION_TYPE}</ser:operationType>
<ser:messageId>${exchange.properties.messageId}</ser:messageId>
<ser:sourceId>${exchange.properties.sourceId}</ser:sourceId>
<ser:destinationId>${exchange.properties.destinationId}</ser:destinationId>
</ser:routingHeader>
<ser:datagram>
${body}
</ser:datagram>
</ser:insertRequest>
</soap:Body>
</soap:Envelope>
You can use http, http4 or jetty components to send such an ebXml SOAP message via apache camel.
to("jetty:http://{{server.host}}:{{server.http.port}}/service/").
log(LoggingLevel.INFO, "HTTP response code: ${in.header.CamelHttpResponseCode}")
After you only need to parse SOAP response manually (XPath, maybe), or you can transform response by XSLT.
Maybe you can use beanio, xstream or jaxb and so on to transform XML to POJO.
....
to("velocity:file:///{{karaf.home}}/etc/vm/ws-message-oc.vm?contentCache=true").
setProperty(Exchange.CONTENT_TYPE).constant("application/soap+xml").
setProperty(Exchange.CONTENT_ENCODING).constant("gzip").
setProperty(Exchange.CHARSET_NAME).constant("utf-8").
//log(LoggingLevel.INFO, "WS request: ${body}").
to("jetty:http://{{app-server.host}}:{{app-server.http.port}}/service/").
log(LoggingLevel.INFO, "HTTP response code: ${in.header.CamelHttpResponseCode}")
//log(LoggingLevel.INFO, "WS response: ${body}")
.setHeader("callRC").xpath("//ser:callRC/text()", String.class, XmlNamespaces.NAMESPACES.getNamespace())
....

Create proxy for Apache CXF Web services in wso2 ESB

I am a very beginner in ESB. So, kindly excuse me for this basic question.
Currently we have web services created with Apache CXF and Spring running. Now, we need to create proxy services for these in WSo2 ESB. Can someone please let us know how can we do this?
I created Pass Through proxy and use wsdl definition as from URL, but when i use try it option i get he endpoint reference (EPR) for the Operation not found is /services/ and the WSA Action = null.
If this EPR was previously reachable,please contact the server administrator.
Since ESB 4.6, pass-through transport is enabled by default : The message body is not build so, SOAP Body based dispatching is not supported => in this case, the error you're speaking about is thrown
One solution could be to add this parameter in your proxy conf : <parameter name="disableOperationValidation" locked="false">true</parameter>
Have a look there for other options : Using WSO2 ESB PassThrough Proxy on WebLogic (Spring) Web Service
How did you create the proxy service? If you have the wsdl of the Backend service you can use it to create the proxy service like follows.
<proxy xmlns="http://ws.apache.org/ns/synapse" name="testProxy2" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">
<target>
<outSequence>
<send/>
</outSequence>
<endpoint>
<wsdl service="SimpleStockQuoteService"
port="SimpleStockQuoteServiceHttpSoap11Endpoint"
uri="http://localhost:9000/services/SimpleStockQuoteService?wsdl"/>
</endpoint>
</target>
<description/>
</proxy>
The ESB gets the endpoint url from the Service name and Port defined in the WSDL. For SOAP 1.1 the WSA action will be the SOAPAction header and for SOAP 1.2 the WSA action goes with the action element of Content-Type header. For example,
Content-Type: application/soap+xml;charset=UTF-8;action="TheSoapAction"
Try to use a SOAP client like SOAPUI to test your proxy service.

Resources