0

I've created a Web Service Client in eclipse using Apache CXF 2.x from the following 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):

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?

user1084509
  • 1,832
  • 10
  • 33
  • 48

1 Answers1

3

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

That service is seriously f** up.

For example

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

in

<cfdi:GeneraTimbre>

is optional according to the 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>

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

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

Gergely Szilagyi
  • 3,813
  • 1
  • 14
  • 12
  • I know the service is not properly built. But I need to consume this web service as it is required for doing electronic invoices in Mexico. Any help would be appreciated – user1084509 Jul 03 '12 at 14:24
  • 1
    Since they're misusing the whole 'contract' part of the webservice, I think you only have two options: spend a lot of time with trial&error, or contact them to get a working sample... – Gergely Szilagyi Jul 04 '12 at 12:47