0

我使用来自以下 WSDL 的 Apache CXF 2.x 在 eclipse 中创建了一个 Web 服务客户端:

https://test.timbrado.com.mx/cfdi/wstimbrado.asmx?WSDL

在进行 Web 服务调用时,我收到以下错误堆栈跟踪(服务器无法处理请求 ---> 对未建立为对象实例的对象的引用):

javax.xml.ws.soap.SOAPFaultException: El servidor no puede procesar la solicitud. ---> Referencia a objeto no establecida como instancia de un objeto.
 [java]     at com.sun.xml.internal.ws.fault.SOAP11Fault.getProtocolException(Unknown Source)
 [java]     at com.sun.xml.internal.ws.fault.SOAPFaultBuilder.createException(Unknown Source)
 [java]     at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(Unknown Source)
 [java]     at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(Unknown Source)
 [java]     at com.sun.xml.internal.ws.client.sei.SEIStub.invoke(Unknown Source)
 [java]     at $Proxy34.generaTimbre(Unknown Source)
 [java]     at com.vital.fevital.funciones.FacturaElectronica.timbrarWebService(FacturaElectronica.java:1258)
 [java]     at facturaVital.factura.servlet.FacturaVenta.generaFactura(FacturaVenta.java:1128)
 [java]     at facturaVital.factura.servlet.FacturaVenta.doPost(FacturaVenta.java:127)
 [java]     at facturaVital.factura.servlet.FacturaVenta.doGet(FacturaVenta.java:86)
 [java]     at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
 [java]     at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
 [java]     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:306)
 [java]     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
 [java]     at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
 [java]     at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161)
 [java]     at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
 [java]     at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
 [java]     at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:541)
 [java]     at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
 [java]     at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:383)
 [java]     at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:243)
 [java]     at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
 [java]     at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:288)
 [java]     at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
 [java]     at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
 [java]     at java.lang.Thread.run(Unknown Source) 

我这样做的电话是这样的:

ObjectFactory of = new ObjectFactory();
    AuthenticationHeader ah = of.createAuthenticationHeader();
    ah.setUserName(cfdi.getUsuarioPAC());
    ah.setPassword(cfdi.getPasswordPAC());
    JAXBElement<AuthenticationHeader> jah = of.createAuthenticationHeader(ah);

    ServicioTimbradoPruebas stp = new ServicioTimbradoPruebas();
    ServicioTimbradoPruebasSoap stpSoap = stp.getServicioTimbradoPruebasSoap();

    try{
        WSBindingProvider bp = (WSBindingProvider)stpSoap;
        Header hdr = Headers.create((JAXBRIContext) JAXBContext.newInstance(AuthenticationHeader.class),jah);
        bp.setOutboundHeaders(hdr);
    }catch(Exception ex){
        ex.printStackTrace();
        error = "Error en webservice ";
    }
    byte [] xmlBytes = cfdi.getXml().getBytes("UTF-8");
    String result = stpSoap.generaTimbre(xmlBytes);

我在以下行中得到它的错误:

String result = stpSoap.generaTimbre(xmlBytes);

在我能够进行 Web 服务调用之前,但现在我无法做到这一点,并且出现以下错误。关于如何解决这个问题的任何建议?

4

1 回答 1

3

我想这不会是一个很大的答案,但无论如何:

该服务严重f * * up。

例如

<cfdi:xmlBytes>cdi:246460475753</cfdi:xmlBytes>

<cfdi:GeneraTimbre>

根据 WSDL 合同是可选的:

     <s:element name="GeneraTimbre">
        <s:complexType>
           <s:sequence>
              <s:element minOccurs="0" maxOccurs="1" name="xmlBytes" type="s:base64Binary"/>
           </s:sequence>
        </s:complexType>
     </s:element>

(注意minOccurs="0"!)然而,当你发送没有可选部分的消息时,你会得到一个 soapfault:

 <soap:Body>
      <soap:Fault>
         <faultcode>soap:MustUnderstand</faultcode>
         <faultstring>No se entendió el encabezado SOAP Security.</faultstring>
      </soap:Fault>
   </soap:Body>

正如我在开始时所说,这不会是一个太多的答案,可能只是一个建议:尽量远离写得这么糟糕的服务。(我的猜测是他们试图实现 ws-sec,但没有 ws-policy 框架,这是可以做到的,但对于服务消费者如何正确使用它几乎没有帮助或根本没有帮助)

于 2012-07-02T21:54:02.993 回答