java - Mule 流尝试调用 Web 服务时出现 CXF 异常

标签 java web-services jax-ws cxf mule

我是 mule ESB 的新手,我正在尝试实现一个简单的应用程序流程:

<mule ...>
    <flow name="extrator_gep_spedFlow1" doc:name="extrator_gep_spedFlow1">
        <file:inbound-endpoint path="/home/brevleq/inicio_extrator" responseTimeout="10000" doc:name="Inicio"/>
        <file:file-to-string-transformer doc:name="File to String"/>
        <echo-component doc:name="Echo"/>
        <cxf:jaxws-client operation="empresaExiste" clientClass="com.hrgi.gepsped.ServicoDeCadastroEAgendamento_Service" port="hrgi" enableMuleSoapHeaders="true" doc:name="empresa esta cadastrada"/>
        <echo-component doc:name="Echo"/>
    </flow>
</mule>

基本上,当用户将文件放入扫描目录中并使用文件内容调用网络服务时,此流程就会开始。

不幸的是,执行流程时出现此错误:

Exception stack is:
1. Unexpected wrapper element {http://endpoints.ws.gepsped.hrgi.com/}empresaExiste found.   Expected {http://endpoints.ws.gepsped.hrgi.com/}empresaExisteResponse. (org.apache.cxf.interceptor.Fault)
org.apache.cxf.interceptor.DocLiteralInInterceptor:106 (null)
2. Unexpected wrapper element {http://endpoints.ws.gepsped.hrgi.com/}empresaExiste found.   Expected {http://endpoints.ws.gepsped.hrgi.com/}empresaExisteResponse. (javax.xml.ws.soap.SOAPFaultException)
org.apache.cxf.jaxws.JaxWsClientProxy:156 (http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/xml/ws/soap/SOAPFaultException.html)
3. Unexpected wrapper element {http://endpoints.ws.gepsped.hrgi.com/}empresaExiste found.   Expected {http://endpoints.ws.gepsped.hrgi.com/}empresaExisteResponse.. Failed to route event via endpoint: org.mule.module.cxf.CxfOutboundMessageProcessor. Message payload is of type: PushbackInputStream (org.mule.api.transport.DispatchException)
org.mule.module.cxf.CxfOutboundMessageProcessor:148 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/transport/DispatchException.html)
--------------------------------------------------------------------------------
Root Exception stack trace:
org.apache.cxf.interceptor.Fault: Unexpected wrapper element {http://endpoints.ws.gepsped.hrgi.com/}empresaExiste found.   Expected {http://endpoints.ws.gepsped.hrgi.com/}empresaExisteResponse.
at org.apache.cxf.interceptor.DocLiteralInInterceptor.handleMessage(DocLiteralInInterceptor.java:106)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:263)
at org.apache.cxf.endpoint.ClientImpl.onMessage(ClientImpl.java:799)
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)

这是 wsdl2java 生成的类:

@WebServiceClient(name = "ServicoDeCadastroEAgendamento", 
              wsdlLocation = "http://localhost:8080/gep-sped/servicos/ServicoDeCadastroEAgendamento?wsdl",
              targetNamespace = "http://endpoints.ws.gepsped.hrgi.com/") 
public class ServicoDeCadastroEAgendamento extends Service {
public final static URL WSDL_LOCATION;

public final static QName SERVICE = new QName("http://endpoints.ws.gepsped.hrgi.com/", "ServicoDeCadastroEAgendamento");
public final static QName Hrgi = new QName("http://endpoints.ws.gepsped.hrgi.com/", "hrgi");
static {
    URL url = null;
    try {
        url = new URL("http://localhost:8080/gep-sped/servicos/ServicoDeCadastroEAgendamento?wsdl");
    } catch (MalformedURLException e) {
        java.util.logging.Logger.getLogger(ServicoDeCadastroEAgendamento.class.getName())
            .log(java.util.logging.Level.INFO, 
                 "Can not initialize the default wsdl from {0}", "http://localhost:8080/gep-sped/servicos/ServicoDeCadastroEAgendamento?wsdl");
    }
    WSDL_LOCATION = url;
}

public ServicoDeCadastroEAgendamento(URL wsdlLocation) {
    super(wsdlLocation, SERVICE);
}

public ServicoDeCadastroEAgendamento(URL wsdlLocation, QName serviceName) {
    super(wsdlLocation, serviceName);
}

public ServicoDeCadastroEAgendamento() {
    super(WSDL_LOCATION, SERVICE);
}

public ServicoDeCadastroEAgendamento(WebServiceFeature ... features) {
    super(WSDL_LOCATION, SERVICE, features);
}

public ServicoDeCadastroEAgendamento(URL wsdlLocation, WebServiceFeature ... features) {
    super(wsdlLocation, SERVICE, features);
}

public ServicoDeCadastroEAgendamento(URL wsdlLocation, QName serviceName, WebServiceFeature ... features) {
    super(wsdlLocation, serviceName, features);
}

@WebEndpoint(name = "hrgi")
public ServicoDeCadastroEAgendamentoEndPoint getHrgi() {
    return super.getPort(Hrgi, ServicoDeCadastroEAgendamentoEndPoint.class);
}

@WebEndpoint(name = "hrgi")
public ServicoDeCadastroEAgendamentoEndPoint getHrgi(WebServiceFeature... features) {
    return super.getPort(Hrgi, ServicoDeCadastroEAgendamentoEndPoint.class, features);
}
}

这是我的服务生成的 wsdl:

<definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://endpoints.ws.gepsped.hrgi.com/"
         xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/"
         targetNamespace="http://endpoints.ws.gepsped.hrgi.com/" name="ServicoDeCadastroEAgendamento">
<types>
    <xsd:schema>
        <xsd:import namespace="http://endpoints.ws.gepsped.hrgi.com/"
                    schemaLocation="http://localhost:8080/gep-sped/servicos/ServicoDeCadastroEAgendamento?xsd=1"/>
    </xsd:schema>
</types>
<message name="empresaExiste">
    <part name="parameters" element="tns:empresaExiste"/>
</message>
<message name="empresaExisteResponse">
    <part name="parameters" element="tns:empresaExisteResponse"/>
</message>
<message name="cadastrarEmpresa">
    <part name="parameters" element="tns:cadastrarEmpresa"/>
</message>
<message name="cadastrarEmpresaResponse">
    <part name="parameters" element="tns:cadastrarEmpresaResponse"/>
</message>
<message name="recuperarHorarioAgendamento">
    <part name="parameters" element="tns:recuperarHorarioAgendamento"/>
</message>
<message name="recuperarHorarioAgendamentoResponse">
    <part name="parameters" element="tns:recuperarHorarioAgendamentoResponse"/>
</message>
<portType name="ServicoDeCadastroEAgendamentoEndPoint">
    <operation name="empresaExiste">
        <input message="tns:empresaExiste"/>
        <output message="tns:empresaExisteResponse"/>
    </operation>
    <operation name="cadastrarEmpresa">
        <input message="tns:cadastrarEmpresa"/>
        <output message="tns:cadastrarEmpresaResponse"/>
    </operation>
    <operation name="recuperarHorarioAgendamento">
        <input message="tns:recuperarHorarioAgendamento"/>
        <output message="tns:recuperarHorarioAgendamentoResponse"/>
    </operation>
</portType>
<binding name="hrgiBinding" type="tns:ServicoDeCadastroEAgendamentoEndPoint">
    <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
    <operation name="empresaExiste">
        <soap:operation soapAction=""/>
        <input>
            <soap:body use="literal"/>
        </input>
        <output>
            <soap:body use="literal"/>
        </output>
    </operation>
    <operation name="cadastrarEmpresa">
        <soap:operation soapAction=""/>
        <input>
            <soap:body use="literal"/>
        </input>
        <output>
            <soap:body use="literal"/>
        </output>
    </operation>
    <operation name="recuperarHorarioAgendamento">
        <soap:operation soapAction=""/>
        <input>
            <soap:body use="literal"/>
        </input>
        <output>
            <soap:body use="literal"/>
        </output>
    </operation>
</binding>
<service name="ServicoDeCadastroEAgendamento">
    <port name="hrgi" binding="tns:hrgiBinding">
        <soap:address location="http://localhost:8080/gep-sped/servicos/ServicoDeCadastroEAgendamento"/>
    </port>
</service>
</definitions>

有人可以解释一下我做错了什么吗?

最佳答案

我的错误,我不知道 cxf 组件之后需要一个端点:

<mule ...>
    <flow name="extrator_gep_spedFlow1" doc:name="extrator_gep_spedFlow1">
        <file:inbound-endpoint path="/home/brevleq/inicio_extrator" responseTimeout="10000" doc:name="Inicio"/>
        <file:file-to-string-transformer doc:name="File to String"/>
        <echo-component doc:name="Echo"/>
        <cxf:jaxws-client operation="empresaExiste" clientClass="com.hrgi.gepsped.ws.endpoints.ServicoDeCadastroEAgendamento" port="hrgi" enableMuleSoapHeaders="true" doc:name="empresa esta cadastrada">
            <cxf:jaxb-databinding/>
        </cxf:jaxws-client>
        <outbound-endpoint address="http://localhost:8080/gep-sped/servicos/ServicoDeCadastroEAgendamento" doc:name="Generic" exchange-pattern="request-response"/>
        <echo-component doc:name="Echo"/>
    </flow>
</mule>

关于java - Mule 流尝试调用 Web 服务时出现 CXF 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13404172/

相关文章:

java - 我的 java 程序给我一个 IndexOutOfBoundsException

java - 在 Java Web 服务器的空闲时间运行垃圾收集

jakarta-ee - 无法排除方法被 JAX-WS 作为 Web 服务操作公开

iphone - 使用 NSURLConnection 发送 POST 请求

java - 处理延迟加载的 EJB JPA 实体的 JAX-WS 代理对象的最佳方法是什么?

java - jaxws 网络服务。更改节点结构

java - 最快的同步技术

java - 检查按钮的 ID

java - 如何转换 Groovy -> Kotlin DSL (Gradle) 的 "sourceSet"?

web-services - 如何使用 Rhino Mocks 模拟 WCF Web 服务