Removing namespace from Soap Response Camel CXF - soap

Below is my sample Soap Response for a service hosted in camel cxf
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns2:XpgIntegratedPaymentResponse xmlns:ns2="http://test:9090/wsx/services/WemXpgPaymentService"/>
</soap:Body>
</soap:Envelope>
Now I don't want to generate "ns2" namespace prefix in response.
Can anyone help?

if you want to drop the namespace of that element so that it is serialized as no-namespaced XpgIntegratedPaymentResponse, the common approach is to use CXF's transform feature.
see more info here:
http://cxf.apache.org/docs/transformationfeature.html#TransformationFeature-Changinginputandoutputelementnamesandnamespaces
in your particular case, you will need the following entry
<entry key="{http://test:9090/wsx/services/WemXpgPaymentService"}XpgIntegratedPaymentResponse"
value="XpgIntegratedPaymentResponse"/>

Are you using Camel 2.11+ ? You can control the namespaces mapping:
Taken from:
http://camel.apache.org/jaxb.html
When marshalling using JAXB or SOAP then the JAXB implementation will automatic assign namespace prefixes, such as ns2, ns3, ns4 etc. To control this mapping, Camel allows you to refer to a map which contains the desired mapping.
Notice this requires having JAXB-RI 2.1 or better (from SUN) on the classpath, as the mapping functionality is dependent on the implementation of JAXB, whether its supported.
For example in Spring XML we can define a Map with the mapping. In the mapping file below, we map SOAP to use soap as prefix. While our custom namespace "http://www.mycompany.com/foo/2" is not using any prefix.
<util:map id="myMap">
<entry key="http://www.w3.org/2003/05/soap-envelope" value="soap"/>
<!-- we dont want any prefix for our namespace -->
<entry key="http://www.mycompany.com/foo/2" value=""/>
</util:map>
To use this in JAXB or SOAP you refer to this map, using the namespacePrefixRef attribute as shown below. Then Camel will lookup in the Registry a java.util.Map with the id "myMap", which was what we defined above.
<marshal>
<soapjaxb version="1.2" contextPath="com.mycompany.foo" namespacePrefixRef="myMap"/>
</marshal>

Related

How to implement Callback interface using REST API with GET operation in Mule?

How to implement Callback interface using REST API with GET operation in Mule? Any reference example with Mule is welcome
Here are the steps with sample code (with a few assumptions stated at the end):
create RAML mapping in your project's src/main/api:
#%RAML 0.8
---
title: sample
/YourServiceEndpoint
get:
responses:
200:
body:
application/json:
Use APIKit Router in Mule to create a mapping in src/main/app. This uses GET as per the question (you can substitute with POST or any other REST action when writing integration tests for your use-case):
<!-- /api/v1 is defined in the APIKit configuration -->
<flow name="get:/api/v1/YourServiceEndPoint">
<http:inbound-endpoint exchange-pattern="request-response" connector-ref="HTTP_HTTPS" ref="HTTP" doc:name="HTTP"/>
<apikit:router config-ref="APIKitRouter" doc:name="APIkit Router"/>
<exception-strategy ref="Standard_Error_Responses" doc:name="Reference Exception Strategy"/>
<!-- do all other stuff here; for example -->
<when expression="#[payload.containsKey("resultSet1") && payload.get("resultSet1").size() > 0]">
<set-payload value="#[payload.get("resultSet1").get(0)]" doc:name="Set Payload"/>
<json:object-to-json-transformer doc:name="Object to JSON"/>
</when>
</flow>
The above connector-ref requires your global configuration (most probably defined as global-configuration.xml in your project) to have a configuration snippet similar to one as follows:
<https:connector name="HTTPS" enableCookies="true" cookieSpec="netscape" validateConnections="true" sendBufferSize="0" receiveBufferSize="0" receiveBacklog="0" clientSoTimeout="10000" serverSoTimeout="10000" socketSoLinger="0" doc:name="HTTP\HTTPS">
<https:tls-server path="${truststoreLocation}" storePassword="${truststorePassword}"/>
</https:connector>
Assumptions:
APIKit Router requires Enterprise license from Mulesoft/Salesforce, otherwise this does not work.
The snippet paths assume use of Maven. Choose Project > Mavenize if your project does not support maven already.
This is just a suggestion and not relevant to the question. The use-case states "huge data load", which implies this should be handled differently by architecture -- you should probably use SFTP instead of HTTP/HTTPS API.
Helpful note(s):
There are additional samples within the application's Help menu which demonstrate the use of SOAP, Callable interface, etc. That will allow you to move forward.

Apache camel endpoint handling

