本文介绍了Apache的骆驼SOAP请求类型转换错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想送在Apache的骆驼上OSGi的环境(karaf)运行的SOAP请求。到现在为止,我得到这个code

 公共无效启动(BundleContext的上下文)抛出异常{
    LOGGER.log(Level.INFO,START);    MyRouteBuilder routeBuilder =新MyRouteBuilder();
    camelContext =新DefaultCamelContext();    StreamComponent流=新StreamComponent();
    camelContext.addComponent(流流);    camelContext.addRoutes(routeBuilder);    CxfComponent CXF =新CxfComponent();
    camelContext.addComponent(CXF,CXF);    尝试{
        ProducerTemplate模板= camelContext.createProducerTemplate(0);
        camelContext.start();
        字符串URL =CXF:// HTTP://some.server/webservice?
                += WSDLURL HTTP://some.server/webservice WSDL和放大器;
                +服务名= {HTTP://some.server}服务与;
                += PORTNAME {HTTP://some.server} ServiceSoapPort
                +&放大器; DATAFORMAT = MESSAGE;
        Exchange电子邮件= sendSimpleMessage(模板,URL);
        LOGGER.log(。Level.INFO,e.getOut()getBody()的toString());
    }赶上(例外五){
        LOGGER.log(Level.SEVERE,ERROR:);
    }}公共无效停止(BundleContext的上下文){
    LOGGER.log(Level.INFO,STOP);    尝试{
        camelContext.stop();
    }赶上(例外五){
        LOGGER.log(Level.INFO,e.toString());
    }}私有静态交易所sendSimpleMessage(ProducerTemplate模板,
        字符串endpointUri){    最终名单<串GT; PARAMS =新的ArrayList<串GT;();
    地图<弦乐,对象>标题=新的HashMap<弦乐,对象>();
    headers.put(CxfConstants.OPERATION_NAME,验证);
    headers.put(requestObject,新DefaultCxfBinding());
    params.add(世界你好);    外汇汇率= template.request(endpointUri,新处理器(){
        公共无效过程(最后交易交换)抛出异常{
            的SOAPMessage的SOAPMessage = createSOA prequest();            soapMessage.setContentDescription(someId);
            soapMessage.setProperty(键,值);
            soapMessage.setProperty(键,值);
            soapMessage.setProperty(键,值);            soapMessage.setContentDescription();
            soapMessage.setProperty(键,值);            。exchange.getIn()setBody(soapMessage.getSOAPBody());
        }
    });
    返回交流;}私有静态的SOAPMessage createSOA prequest()抛出异常{
    的MessageFactory的MessageFactory = MessageFactory.newInstance();
    的SOAPMessage的SOAPMessage = messageFactory.createMessage();
    SOAPPart中的SOAPPart = SOAPMessage.getSOAPPart来();    字符串serverURI =HTTP://some.server    // SOAP信封
    信封的SoapEnvelope = soapPart.getEnvelope();
    envelope.addNamespaceDeclaration(,serverURI);    javax.xml.soap.SOAPBody的SOAPBody = envelope.getBody();
    的SOAPElement soapBodyElem = soapBody.addChildElement(getApplication
            例);    的MimeHeaders头= soapMessage.getMimeHeaders();
    headers.addHeader(的SOAPAction,HTTP://some.server/someFunction);    soapMessage.saveChanges();    LOGGER.log(Level.INFO,soapMessage.toString());    返回的SOAPMessage;
}

而现在我在karaf日志中得到这个错误

  java.lang.IllegalArgumentExcetion:找不到财产合适的setter方法​​:PORTNAME因为没有setter方法​​同类型:java.lang.String中也没有类型转换可能: java.lang.String中所要求的类型:无可用类型转换器从类型转换javax.xml.namespace.QName中值为[...]

和同样的情况,当我删除PORTNAME服务名 - 那么怎么可能通过这些参数作为javax.xml.namespace.QName中?或者是有什么我做错了吗?

编辑:
得到同样的错误当我把它简化为这个

 从(直接:启动)
            .process(新处理器(){                公共无效过程(外汇兑换)抛出异常{
                    exchange.getIn()setBody(&所述; mandant> 001&下; /&下; mandant>中)。
                }
            })
            。要(CXF:// HTTP://some.server/webservice?
            += WSDLURL HTTP://some.server/webservice WSDL和放大器;
            +服务名= {HTTP://some.server}服务与;
            += PORTNAME {HTTP://some.server} ServiceSoapPort
            +&放大器; DATAFORMAT = MESSAGE)
            。要(?文件:C:/输出文件名= soap.txt);


解决方案

这是你需要的是 CxfConverter 它通常由Spring使用蓝图 AnnotationTypeConverterLoader 。您可以类型转换器添加到CamelContext如但它仅适用于实现类型转换器接口的类,但CxfConverter是@Converter注解,它应该用发现被发现。

我不知道如何解决,但我希望你这个信息进一步得到。如果你想出解决​​办法,请更新在这里。

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;
}

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 [...]

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?

EDIT: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");
解决方案

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的骆驼SOAP请求类型转换错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 23:19