当前位置: 首页 > 知识库问答 >
问题:

使用Apache Camel和CXFendpoint调用RPC/encoded Webservice

亢奇
2023-03-14

有很多关于Apache Camel CXF-Endpoint和RPC/编码的遗留Web服务的信息。但是直到现在我都没有找到解决问题的方法。

我想通过CXFendpoint从Apache Camel调用一个RPC/编码的Web服务。CXF不支持RPC/编码的Web服务。所以我尝试了两种方法来解决这个问题。

>

  • 将wsdl从RPC/编码转换为RPC/文字并生成源文件。以CXF支持的RPC/文字样式调用webservice。下面的文章建议这种方法可以解决我的问题:使用RPC/编码网络服务的最佳方式?

    发送完整的SOAP消息,而不映射到对象(无JAXB)。

    方法1和方法2都不起作用。在接下来的章节中,我将更详细地解释我的方法和问题。

    • Apache Tomcat 7
    • Apache骆驼2.14.1
    • Apache CXF 2.7.10
    • Webservice Endpoint在http://localhost:9000/myfunctionalmock上使用SOAP-UI 5.0.0进行了模拟

    在RCP/编码wsdl中,我更改了以下内容:

    WSDL绑定:

    <wsdl:binding name="exampleSoapBinding" type="impl:MyFunctionalWebservices">
       <wsdlsoap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
       <wsdl:operation name="isAlive">
          <wsdlsoap:operation soapAction=""/>
          <wsdl:input name="isAliveRequest">
             <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://my.example.com/myFunction" use="encoded"/>
          </wsdl:input>
    ...
    

    <wsdl:binding name="exampleSoapBinding" type="impl:MyFunctionalWebservices">
       <wsdlsoap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
       <wsdl:operation name="isAlive">
          <wsdlsoap:operation soapAction=""/>
          <wsdl:input name="isAliveRequest">
             <wsdlsoap:body  namespace="http://my.example.com/myFunction" use="literal"/>
          </wsdl:input>
    …
    

    对象数组:

    <complexType name="ArrayOfMyElement">
     <complexContent>
      <restriction base="soapenc:Array">
       <attribute ref="soapenc:arrayType" wsdl:arrayType="impl:MyElement[]"/>
      </restriction>
     </complexContent>
    </complexType>
    

    <complexType name="ArrayOfMyElement">
        <xsd:sequence>
            <xsd:element name="MyElement"
                         type="impl:MyElement"
                         minOccurs="0"
                         maxOccurs="unbounded"/>
        </xsd:sequence>
    </complexType>
    

    简单类型的数组:

    <complexType name="ArrayOf_xsd_string">
     <complexContent>
      <restriction base="soapenc:Array">
       <attribute ref="soapenc:arrayType" wsdl:arrayType="xsd:string[]"/>
      </restriction>
     </complexContent>
    </complexType>
    

    <complexType name="ArrayOf_xsd_string">
        <xsd:sequence>
            <xsd:element name="item"
                         type="xsd:string"
                         minOccurs="0"
                         maxOccurs="unbounded"/>
        </xsd:sequence>
    </complexType>
    

    未定义类型(anyType)的数组:

    <complexType name="ArrayOf_xsd_anyType">
     <complexContent>
      <restriction base="soapenc:Array">
       <attribute ref="soapenc:arrayType" wsdl:arrayType="xsd:anyType[]"/>
      </restriction>
     </complexContent>
    </complexType>
    

    <complexType name="ArrayOf_xsd_anyType">
        <xsd:sequence>
            <xsd:element name="item" 
                         type="xsd:anyType" minOccurs="0" maxOccurs="unbounded"/>
        </xsd:sequence>
    </complexType>
    

    之后,我用IntelliJ Webservice插件生成源文件(通过CXF wsdl2java)

    在Camel中,我配置了以下endpoint:

        CxfEndpoint endpoint = new CxfEndpoint();
        endpoint.setAddress("http://127.0.0.1:9000/myfunctionalmock");
        endpoint.setWsdlURL("wsdl/myservice_literal.wsdl");
        endpoint.setServiceClass("com.my.example.MyFunctionalWebservices");
        endpoint.setEndpointNameString("{http://my.example.com/myFunction}rpcrouter");
        endpoint.setServiceNameString("{http://my.example.com/myFunction}MyFunctionalWebservicesService");
        endpoint.setDataFormat(DataFormat.POJO);
        endpoint.setSynchronous(true);
        endpoint.setCamelContext(camelContext);
        endpoint.setEndpointUriIfNotSpecified(MY_ENDPOINT_URL);
        camelContext.addEndpoint(MY_ENDPOINT_URL, endpoint);
    

    在驼峰路线中使用CXFendpoint:

    我想调用webservice的以下功能:

    public Result isAlive(java.lang.String identifier);
    

    骆驼路线中的计时器仅用于触发Web服务。

        from("timer://myTimer?period=10000")
        .log(LoggingLevel.INFO, "START Timer Webservice.")
        .setBody().constant("1620000018")
        .setHeader("operationName", constant("isAlive"))
        .setHeader("operationNamespace", constant("http://my.example.com/myFunction"))
        .to(MyCamelConfiguration.MY_ENDPOINT_URL);
    

    这种方法的问题:

    在运行时,部署时会出现以下消息:

    2015-03-05 09:57:46,659; 2010; [localhost-startStop-1]; DEBUG;                wsdl11.WSDLServiceBuilder; Operation {http://my.example.com/myFunction}isAlive cannot be unwrapped, input message must reference global element declaration with same localname as operation
    

    运行时发生以下异常:

    org.apache.cxf.binding.soap.SoapFault: No namespace on "HTML" element. You must send a SOAP request.
            at org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor.readVersion(ReadHeadersInterceptor.java:111)
            at org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor.handleMessage(ReadHeadersInterceptor.java:155)
            at org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor.handleMessage(ReadHeadersInterceptor.java:62)
            at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:272)
            at org.apache.cxf.endpoint.ClientImpl.onMessage(ClientImpl.java:835)
            at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponseInternal(HTTPConduit.java:1614)
            at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponse(HTTPConduit.java:1504)
            at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1310)
            at org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:56)
            at org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:628)
            at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:62)
            at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:272)
            at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:565)
            at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:474)
            at org.apache.camel.component.cxf.CxfProducer.process(CxfProducer.java:149)
            at org.apache.camel.impl.SynchronousDelegateProducer.process(SynchronousDelegateProducer.java:62)
            at org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61)
            at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:120)
            at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:72)
            at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:416)
            at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)
            at org.apache.camel.processor.Pipeline.process(Pipeline.java:118)
            at org.apache.camel.processor.Pipeline.process(Pipeline.java:80)
            at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)
            at org.apache.camel.component.timer.TimerConsumer.sendTimerExchange(TimerConsumer.java:166)
            at org.apache.camel.component.timer.TimerConsumer$1.run(TimerConsumer.java:74)
            at java.util.TimerThread.mainLoop(Timer.java:512)
            at java.util.TimerThread.run(Timer.java:462)
    

    Camel中的endpoint定义:

    CxfEndpoint endpoint = new CxfEndpoint();
            endpoint.setAddress("http://127.0.0.1:9000/myfunctionalmock");
            endpoint.setEndpointNameString("{http://my.example.com/myFunction}rpcrouter");
            endpoint.setServiceNameString("{http://my.example.com/myFunction}MyFunctionalWebservicesService");
            endpoint.setDataFormat(DataFormat.RAW);
            endpoint.setWrappedStyle(false);
            endpoint.setSynchronous(true);
            endpoint.setCamelContext(camelContext);
            endpoint.setEndpointUriIfNotSpecified(MY_TEMPLATE_ENDPOINT_URL);
            camelContext.addEndpoint(MY_TEMPLATE_ENDPOINT_URL, endpoint);
    

    路线用法:

            from("timer://myTimer?period=10000")
            .log(LoggingLevel.INFO, "START Timer Webservice.")
            .setBody().constant(
                    "<soapenv:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:myns=\"http://my.example.com/myFunction\">\n" +
                            "   <soapenv:Header/>\n" +
                            "   <soapenv:Body>\n" +
                            "      <myns:isAlive soapenv:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\n" +
                            "         <identifier xsi:type=\"xsd:string\">1620000018</identifier>\n" +
                            "      </myns:isAlive>\n" +
                            "   </soapenv:Body>\n" +
                            "</soapenv:Envelope>"
            )
            .to(MyCamelConfiguration.MY_TEMPLATE_ENDPOINT_URL)
    .log(LoggingLevel.INFO, "END Timer Webservice.")
    .log(LoggingLevel.INFO, "Body after ws call = ${body}");
    

    但是http://localhost:9000/myfunctionalmock上的网络服务从未被调用。我在logfile中发现了以下日志消息:

    2015-03-05 10:56:35,522; 12843; [Camel (camel-1) thread #0 - timer://myTimer]; DEBUG;              phase.PhaseInterceptorChain; Invoking handleMessage on interceptor org.apache.cxf.jaxb.attachment.JAXBAttachmentSchemaValidationHack@1d3694a
    2015-03-05 10:56:35,523; 12844; [Camel (camel-1) thread #0 - timer://myTimer]; DEBUG;              phase.PhaseInterceptorChain; Invoking handleMessage on interceptor org.apache.cxf.ws.policy.PolicyVerificationInInterceptor@1a0ff10
    2015-03-05 10:56:35,523; 12844; [Camel (camel-1) thread #0 - timer://myTimer]; DEBUG;   policy.PolicyVerificationInInterceptor; Verified policies for inbound message.
    2015-03-05 10:56:35,523; 12844; [Camel (camel-1) thread #0 - timer://myTimer]; INFO ;               helpers.MarkerIgnoringBase; END Timer Webservice.
    2015-03-05 10:56:35,523; 12844; [Camel (camel-1) thread #0 - timer://myTimer]; INFO ;               helpers.MarkerIgnoringBase; Body after ws call = <HTML>
    <HEAD><TITLE>Redirection</TITLE></HEAD>
    <BODY><H1>Redirect</H1></BODY>
    

    这两种方法都不起作用。是否有可能在Camel中通过CXF调用RPC/编码的Web服务?

    提前谢谢。

    祝好

    马克斯

  • 共有1个答案

    苏涛
    2023-03-14

    正如您所说,Apache CXF不支持旧的RPC样式。您需要使用较旧的WS-library,比如ApacheAxis1。x、 没有Camel组件,但由于它只是java代码,您可以编写一些使用Axis 1的java代码。x、 然后让Camel使用其bean组件/处理器调用java代码

    • http://camel.apache.org/bean

    另一种选择是,由于SOAP是基于HTTP的,所以也可以使用Camel的HTTP组件。但是您需要根据RPC样式构建消息体和消息头,但这也不难做到。

     类似资料:
    • 说明 此文档只适用于 jboot v3.1.0 以上,之前的版本请参考 这里 。 目录 添加依赖 配置 开始使用 restful 暴露 高级功能 添加依赖 Jboot 支持 dubbo 和 motan,假设我们需要使用 dubbo 作为底层的 RPC 框架,需要添加如下依赖: <dependency> <groupId>org.apache.dubbo</groupId> <art

    • 通过CXFendpoint中的模式验证,实现从CXFendpoint到JMS队列的驼峰路由。 已在CXF终结点中启用验证: 骆驼路线: CXF拦截器: 如果我发送有效的SOAP消息,则工作正常。如果我发送无效的SOAP消息,方法会启动,记录故障,仅此而已。对于无效的SOAP消息场景,我是否可以使用方法记录故障并仍然将无效消息路由到JMS队列?这是我添加到endpoint的唯一拦截器。 Apache

    • 我想测试以下骆驼路线。我在网上找到的所有例子都有以文件开头的路由,在我的例子中,我有一个Springbean方法,每隔几分钟就会被调用一次,最后消息被转换并移动到jms以及审计目录。 我对这条路线的写测试毫无头绪。目前我在测试用例中所拥有的是

    • 问题内容: 首先,我知道进行同步调用是“错误的”,并且知道“不可能”。 但是,在非常复杂的情况下(我不知道如何解释),我需要等待服务器的响应,我正在对GWT RPC调用使用GWT-Platform命令实现。 我正在为此寻找某种“黑客”。 提前致谢。 问题答案: 有解决方案,但这并不容易(例如,您无法翻转单个参数以使其起作用)。GWT在后台使用了普通的JS XMLHttpRequest。在GWT中,

    • Introduction 介绍 Socket and HTTP programming use a message-passing paradigm. A client sends a message to a server which usually sends a message back. Both sides are responsible for creating messages in

    • 本文向大家介绍golang两种调用rpc的方法,包括了golang两种调用rpc的方法的使用技巧和注意事项,需要的朋友参考一下 本文实例讲述了golang两种调用rpc的方法。分享给大家供大家参考,具体如下: golang的rpc有两种方法进行调用,一种是rpc例子中给的: 另一种是使用NewServer 这种是当rpc已经注册的时候就要使用了另外一种了。即一个server只能在DefaultRP