Apache Camel Fuse soap CXF代理服务元帅jacksonXML输出

问题描述

我使用Red Hat Fuse CodeReady Studio12.16.0.GA。我已经使用CXF创建了肥皂代理服务。

这是代理服务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>

以下是生成的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,QName serviceName,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;
    }

}

真实的Web服务位于[http://webservices.oorsprong.org/websamples.countryinfo/CountryInfoService.wso] [1]

这是我的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返回VsetkyInformacieKrajinyResponse类对象中的数据。然后我做了元帅jacksonxml,但是关于输出类型的问题我却得到了例外

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)

怎么了?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...