我试图在运行在osgi环境(karaf)上的apache camel发送肥皂请求。到现在为止我得到了这段代码
public void start(BundleContext context) throws Exception {
LOGGER.log(Level.INFO, "START");
MyRouteBuilder routeBuilder = new MyRouteBuilder();
camelContext = new DefaultCamelContext();
StreamComponent stream = new StreamComponent();
camelContext.addComponent("stream", stream);
camelContext.addRoutes(routeBuilder);
CxfComponent cxf = new CxfComponent();
camelContext.addComponent("cxf", cxf);
try {
ProducerTemplate template = camelContext.createProducerTemplate(0);
camelContext.start();
String url = "cxf://http://some.server/webservice?"
+ "wsdlURL=http://some.server/webservice?wsdl&"
+ "serviceName={http://some.server}Service&"
+ "portName={http://some.server}ServiceSoapPort"
+ "&dataFormat=MESSAGE";
Exchange e = sendSimpleMessage(template, url);
LOGGER.log(Level.INFO, e.getOut().getBody().toString());
} catch (Exception e) {
LOGGER.log(Level.SEVERE, "ERROR: ");
}
}
public void stop(BundleContext context) {
LOGGER.log(Level.INFO, "STOP");
try {
camelContext.stop();
} catch (Exception e) {
LOGGER.log(Level.INFO, e.toString());
}
}
private static Exchange sendSimpleMessage(ProducerTemplate template,
String endpointUri) {
final List<String> params = new ArrayList<String>();
Map<String, Object> headers = new HashMap<String, Object>();
headers.put(CxfConstants.OPERATION_NAME, "authenticate");
headers.put("requestObject", new DefaultCxfBinding());
params.add("hello world");
Exchange exchange = template.request(endpointUri, new Processor() {
public void process(final Exchange exchange) throws Exception {
SOAPMessage soapMessage = createSOAPRequest();
soapMessage.setContentDescription("someId");
soapMessage.setProperty("key", "value");
soapMessage.setProperty("key", "value");
soapMessage.setProperty("key", "value");
soapMessage.setContentDescription("");
soapMessage.setProperty("key", "value");
exchange.getIn().setBody(soapMessage.getSOAPBody());
}
});
return exchange;
}
private static SOAPMessage createSOAPRequest() throws Exception {
MessageFactory messageFactory = MessageFactory.newInstance();
SOAPMessage soapMessage = messageFactory.createMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
String serverURI = "http://some.server";
// SOAP Envelope
SOAPEnvelope envelope = soapPart.getEnvelope();
envelope.addNamespaceDeclaration("", serverURI);
javax.xml.soap.SOAPBody soapBody = envelope.getBody();
SOAPElement soapBodyElem = soapBody.addChildElement("getApplication",
"example");
MimeHeaders headers = soapMessage.getMimeHeaders();
headers.addHeader("SOAPAction", "http://some.server/someFunction");
soapMessage.saveChanges();
LOGGER.log(Level.INFO, soapMessage.toString());
return soapMessage;
}
现在我的karaf日志中出现了这个错误
java.lang.IllegalArgumentExcetion: Could not find a suitable setter for property: portName as there isn't a setter method with same type: java.lang.String nor type conversion possible: No type converter available to convert from type: java.lang.String to the required type: javax.xml.namespace.QName with value [...]
当我删除portName时,serviceName也会发生同样的情况 - 那么如何将这些参数作为javax.xml.namespace.QName传递呢?或者还有什么我做错了吗?
修改 当我将其简化为
时,会出现同样的错误 from("direct:start")
.process(new Processor() {
public void process(Exchange exchange) throws Exception {
exchange.getIn().setBody("<mandant>001</<mandant>");
}
})
.to("cxf://http://some.server/webservice?"
+ "wsdlURL=http://some.server/webservice?wsdl&"
+ "serviceName={http://some.server}Service&"
+ "portName={http://some.server}ServiceSoapPort"
+ "&dataFormat=MESSAGE")
.to("file:C:/output?fileName=soap.txt");
答案 0 :(得分:1)
你需要的TypeConverter是CxfConverter它通常由Spring或Blueprint使用AnnotationTypeConverterLoader加载到CamelContext。您可以将TypeConverters添加到CamelContext,如this,但它仅适用于实现TypeConverter接口的类,但CxfConverter是@Converter注释,应该使用发现找到它。
我不知道如何解决这个问题,但我希望你能进一步了解这些信息。如果你搞清楚了,请在这里更新。