vendredi 1 mars 2019

Problem with soap service connection in SpringBoot

When trying to consume a soap service I get the following error:

Could not create message from InputStream: Invalid Content-Type:application/wsdl+xml. Is this an error message instead of a SOAP response?; nested exception is com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: Invalid Content-Type:application/wsdl+xml. Is this an error message instead of a SOAP response?

The Code:

String url = "https://www.cpo.com.br/proxy/wsdl/proxyService_p.wsdl";


    SaajSoapMessageFactory messageFactory = new SaajSoapMessageFactory(
            MessageFactory.newInstance());
    messageFactory.afterPropertiesSet();

    WebServiceTemplate webServiceTemplate = new WebServiceTemplate(messageFactory);
    Jaxb2Marshaller marshaller = new Jaxb2Marshaller();

    marshaller.setContextPath("br.com.dados_cadastrais.local.entity");
    setMarshaller(marshaller);
    setUnmarshaller(marshaller);
    marshaller.afterPropertiesSet();

    webServiceTemplate.setMarshaller(marshaller);
    webServiceTemplate.afterPropertiesSet();



    CpfRequest cpfRequest = new CpfRequest();
    cpfRequest.setPNumCPF("*");
    cpfRequest.setPNomeOrgao("*");
    cpfRequest.setPLoginUsuario("*");
    cpfRequest.setPNomeAplicacao("*");

    JAXBElement<CpfResponse> response = (JAXBElement<CpfResponse>) webServiceTemplate.marshalSendAndReceive(url, cpfRequest, new SoapActionCallback("http://webservice.cjf.gov.br/wsConsultaCPF"));

    return response.getValue();

I've tried other solutions, like changing WSDL URLs but I was not successful. The service can only be accessed by a specific IP, so you will not be able to access its content. I guess the error is in my code.




Aucun commentaire:

Enregistrer un commentaire