You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Peter Turányi <pe...@pobox.sk> on 2020/10/05 06:29:16 UTC

Apache Camel Fuse soap CXF proxy service marshal jacksonXML output

   <https://stackoverflow.com/posts/64181884/timeline>
  
I use Red Hat Fuse CodeReady Studio 12.16.0.GA. I have created soap proxy service using CXF.
Here is main part of proxy service wsdl.
<?xml version="1.0" encoding="UTF-8"?> <definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:tns="http://www.demo.com/countryinfo" name="CountryInfoService" targetNamespace="http://www.demo.com/countryinfo"> <types> <xs:schema elementFormDefault="qualified" targetNamespace="http://www.demo.com/countryinfo"> <xs:complexType name="tCountryInfo"> <xs:sequence> <xs:element name="Kod_ISO" type="xs:string"/> <xs:element name="Nazov" type="xs:string"/> <xs:element name="Hlavne_mesto" type="xs:string"/> <xs:element name="Telefonny_kod" type="xs:string"/> <xs:element name="Kod_kontinentu" type="xs:string"/> <xs:element name="ISO_kod_meny" type="xs:string"/> <xs:element name="Vlajka" type="xs:string"/> <xs:element name="Jazyk" type="tns:ArrayOftLanguage"/> </xs:sequence> </xs:complexType> <xs:complexType name="tLanguage"> <xs:sequence> <xs:element name="Kod_ISO" type="xs:string"/> <xs:element name="Nazov" type="xs:string"/> </xs:sequence> </xs:complexType> <xs:complexType name="ArrayOftLanguage"> <xs:sequence> <xs:element name="tLanguage" type="tns:tLanguage" minOccurs="0" maxOccurs="unbounded" nillable="true"/> </xs:sequence> </xs:complexType> <xs:element name="VsetkyInformacieKrajiny"> <xs:complexType> <xs:sequence> <xs:element name="Kod_krajiny" type="xs:string"/> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="VsetkyInformacieKrajinyResponse"> <xs:complexType> <xs:sequence> <xs:element name="FullCountryInfoResult" type="tns:tCountryInfo"/> </xs:sequence> </xs:complexType> </xs:element> </xs:schema> </types> <message name="FullCountryInfoSoapRequest"> <part name="parameters" element="tns:VsetkyInformacieKrajiny"/> </message> <message name="FullCountryInfoSoapResponse"> <part name="parameters" element="tns:VsetkyInformacieKrajinyResponse"/> </message> <portType name="CountryInfoServiceSoapType"> <operation name="FullCountryInfo"> <documentation>Returns a struct with all the stored country information. Pass the ISO country code</documentation> <input message="tns:FullCountryInfoSoapRequest"/> <output message="tns:FullCountryInfoSoapResponse"/> </operation> </portType> <binding name="CountryInfoServiceSoapBinding" type="tns:CountryInfoServiceSoapType"> <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/> <operation name="FullCountryInfo"> <soap:operation soapAction="" style="document"/> <input> <soap:body use="literal"/> </input> <output> <soap:body use="literal"/> </output> </operation> </binding> <service name="CountryInfoService"> <port name="CountryInfoServiceSoap" binding="tns:CountryInfoServiceSoapBinding"> <soap:address location="http://localhost:8080/CountryInfoProxyService"/> </port> </service> </definitions> Here are are snippets of generated java clasess
 CountryInfoService.java
