java 调用 Web 服务时出现 javax.xml.ws.soap.SOAPFaultException

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11301395/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 04:35:24  来源:igfitidea点击:

javax.xml.ws.soap.SOAPFaultException when calling web service

javacxfwebservice-client

提问by user1084509

I've created a Web Service Client in eclipse using Apache CXF 2.x from the following WSDL:

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

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

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

When doing the web service call I get the following error stacktrace (The server can't process the request ---> Reference to object not established as an object instance):

在执行 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) 

The call I am doing it this way:

我这样做的电话是:

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

The error I get it in the following line:

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

String result = stpSoap.generaTimbre(xmlBytes);

Before I was able to do the web service call, but now I am not able to do it and I get the following error. Any suggestions of how I can solve this problem?

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

回答by Gergely Szilagyi

I guess this will be not much of an answer, but anyways:

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

That service is seriously f**up.

这项服务是认真F * *了。

For example

例如

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

in

<cfdi:GeneraTimbre>

is optional according to the WSDL contract:

根据 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>

(notice the minOccurs="0"!) Yet when you send a message without the optionalpart, you'll get a soapfault:

(注意minOccurs="0"!)但是当你发送一条没有可选部分的消息时,你会得到一个肥皂错误:

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

As I said in the beginning, this won't be much of an answer, just an advice maybe: try to stay away from so poorly written services. (My guess is that they tried to implement ws-sec, but without the ws-policy framework, which can be done, but will give little or no help at all to the service consumer on how to use it properly)

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