I have an applicationContext xml file that imports multiple resources (camel context files).
<import resource="AddRequest.xml" >
<import resource="AdviseRequest.xml" >
I am caching the definitions of this xml before hand using new FileSystemXmlApplicationContext().
Say AddRequest.xml uses some method to connect to some host, while AdviseRequest.xml uses CXF endpoint to SOAP.
When I try to load the applicationContext xml, it tries to caches both files first before actually starting camelContext. At this stage, it is trying to check the CXF endpoint availabilty. Is there anyway to handle this, if the soap wsdl is actually down ?
The reason is, if there's some connection issues in the second xml, my first xml also fails, as it tries to cache both at a time.
Note: I cannot use two separate applicationContext files
I have used below code in the camel route.
<onException id="Request_onException1">
<exception>java.net.ConnectException</exception>
<handled>
<constant>true</constant>
</handled>
</onException>

Meaning of name attribute in JBoss MBean xml descriptor

JBoss 4/5 MBeans such as NamingAlias are defined in XML as follows
<mbean code="org.jboss.naming.NamingAlias" name=":service=NamingAlias,fromName=queue/original">
<attribute name="ToName">queue/linked</attribute>
<attribute name="FromName">queue/original</attribute>
</mbean>
Paying attention to the attributename=":service=NamingAlias,fromName=queue/original I see the parameters service and fromName.
Following the instructions to create a custom MBean here:
https://developer.jboss.org/wiki/ExampleHelloWorldService
The XML configuration for the MBean created is
<server>
<mbean code="com.acme.HelloWorldService" name="acme.com:service=HelloWorld">
<attribute name="Message">Hello World</attribute>
</mbean>
</server>
I noticed only service is specified in the name attribute.
Is service mandatory for all the beans? What about adding additional parameters such as fromName? Can these values be used from within the class that implements the MBean or are those mandated?
The name attribute can be any valid (and unique) JMX ObjectName. The keys and values themselves do not have any special significance other than their subjective significance to the developer.
In the first example, the ObjectName does not specify a domain (the value to the left of the colon) so the MBeanServer assumes the default domain, which in this case would be jboss so notionally:
:service=NamingAlias,fromName=queue/original == jboss:service=NamingAlias,fromName=queue/original
The ObjectName (and it's embedded domain and key/values) can be used within the class. In standard JMX, one would typically make the impl implement MBeanRegistration which injects the MBeanServer and ObjectName when the bean is registered. However, the example you referenced is a specialized JBoss ServiceMBean which does this automatically and your implementation will store the ObjectName in the field called serviceName.

Camel Restlet maxThreads Component Option

I have a problem. The apache camel documentation states that for the camel-restlet component (starting from 2.10 version) is possible to define the max number of threads that will service requests (http://camel.apache.org/restlet.html).
How can i specify this parameter?
This is the route that I made
from(
"restlet:http://localhost:" + config.getEmergencyRESTPort()
+ "?restletMethods=post,get&restletUriPatterns=#emergencyUriTemplates&maxThreads=64").process(
new EmergencyServerProcessor(config, emergencyService));
I used the maxThreads parameter in the url but it doesn't work.
What is the error?
maxThreads is not a URI option but rather it is a component option.
You can configure your restlet component by creating a bean like this:
<bean id="restlet" class="org.apache.camel.component.restlet.RestletComponent">
<property name="maxThreads" value="50"/>
</bean>

Order of execution of RequestHandlers configured in Apache CXF and JAX-RS

I am in process of implementing a REST API server using Apache CXF JAX-RS v(2.30). I am using spring as container. I am thinking of making use of org.apache.cxf.jaxrs.ext.RequestHandler to implement few features like license check, authentication, authorization (All of which has custom code). My idea is to segregate this code in individual implementation classes (implementing RequestHandler) and configure it for a base REST url something like /rest/*. Being new to Apache CXF and JAX-RS, I want to understand following things.
Is this approach the right way to implement the features I want to?
If yes, then is the order in which the RequestHandlers are declared is the order of their invocation?
For example if in my definition I declare:
<beans>
<jaxrs:server id="abcRestService" address="/rest">
<jaxrs:serviceBeans>
<bean class="com.abc.api.rest.service.FooService" />
</jaxrs:serviceBeans>
<jaxrs:providers>
<ref bean="licenseFilter" />
<ref bean="authorizationFilter" />
</jaxrs:providers>
</jaxrs:server>
<bean id="licenseFilter" class="com.abc.api.rest.providers.LicenseValidator">
<!-- License check bean properties -->
</bean>
<bean id="authorizationFilter" class="com.abc.api.rest.providers.AuthorizationFilter">
<!-- authorization bean properties -->
</bean>
</beans>
then will the licenseFilter always get invoked before authorizationFilter?
I did not find a mention of invocation ordering of RequestHandlers as well as ResponseHandlers.
Thanks in advance.
Figured this out.
It gets invoked in the order of declaration of beans in <jaxrs:providers>. Thus in case mentioned in question, licenseFilter will get invoked before authorizationFilter.