使用Camel和CXF进行WSDL响应

时间:2014-01-01 12:02:13

标签: wsdl cxf apache-camel wsdl2java

虽然我已与他们互动多年,但我对WSDL设计并不陌生。我有一个WSDL,我正在尝试使用Camel& CXF使用wsdl2java生成代码。

我想要实现的是SOAP客户端的自定义响应字符串,并将SOAP请求转换为JSON并将其推送到websockets端点。

我的WSDL架构在生成代码时生成响应类,但似乎从未在调试器中调用响应。

更重要的是,如果我删除Camel中的json转换器,整个soap请求将返回给SOAP客户端,如果我将转换器留在其中,则会因为期望XML而获得json blob而感到不安。

 <cxf:cxfEndpoint id="position-ws"
                 address="/positions"
                 endpointName="c:PositionsPort"
                 serviceName="c:PositionsService"
                 serviceClass="com.company.finance.positions.PositionsImpl"
                 xmlns:c="http://positions.finance.company.com/">
    <cxf:properties>
        <entry key="schema-validation-enabled" value="true"></entry>
    </cxf:properties>
                 </cxf:cxfEndpoint>

<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
    <dataFormats>
        <xmljson id="xmljson"/>
        <xmljson id="xmljsonWithOptions" forceTopLevelObject="true" trimSpaces="true" rootName="newRoot" skipNamespaces="true"
                 removeNamespacePrefixes="true" expandableProperties="d e"/>
    </dataFormats>

    <route>
        <from uri="cxf:bean:position-ws?dataFormat=PAYLOAD"/>
        <convertBodyTo type="String"></convertBodyTo>
        <to uri="log:com.mycompany.order?level=DEBUG"/>
        <process ref="xmlTransformProcessor"/>
        <to uri="log:com.mycompany.order?level=DEBUG"/>
        <to uri="websocket:positionsTopic?sendToAll=true"/>

    </route>
</camelContext>

<bean id="xmlTransformProcessor" class="com.company.finance.positions.XMLTransformer"/>

XML to Json Converter

public class XMLTransformer implements Processor {

public void process(Exchange exchange) throws Exception {

    String data = exchange.getIn().getBody(String.class);


    JSONObject jsonObj = XML.toJSONObject(data);
    String json = jsonObj.toString();

    // use regular java code to transform to a better form
    //exchange.getIn().setBody(json);
    exchange.getOut().setBody(json);
}

}

所以我的问题是,使用Camel,我如何返回自定义响应字符串“Okay”,“Not Okay”等,同时将其余数据推送到路径中的另一个步骤?

由于

1 个答案:

答案 0 :(得分:0)

神秘解决了。

我需要类似的东西:

 <route>
        <from uri="cxf:bean:position-ws"/>
        <to uri="log:com.mycompany.order?level=DEBUG"/>
        <convertBodyTo type="com.company.finance.positions.PositionSummary"/>
        <marshal>
        <jaxb contextPath="com.meteoriteconsulting.finance.positions"
        partClass="com.company.finance.positions.NewEntry"
        fragment="true"
        partNamespace="{http://com.company}NewEntry" />
        </marshal>
        <process ref="xmlTransformProcessor"/>
        <to uri="log:com.mycompany.order?level=DEBUG"/>
        <to uri="websocket:positionsTopic?sendToAll=true"/>
        <transform>
            <constant>OK</constant>
        </transform>

    </route>