0

I'm trying to consume a service that does not need a certificate. It only receives username and password as the property of the request. I'm using the maven-jaxb2-plugin plugin to generate the code. I tried copying using the following commands:

mvn generate-sources -Dmaven.wagon.http.ssl.insecure=true -Dmaven.wagon.http.ssl.allowall=true -Dmaven.wagon.http.ssl.ignore.validity.dates=true

and

mvn generate-sources

But I have received the following error:

org.springframework.ws.client.WebServiceIOException: I/O error: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target; nested exception is javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

This is my setup method:

   @Bean
    Jaxb2Marshaller jaxb2Marshaller() {
        Jaxb2Marshaller jaxb2Marshaller = new Jaxb2Marshaller();
jaxb2Marshaller.setPackagesToScan("ce.gov.s2gpr.compras.licita.business.model.service.bean");
        return jaxb2Marshaller;
    }


@Bean
public WebServiceTemplate webServiceTemplate() {
    WebServiceTemplate webServiceTemplate = new WebServiceTemplate();
    webServiceTemplate.setMarshaller(jaxb2Marshaller());
    webServiceTemplate.setUnmarshaller(jaxb2Marshaller());
    webServiceTemplate.setDefaultUri(defaultUri);
    webServiceTemplate.setMessageSender(webServiceMessageSender());

    return webServiceTemplate;
}

@Bean
public WebServiceMessageSender webServiceMessageSender() {
    HttpComponentsMessageSender httpComponentsMessageSender = new HttpComponentsMessageSender();
    // timeout for creating a connection
    httpComponentsMessageSender.setConnectionTimeout(timeout);
    // when you have a connection, timeout the read blocks for
    httpComponentsMessageSender.setReadTimeout(timeout);
    httpComponentsMessageSender.setCredentials(new UsernamePasswordCredentials(userName, userPassword));
    return httpComponentsMessageSender;
}

This is my method that consumes the service:

@SuppressWarnings("unchecked")
    public AtualizacaoItensGruposResponse testeSoap(PgeTO dto) {

        ObjectFactory factory = new ObjectFactory();

        AtualizacaoItensGrupos itens = factory.createAtualizacaoItensGrupos();

        itens.setArg0(dto);
        JAXBElement<AtualizacaoItensGrupos> request =  factory.createAtualizacaoItensGrupos(itens);

        try {
//            webServiceTemplate.marshalSendAndReceive(request);
                    webServiceTemplate.marshalSendAndReceive(itens);
            return null;
        } catch (Exception e) {
            log.error(e.getMessage());

        }

    }
lexicore
  • 42,748
  • 17
  • 132
  • 221
  • And I tred add WebServiceMessageCallback, taking the connection and adding the properties: username and password. HttpUrlConnection connection = (HttpUrlConnection) context.getConnection(); connection.getConnection().addRequestProperty("Username", "seplag"); connection.getConnection().addRequestProperty("Password", "83s#@asf"); – Junior Bezerra Apr 13 '18 at 19:20
  • Do you receive this error during code generation? Or in the runtime? – lexicore Apr 15 '18 at 08:55
  • Runtime, line: webServiceTemplate.marshalSendAndReceive(itens); – Junior Bezerra Apr 15 '18 at 12:06

0 Answers0