gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 00:19:29 25 4
gpt4 key购买 nike

我使用来自以下 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 服务调用,但现在我无法执行此操作并且收到以下错误。关于如何解决这个问题有什么建议吗?

最佳答案

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

这项服务实在是太糟糕了。*

例如

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

<cfdi:GeneraTimbre>

根据 WSDL 契约(Contract)是可选的:

     <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"!)然而,当您发送没有可选部分的消息时,您将收到肥皂错误:

 <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 框架,这可以做到,但对服务使用者来说几乎没有帮助或根本没有帮助如何正确使用它)

关于调用 Web 服务时出现 javax.xml.ws.soap.SOAPFaultException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11301395/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com