Apache camel soap request type conversion error(Apache camel soap请求类型转换错误)
问题描述
我正在尝试在 osgi 环境 (karaf) 上运行的 apache camel 中发送一个肥皂请求.直到现在我得到了这个代码
I'm trying to send a soap request in apache camel running on an osgi enviroment (karaf). Until now I got this code
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 日志中出现了这个错误
And now I got this error in my karaf logs
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 传递呢?还是我做错了什么?
And the same happens for serviceName when I delete portName - So how is it possible to pass these arguments as javax.xml.namespace.QName? Or is there anything else I'm doing wrong?
当我将它简化为这个时得到同样的错误
Getting the same error when I simplify it to this
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");
推荐答案
你需要的TypeConverter是CxfConverter 通常由 Spring 或 Blueprint 使用 AnnotationTypeConverterLoader.您可以像 this 一样将 TypeConverters 添加到 CamelContext 但它仅适用于实现 TypeConverter 接口的类,但CxfConverter 是@Converter 注解的,应该使用discovery 找到它.
The TypeConverter that you need is CxfConverter It is normally loaded to CamelContext by Spring or Blueprint using AnnotationTypeConverterLoader. You can add TypeConverters to CamelContext like this but it only works on classes that implement TypeConverter interface but CxfConverter is @Converter annotated and it should be found using discovery.
我不知道如何解决这个问题,但我希望你能进一步了解这些信息.如果你明白了,请在此处更新.
I don't know how to solve this but I hope you get further with this information. Please update here if you figure this out.
这篇关于Apache camel soap请求类型转换错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Apache camel soap请求类型转换错误


基础教程推荐
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- 降序排序:Java Map 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01