【发布时间】:2014-01-01 12:02:13
【问题描述】:
虽然我已经与他们互动多年,但我对 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 到 Json 转换器
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”等,同时将其余数据推送到路径中的另一个步骤?
谢谢
【问题讨论】:
标签: wsdl cxf apache-camel wsdl2java