I'm trying to call a web service exposed by third party. After receiving the response I'm wrapping the response to the appropriate class. While marshalling the object of the wrapper class to xml string using "jaxb" I'm getting the error as:
org.apache.camel.NoTypeConversionAvailableException: No type converter
available to convert from type:
com.unifyv4.ws.CreateOrganisationResponse to the required type:
java.io.InputStream with value
com.unifyv4.ws.CreateOrganisationResponse#312ea56e
Detailed Stack Trace:
n | BodyType com.unifyv4.ws.CreateOrganisationResponse
n | Body
com.unifyv4.ws.CreateOrganisationResponse#2c9a5080
n | ]n | n | Stacktracen |
java.io.IOException:
org.apache.camel.NoTypeConversionAvailableException: No type converter
available to convert from type:
com.unifyv4.ws.CreateOrganisationResponse to the required type:
java.io.InputStream with value
com.unifyv4.ws.CreateOrganisationResponse#2c9a5080
at org.apache.camel.converter.jaxb.JaxbDataFormat.marshal(JaxbDataFormat.java:141)[235:org.apache.camel.camel-jaxb:2.15.1.redhat-621084]
at org.apache.camel.processor.MarshalProcessor.process(MarshalProcessor.java:83)[198:org.apache.camel.camel-core:2.15.1.redhat-621084]
at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77)[198:org.apache.camel.camel-core:2.15.1.redhat-621084]
at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:448)[198:org.apache.camel.camel-core:2.15.1.redhat-621084]
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)[198:org.apache.camel.camel-core:2.15.1.redhat-621084]
at org.apache.camel.processor.Pipeline.process(Pipeline.java:121)[198:org.apache.camel.camel-core:2.15.1.redhat-621084]
at org.apache.camel.processor.Pipeline.access$100(Pipeline.java:44)[198:org.apache.camel.camel-core:2.15.1.redhat-621084]
at org.apache.camel.processor.Pipeline$1.done(Pipeline.java:139)[198:org.apache.camel.camel-core:2.15.1.redhat-621084]
at org.apache.camel.processor.CamelInternalProcessor$InternalCallback.done(CamelInternalProcessor.java:251)[198:org.apache.camel.camel-core:2.15.1.redhat-621084]
at org.apache.camel.processor.RedeliveryErrorHandler$1.done(RedeliveryErrorHandler.java:460)[198:org.apache.camel.camel-core:2.15.1.redhat-621084]
at org.apache.camel.management.InstrumentationProcessor$1.done(InstrumentationProcessor.java:86)[198:org.apache.camel.camel-core:2.15.1.redhat-621084]
at org.apache.camel.processor.SendProcessor$1.done(SendProcessor.java:149)[198:org.apache.camel.camel-core:2.15.1.redhat-621084]
at org.apache.camel.component.cxf.CxfClientCallback.handleResponse(CxfClientCallback.java:61)[207:org.apache.camel.camel-cxf:2.15.1.redhat-621084]
at org.apache.cxf.endpoint.ClientImpl.onMessage(ClientImpl.java:823)[74:org.apache.cxf.cxf-core:3.0.4.redhat-621084]
at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponseInternal(HTTPConduit.java:1644)[96:org.apache.cxf.cxf-rt-transports-http:3.0.4.redhat-621084]
at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream$1.run(HTTPConduit.java:1155)[96:org.apache.cxf.cxf-rt-transports-http:3.0.4.redhat-621084]
at org.apache.cxf.workqueue.AutomaticWorkQueueImpl$3.run(AutomaticWorkQueueImpl.java:428)[74:org.apache.cxf.cxf-core:3.0.4.redhat-621084]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)[:1.8.0_40]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)[:1.8.0_40]
at org.apache.cxf.workqueue.AutomaticWorkQueueImpl$AWQThreadFactory$1.run(AutomaticWorkQueueImpl.java:353)[74:org.apache.cxf.cxf-core:3.0.4.redhat-621084]
at java.lang.Thread.run(Thread.java:745)[:1.8.0_40]
Caused by: org.apache.camel.NoTypeConversionAvailableException: No
type converter available to convert from type:
com.unifyv4.ws.CreateOrganisationResponse to the required type:
java.io.InputStream with value
com.unifyv4.ws.CreateOrganisationResponse#2c9a5080
at org.apache.camel.impl.converter.BaseTypeConverterRegistry.mandatoryConvertTo(BaseTypeConverterRegistry.java:177)[198:org.apache.camel.camel-core:2.15.1.redhat-621084]
at org.apache.camel.core.osgi.OsgiTypeConverter.mandatoryConvertTo(OsgiTypeConverter.java:122)[204:org.apache.camel.camel-blueprint:2.15.1.redhat-621084]
at org.apache.camel.converter.jaxb.JaxbDataFormat.marshal(JaxbDataFormat.java:172)[235:org.apache.camel.camel-jaxb:2.15.1.redhat-621084]
at org.apache.camel.converter.jaxb.JaxbDataFormat.marshal(JaxbDataFormat.java:138)[235:org.apache.camel.camel-jaxb:2.15.1.redhat-621084]
... 20 more
Below is the blueprint.xml file and class where I'm trying to marshal the response object.
Blueprint.xml
<cxf:rsServer id="crmRequest" address="http://localhost:9002/rest/" serviceClass="com.spectranet.createEnterpriseCustomer.ReceiveEnterpriseRequest" />
<bean id="crmRequestBean" class="com.spectranet.createEnterpriseCustomer.ReceiveEnterpriseRequest" />
<bean id="myProcessor" class="com.spectranet.createEnterpriseCustomer.MyProcessor" />
<bean id="myProcessor2" class="com.spectranet.createEnterpriseCustomer.MyProcessor2" />
<bean id="dozerConverterLoader" class="org.apache.camel.converter.dozer.DozerTypeConverterLoader">
<argument index="0" ref="myCamel" />
<argument index="1" ref="createOrg" />
</bean>
<bean id="createOrg" class="org.apache.camel.converter.dozer.DozerBeanMapperConfiguration">
<property name="mappingFiles">
<list>
<value>transformation.xml</value>
</list>
</property>
</bean>
<cxf:cxfEndpoint id="unifyCreateOrg" address="http://203.122.58.158:9080/unifyejb/CRMAPI" serviceClass="com.unifyv4.ws.CRMAPI" serviceName="com.unifyv4.ws.CRMAPIService" wsdlURL="wsdl/CRMAPI_WSDL.wsdl" />
<camelContext id="myCamel" xmlns="http://camel.apache.org/schema/blueprint">
<endpoint uri="dozer:createOrg?sourceModel=com.spectranet.createEnterpriseCustomer.CRMCAFRequest&targetModel=com.unifyv4.ws.CreateOrganisation&mappingFile=transformation.xml" id="crmToUnify"/>
<dataFormats>
<jaxb contextPath="generated" id="generated"/>
<jaxb contextPath="com.unifyv4.ws" prettyPrint="true" encoding="UTF-8" partClass="com.unifyv4.ws.CreateOrganisationResponse" id="myPartialJaxb"/>
</dataFormats>
<route>
<from uri="cxfrs:bean:crmRequest" id="crmRequest">
<description/>
</from>
<convertBodyTo type="com.spectranet.createEnterpriseCustomer.CRMCAFRequest"/>
<to pattern="InOut" ref="crmToUnify"/>
<setHeader headerName="Username">
<constant>admin</constant>
</setHeader>
<setHeader headerName="Password">
<constant>admin</constant>
</setHeader>
<setHeader headerName="operationName">
<constant>createOrganisation</constant>
</setHeader>
<setHeader headerName="operationNameSpace">
<constant>http://ws.unifyv4.com/</constant>
</setHeader>
<log message="customer: ${in.body.organisation.customer}"/>
<log message="ipAddress: ${in.body.sessionObject.ipAddress}"/>
<process ref="myProcessor"/>
<to pattern="InOut" uri="cxf:bean:unifyCreateOrg"/>
<marshal ref="myPartialJaxb"/>
<log message="Messsage from soap call is : ${body}"/>
</route>
</camelContext>
Java Code to Marshal the object to xml.
package com.spectranet.createEnterpriseCustomer;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import com.unifyv4.ws.CreateOrganisationResponse;
import com.unifyv4.ws.Organisation;
public class MyProcessor2 implements Processor {
public void process(Exchange exchng) throws Exception {
CreateOrganisationResponse orgResponse = new CreateOrganisationResponse();
orgResponse.setReturn(exchng.getIn().getBody(Organisation.class));
System.out.println("Organisation Created : " + orgResponse.getReturn().getOrgNo());
exchng.getIn().setBody(orgResponse);
}
}
Kindly please provide any suggestions if any.
First of all, may I know why you want to marshal ?
Looking at route, I dont think you need to marshal any payload.
Just play around XPATH, XSLT & Camel. Camel becomes more complicated in-fact, if you want to marshal and unmarshal. I am not saying its wrong, I am saying its easier without the hassle of marshal, unmarshal, etc. Because ultimately thats what all frameworks do internally. :)
Eg: https://github.com/gnanagurus/camel-guru-projects/tree/master/camel-cxf-geocoder-example
Cheers
This issue can come when the generated class does not contain XML root element tag. Because of it, framework can not explicitly convert the objects to XML and vice versa.
Hence you are creating the response via processor, please refer your WSDL and create the wrapper response as well.
Thanks
Shiv
Related
I want to create a rest api where i send the json request payload and it should change the json key value based on rule defined using rule mediator
i have already tried the Sample 600 and modified with below code to achieve my requirement.
<rule xmlns:brs="http://wso2.org/carbon/rules">
<source xpath="//val"/>
<target action="replace" resultXpath="//val" xpath="//val"/>
<ruleSet>
<properties/>
<rule resourceType="regular" sourceType="inline"><![CDATA[
rule Invokeval
when
val: String()
eval(val.equals("someval"))
then update(drools.getWorkingMemory().getFactHandle(val),"WORKINGDROOL");
end
]]></rule>
</ruleSet>
<input namespace="http://services.samples" wrapperElementName="jsonObject">
<fact elementName="val" namespace="http://services.samples" type="java.lang.String" xpath="//val"/>
</input>
<output namespace="http://services.samples" wrapperElementName="jsonObject">
<fact elementName="val" namespace="http://services.samples" type="java.lang.String"/>
</output>
</rule>
getting RuleMediator invalde source value Error
I have configured JMS receiver in WSO2 DAS something like below xml. Now I am configuring receiver xml file for each stream. I see there is no configuration difference except stream name change (streamName="TABLE_NAME"). Is there any way I can use single event receiver for multiple streams to avoid duplicate code.
<?xml version="1.0" encoding="UTF-8"?>
<eventReceiver name="divolte_events_data_receiver" statistics="enable"
trace="enable" xmlns="http://wso2.org/carbon/eventreceiver">
<from eventAdapterType="jms">
<property name="transport.jms.DestinationType">queue</property>
<property name="transport.jms.Destination">MyQueue</property>
<property name="java.naming.factory.initial">org.wso2.andes.jndi.PropertiesFileInitialContextFactory</property>
<property name="java.naming.provider.url">repository/conf/jndi.properties</property>
<property name="transport.jms.SubscriptionDurable">false</property>
<property name="transport.jms.ConnectionFactoryJNDIName">QueueConnectionFactory</property>
<property name="transport.jms.UserName">admin</property>
<property encrypted="true" name="transport.jms.Password">***</property>
</from>
<mapping customMapping="disable" type="json"/>
<to streamName="TABLE_NAME" version="1.0.0"/>
Its not possible with DAS as receivers are bound to streams and the flow. For JMS it looks like same but generally there are other receiver types which requires its own receiver. Ex:- In Http receivers different endpoints will be created for each receiver where as JSON event structure is based on the stream bound to the receiver
I'm implementing a web service using camel cxf to be deployed in Karaf.
I'm using the pax web that comes with karaf. I'm using the cxf codegen plugin in pom to do wsdl to java.
I'm defining the cxf uri and the routes in the RouteBuilder Java DSL. The blueprint.xml only has some beans and ref to the RouteBuilder.
final String cxfUri =
String.format("cxf:%s?serviceClass=%s&wsdlURL=wsdl/Event.wsdl",
"/Event.jws", com.example.EventPortType.class.getCanonicalName());
I have setup ssl with the pax-web(jetty.xml). If i send the WSSE security headers with username and password, it generates a MustUnderstand soap fault.
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" S:mustUnderstand="1">
<wsse:UsernameToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="Id-LdZa8aaGdy7mWQWXLp_zpbfg">
<wsse:Username>xxx</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">xxx</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
The input request cannot be changed.
I get this exception.
<soap:Fault>
<faultcode>soap:MustUnderstand</faultcode>
<faultstring>MustUnderstand headers: [{http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd}Security] are not understood.</faultstring>
</soap:Fault>
How can i secure the cxf endpoint to authenticate the request?
Thank you.
you need to add a WSS4J interceptors to the exposed CXF service. You can provide your own PasswordCallback for the user validation, but I prefer to leverage the native JAAS. This is a blueprint example requiring the UsernameToken with any Karaf user (this is for exposing a camel-cxf routes, however the same principle applies to the pure CXF implementation). If you prefer Java based Camel route builders, you may add the interceptor beans to the context registry to use them. But - the blueprint (or spring config) allows you to more fine-grained control than simple endpoint parameters.
<?xml version="1.0" encoding="UTF-8"?>
<blueprint
xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cxf="http://cxf.apache.org/blueprint/core"
xmlns:camelcxf="http://camel.apache.org/schema/blueprint/cxf"
xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0"
xmlns:jaxws="http://cxf.apache.org/blueprint/jaxws"
xsi:schemaLocation="
http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd http://camel.apache.org/schema/blueprint
http://camel.apache.org/schema/blueprint/camel-blueprint.xsd http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0
http://svn.apache.org/repos/asf/aries/trunk/blueprint/blueprint-cm/src/main/resources/org/apache/aries/blueprint/compendium/cm/blueprint-cm-1.1.0.xsd
http://cxf.apache.org/blueprint/core http://cxf.apache.org/schemas/blueprint/core.xsd
http://cxf.apache.org/blueprint/jaxws http://cxf.apache.org/schemas/blueprint/jaxws.xsd
http://camel.apache.org/schema/blueprint/cxf http://camel.apache.org/schema/cxf/camel-cxf-2.7.5.xsd">
<bean id="authenticationInterceptor" class="org.apache.cxf.interceptor.security.JAASLoginInterceptor">
<property name="contextName" value="karaf"/>
<property name="roleClassifier" value="RolePrincipal"/>
<property name="roleClassifierType" value="classname"/>
</bean>
<bean id="wsSecInterceptor" class="org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor">
<argument>
<map>
<entry key="action" value="UsernameToken"/>
<entry key="passwordType" value="PasswordText"/>
</map>
</argument>
</bean>
<!-- ================ Apache Camel impl ======================= -->
<camelcxf:cxfEndpoint id="testService2"
address="/api/2.0/external/TestService"
xmlns:apogado="http://test.ws.apogado.com/v1_0/ws"
endpointName="apogado:AddressServicePort"
serviceName="apogado:AddressService"
wsdlURL="classpath:/xsd/ws/TestService.wsdl"
>
<camelcxf:properties>
<entry key="dataFormat" value="PAYLOAD" />
<entry key="ws-security.ut.no-callbacks" value="true"/>
<entry key="ws-security.validate.token" value="false"/>
</camelcxf:properties>
<camelcxf:inInterceptors>
<ref component-id="wsSecInterceptor" />
<ref component-id="authenticationInterceptor"/>
</camelcxf:inInterceptors>
<camelcxf:features>
</camelcxf:features>
</camelcxf:cxfEndpoint>
<camelContext xmlns="http://camel.apache.org/schema/blueprint" id="testWsCtx" trace="true">
<!-- your service implementation -->
<route>
<from uri="testService2" />
<to uri="..." />
<route>
</camelContext>
</blueprint>
I have a Soap web services exposed through Springs...
I need to expose the WSDL for the same. My Bean definition to expose the WSDL is as shown below.
<bean id="schemaCollection" class="org.springframework.xml.xsd.commons.CommonsXsdSchemaCollection">
<description>
This bean wrap the messages.xsd (which imports types.xsd), and inlines them as a one.
</description>
<property name="xsds">
<list>
<value>/WEB-INF/classes/schema/HL7V3/NE2008/multicacheschemas/PRPA_IN201301UV02.xsd</value>
<value>/WEB-INF/classes/schema/HL7V3/NE2008/multicacheschemas/PRPA_IN201302UV02.xsd</value>
<value>/WEB-INF/classes/schema/HL7V3/NE2008/multicacheschemas/PRPA_IN201304UV02.xsd</value>
<value>/WEB-INF/classes/schema/HL7V3/NE2008/multicacheschemas/MCCI_IN000002UV01.xsd</value>
<value>/WEB-INF/classes/schema/HL7V3/NE2008/multicacheschemas/PRPA_IN201309UV02.xsd</value>
<value>/WEB-INF/classes/schema/HL7V3/NE2008/multicacheschemas/PRPA_IN201310UV02.xsd</value>
</list>
</property>
<property name="inline" value="true"/>
</bean>
<bean id="pixManager" class="org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition">
<property name="schemaCollection" ref ="schemaCollection"/>
<property name="portTypeName" value="PIXManager_PortType"/>
<property name="locationUri" value="/services/pixManager/"/>
</bean>
The problem I am facing here is I have child XSDs that are referred from these XSDs as shown below which is not getting resolved.
<xs:include schemaLocation="../coreschemas/infrastructureRoot.xsd"/>
I am getting the following error..
Caused by: org.springframework.xml.xsd.commons.CommonsXsdSchemaException: Schema [ServletContext resource [/WEB-INF/classes/schema/HL7V3/NE2008/multicaches
chemas/PRPA_IN201301UV02.xsd]] could not be loaded; nested exception is java.lang.IllegalArgumentException: The resource path [/../coreschemas/infrastructu
reRoot.xsd] has been normalized to [null] which is not valid
Where [/../coreschemas/infrastructu
reRoot.xsd] is the relative path of the child XSDs.
You need extract only schemas required for your interaction(s), so the folder structure will be like this:
../coreschemas
../schemas
and then "flatten" an interaction schema and related schemas into one which you may then embed into your WSDL.
I have implemented a web services using JaxWS-Spring. I would like to log the XML being received. I have tried various attempts, among which to add the proper categories to my log4j.properties file and using interceptors. However I have always failed for one reason or another (logging seems to be ignored - adding interceptors to my application context gives other issues).
The following snippets from my project :
PS: I am using Spring 2.5.6
web.xml
<servlet>
<servlet-name>jaxws-servlet</servlet-name>
<servlet-class>com.sun.xml.ws.transport.http.servlet.WSSpringServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- Mapping to redirect all requests from 'FaxWebService' to jaxws-servlet. -->
<servlet-mapping>
<servlet-name>jaxws-servlet</servlet-name>
<url-pattern>/FaxWebService</url-pattern>
</servlet-mapping>
applicationContext.xml
<!-- Bind the URL FaxWebService to our bean FaxWebService. -->
<wss:binding url="/FaxWebService">
<wss:service>
<ws:service bean="#faxWebService"/>
</wss:service>
</wss:binding>
<!-- Bean responsible of taking care of the webservice. -->
<bean id="faxWebService" class="com.connexo.icubeplus3.dispatcher.webservices.FaxWebService"
scope="singleton">
<property name="dummyMode" value="${fax.dummy.mode}"/>
</bean>
I doubt this has anything to do with Spring WS to be honest.
If you want to log the incoming messages in Spring WS, you want to raise the logging level for org.springframework.ws.client.MessageTracing.sent and org.springframework.ws.client.MessageTracing.received to TRACE. For example, in log4j config:
<logger name="org.springframework.ws.client.MessageTracing.sent">
<level value="TRACE" />
<appender-ref ref="stdout" />
</logger>
<logger name="org.springframework.ws.client.MessageTracing.received">
<level value="TRACE" />
<appender-ref ref="stdout" />
</logger>
You will have to write a handler to log it. There are various examples in the web, like http://docs.oracle.com/cd/E13222_01/wls/docs103/webserv_adv_rpc/handlers.html