无法将CXF Web服务对象解组为XML

时间:2016-07-04 05:54:45

标签: web-services jaxb apache-camel jbossfuse fuseesb

我正在尝试调用第三方公开的网络服务。收到响应后,我将响应包装到相应的类中。在使用“jaxb”将包装类的对象编组为xml字符串时,我收到的错误为:

  

org.apache.camel.NoTypeConversionAvailableException:没有类型转换器   可以转换类型:   com.unifyv4.ws.CreateOrganisationResponse为所需类型:   带有值的java.io.InputStream   com.unifyv4.ws.CreateOrganisationResponse@312ea56e

     

详细的堆栈跟踪:

     

n | BodyType com.unifyv4.ws.CreateOrganisationResponse   n |车身
    com.unifyv4.ws.CreateOrganisationResponse@2c9a5080

     

n | ] n | n | Stacktracen |

     

java.io.IOException的:   org.apache.camel.NoTypeConversionAvailableException:没有类型转换器   可以转换类型:   com.unifyv4.ws.CreateOrganisationResponse为所需类型:   带有值的java.io.InputStream   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]
     

引起:org.apache.camel.NoTypeConversionAvailableException:没有   type转换器可以转换类型:   com.unifyv4.ws.CreateOrganisationResponse为所需类型:   带有值的java.io.InputStream   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

下面是我正在尝试编组响应对象的blueprint.xml文件和类。

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&amp;targetModel=com.unifyv4.ws.CreateOrganisation&amp;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代码将对象编组为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);
    }
}

请提供任何建议。

2 个答案:

答案 0 :(得分:0)

首先,我可以知道你为什么要编组吗?

看着路线,我认为你不需要整理任何有效载荷。

玩XPATH,XSLT&amp;骆驼。事实上,如果你想要编组和解组,骆驼会变得更加复杂。我并没有说错了,我说它更容易,没有元帅,解组等麻烦。因为最终这就是所有框架在内部所做的事情。 :)

例如:https://github.com/gnanagurus/camel-guru-projects/tree/master/camel-cxf-geocoder-example

干杯

答案 1 :(得分:0)

当生成的类不包含XML根元素标记时,可能会出现此问题。因此,框架无法将对象显式转换为XML,反之亦然。

因此,您正在通过处理器创建响应,请参阅您的WSDL并创建包装器响应。

由于 希夫