package com.demo.countryinfo; import java.net.MalformedURLException; import java.net.URL; import javax.xml.namespace.QName; import javax.xml.ws.WebEndpoint; import javax.xml.ws.WebServiceClient; import javax.xml.ws.WebServiceFeature; import javax.xml.ws.Service; /** * This DataFlex Web Service opens up country information. 2 letter ISO codes are used for Country code. There are functions to retrieve the used Currency, Language, Capital City, Continent and Telephone code. * * This class was generated by Apache CXF 3.3.6.fuse-780020 * 2020-10-03T09:01:57.443+02:00 * Generated source version: 3.3.6.fuse-780020 * */ @WebServiceClient(name = "CountryInfoService", wsdlLocation = "file:/C:/RedHat/workspace/CountryInfoServiceProxy/src/main/resources/CountryInfoProxyService.wsdl", targetNamespace = "http://www.demo.com/countryinfo") public class CountryInfoService extends Service { public final static URL WSDL_LOCATION; public final static QName SERVICE = new QName("http://www.demo.com/countryinfo", "CountryInfoService"); public final static QName CountryInfoServiceSoap = new QName("http://www.demo.com/countryinfo", "CountryInfoServiceSoap"); static { URL url = null; try { url = new URL("file:/C:/RedHat/workspace/CountryInfoServiceProxy/src/main/resources/CountryInfoProxyService.wsdl"); } catch (MalformedURLException e) { java.util.logging.Logger.getLogger(CountryInfoService.class.getName()) .log(java.util.logging.Level.INFO, "Can not initialize the default wsdl from {0}", "file:/C:/RedHat/workspace/CountryInfoServiceProxy/src/main/resources/CountryInfoProxyService.wsdl"); } WSDL_LOCATION = url; } public CountryInfoService(URL wsdlLocation) { super(wsdlLocation, SERVICE); } public CountryInfoService(URL wsdlLocation, QName serviceName) { super(wsdlLocation, serviceName); } public CountryInfoService() { super(WSDL_LOCATION, SERVICE); } public CountryInfoService(WebServiceFeature ... features) { super(WSDL_LOCATION, SERVICE, features); } public CountryInfoService(URL wsdlLocation, WebServiceFeature ... features) { super(wsdlLocation, SERVICE, features); } public CountryInfoService(URL wsdlLocation, QName serviceName, WebServiceFeature ... features) { super(wsdlLocation, serviceName, features); } /** * * @return * returns CountryInfoServicePortType */ @WebEndpoint(name = "CountryInfoServiceSoap") public CountryInfoServicePortType getCountryInfoServiceSoap() { return super.getPort(CountryInfoServiceSoap, CountryInfoServicePortType.class); } /** * * @param features * A list of {@link javax.xml.ws.WebServiceFeature} to configure on the proxy. Supported features not in the <code>features</code> parameter will have their default values. * @return * returns CountryInfoServicePortType */ @WebEndpoint(name = "CountryInfoServiceSoap") public CountryInfoServicePortType getCountryInfoServiceSoap(WebServiceFeature... features) { return super.getPort(CountryInfoServiceSoap, CountryInfoServicePortType.class, features); } } CountryInfoServicePortType.java
package com.demo.countryinfo; import javax.jws.WebMethod; import javax.jws.WebParam; import javax.jws.WebResult; import javax.jws.WebService; import javax.jws.soap.SOAPBinding; import javax.xml.bind.annotation.XmlSeeAlso; import javax.xml.ws.RequestWrapper; import javax.xml.ws.ResponseWrapper; /** * This class was generated by Apache CXF 3.3.6.fuse-780020 * 2020-10-03T09:01:57.434+02:00 * Generated source version: 3.3.6.fuse-780020 * */ @WebService(targetNamespace = "http://www.demo.com/countryinfo", name = "CountryInfoServicePortType") @XmlSeeAlso({ObjectFactory.class}) public interface CountryInfoServicePortType { /** * Returns a struct with all the stored country information. Pass the ISO country code */ @WebMethod(operationName = "FullCountryInfo") @SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE) @WebResult(name = "VsetkyInformacieKrajinyResponse", targetNamespace = "http://www.demo.com/countryinfo", partName = "parameters") public VsetkyInformacieKrajinyResponse fullCountryInfo( @WebParam(partName = "parameters", name = "VsetkyInformacieKrajiny", targetNamespace = "http://www.demo.com/countryinfo") VsetkyInformacieKrajiny parameters ); } VsetkyInformacieKrajinyResponse.java
package com.demo.countryinfo; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; /** * <p>Java class for anonymous complex type. * * <p>The following schema fragment specifies the expected content contained within this class. * * <pre> * &lt;complexType&gt; * &lt;complexContent&gt; * &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"&gt; * &lt;sequence&gt; * &lt;element name="FullCountryInfoResult" type="{http://www.demo.com/countryinfo}tCountryInfo"/&gt; * &lt;/sequence&gt; * &lt;/restriction&gt; * &lt;/complexContent&gt; * &lt;/complexType&gt; * </pre> * * */ @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "", propOrder = { "fullCountryInfoResult" }) @XmlRootElement(name = "VsetkyInformacieKrajinyResponse") public class VsetkyInformacieKrajinyResponse { @XmlElement(name = "FullCountryInfoResult", required = true) protected TCountryInfo fullCountryInfoResult; /** * Gets the value of the fullCountryInfoResult property. * * @return * possible object is * {@link TCountryInfo } * */ public TCountryInfo getFullCountryInfoResult() { return fullCountryInfoResult; } /** * Sets the value of the fullCountryInfoResult property. * * @param value * allowed object is * {@link TCountryInfo } * */ public void setFullCountryInfoResult(TCountryInfo value) { this.fullCountryInfoResult = value; } } real web service is on [http://webservices.oorsprong.org/websamples.countryinfo/CountryInfoService.wso][1]
Here is my camel-context.xml
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:camel="http://camel.apache.org/schema/spring" xmlns:camel-cxf="http://camel.apache.org/schema/cxf" xmlns:context="http://www.springframework.org/schema/context" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://camel.apache.org/schema/spring https://camel.apache.org/schema/spring/camel-spring.xsd http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd"> <bean class="org.apache.cxf.transport.common.gzip.GZIPInInterceptor" id="gZipInInterceptor"/> <bean class="org.apache.cxf.transport.common.gzip.GZIPOutInterceptor" id="gZipOutInterceptor"/> <camel-cxf:cxfEndpoint address="http://webservices.oorsprong.org/websamples.countryinfo/CountryInfoService.wso" id="countryInfoServiceClient" serviceClass="org.oorsprong.websamples_countryinfo.CountryInfoServiceSoapType"> <camel-cxf:inInterceptors> <ref bean="gZipInInterceptor"/> </camel-cxf:inInterceptors> <camel-cxf:outInterceptors> <ref bean="gZipOutInterceptor"/> </camel-cxf:outInterceptors> </camel-cxf:cxfEndpoint> <camel-cxf:cxfEndpoint address="http://localhost:8082/CountryInfoProxyService" endpointName="s:CountryInfoServiceSoap" id="countryInfoProxyServiceClient" serviceName="s:CountryInfoService" wsdlURL="CountryInfoProxyService.wsdl" xmlns:s="http://www.demo.com/countryinfo" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/> <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring" xmlns:coun="http://www.demo.com/countryinfo"> <dataFormats> <jacksonxml id="jackFullCountryInfoResponse" unmarshalTypeName="com.demo.countryinfo.VsetkyInformacieKrajinyResponse"/> </dataFormats> <route id="simple-route"> <from id="_to2" uri="cxf:bean:countryInfoProxyServiceClient?dataFormat=RAW"/> <bean beanType="com.demo.TransformationBuilder" id="InputTransformation" method="getVsetkyInformacieKrajinyDoc2Str"/> <setHeader headerName="operationName" id="setHeaderOperationName"> <constant>FullCountryInfo</constant> </setHeader> <setHeader headerName="operationNamespace" id="setHeaderOperationNamespace"> <constant>http://www.oorsprong.org/websamples.countryinfo</constant> </setHeader> <log id="InputService" message="Input service >>> ${body}"/> <to id="_to1" uri="cxf:bean:countryInfoServiceClient"/> <bean beanType="com.demo.TransformationBuilder" id="OutputTransformation" method="getFullCountryInfo2VsetkyInformacieKrajinyResponse"/> <marshal id="jackFullCountryInfoResponse"> <jacksonxml/> </marshal> <log id="_log1" message="Output > ${body}"/> <marshal id="jackFullCountryInfoResponse"> <jacksonxml/> </marshal> </route> </camelContext> </beans> TransformationBuilder returns data in VsetkyInformacieKrajinyResponse class object. Then I do marshal jacksonxml but regardles of output type I get exception
09:08:31.151 [default-workqueue-1] INFO simple-route - Output > <VsetkyInformacieKrajinyResponse><FullCountryInfoResult><Kod_ISO>AD</Kod_ISO><Nazov>Andorra</Nazov><Hlavne_mesto>Andorra La Ville</Hlavne_mesto><Telefonny_kod>371</Telefonny_kod><Kod_kontinentu>EU</Kod_kontinentu><ISO_kod_meny>EUR</ISO_kod_meny><Vlajka>http://www.oorsprong.org/WebSamples.CountryInfo/Flags/Andorra.jpg</Vlajka><Jazyk><tLanguage><tLanguage><Kod_ISO>cat</Kod_ISO><Nazov>Catalan</Nazov></tLanguage><tLanguage><Kod_ISO>es</Kod_ISO><Nazov>Spanish</Nazov></tLanguage><tLanguage><Kod_ISO>fr</Kod_ISO><Nazov>French</Nazov></tLanguage><tLanguage><Kod_ISO>glg</Kod_ISO><Nazov>Gallegan</Nazov></tLanguage><tLanguage><Kod_ISO>por</Kod_ISO><Nazov>Portuguese</Nazov></tLanguage></tLanguage></Jazyk></FullCountryInfoResult></VsetkyInformacieKrajinyResponse> 09:08:31.170 [qtp434466006-29] WARN o.a.cxf.phase.PhaseInterceptorChain - Interceptor for {http://www.demo.com/countryinfo}CountryInfoService has thrown exception, unwinding now java.lang.ClassCastException: [B cannot be cast to [Ljava.lang.Object; at org.apache.camel.component.cxf.DefaultCxfBinding.populateCxfResponseFromExchange(DefaultCxfBinding.java:435) What is wrong?