0

I'm working on an application where I have to consume a SOAP webservice and convert it to Rest based webservices. I followed the tutorial from Spring team and was capable to generate pojos, but when I try to make the call using the webServiceTemplate I have an error that the host is not recognized which is basically because I'm behind a proxy in our company.

The technology stack I'm using is Spring boot with web module and spring-ws-core, and I would like to know how to set up my proxy data in the webServiceTemplate.

Thanks

Habchi
  • 1,921
  • 2
  • 22
  • 50

2 Answers2

1

Try to setup the template according this answer.

Afterwards you should be able to set it within your class extending WebServiceGatewaySupport using

setWebServiceTemplate(WebServiceTemplate webServiceTemplate)
pma
  • 860
  • 1
  • 9
  • 26
  • Thanks for the answer however I'm not using a virtual machine to set up this properties. Should I provide them as environment variables (I'm working on Windows OS) – Habchi Aug 06 '18 at 11:05
  • Where exactly do you see a relation/restriction to a virtual machine? – pma Aug 06 '18 at 11:16
  • I'm sorry, does the VM arguments mentioned in the response are arguments to use when launching the application ? Java -jar application.jar [properties]?! – Habchi Aug 06 '18 at 11:18
  • Yes, that would be the JVM arguments: java -Dhttp.proxyHost=[yourProxy] -Dhttp.proxyPort=[yourPort] -jar application.jar However be aware, that I linked to the answer below, which sets the proxy programmatically. – pma Aug 06 '18 at 11:24
  • It didn't work with JVM arguments but I found a solution now. I posted my answer in case someone is facing the same problem. – Habchi Aug 14 '18 at 12:54
1

After a lot of research, I came up with a programmatic solution. Once you defined your SOAP client that will extend WebServiceGatewaySupport class, I created a configuration class (annotated with @configuration that will declare a bean of my SOAP client. In this method, I used the following code to setup my proxy information and thus I was able to consume my web service:

@Bean
    public CommerceSoapClient commerceSoapClient(Jaxb2Marshaller marshaller) {
        CommerceSoapClient commerceService = new CommerceSoapClient();

        //Setup proxy
        HttpClientBuilder builder = HttpClientBuilder.create();
        builder.addInterceptorFirst(new HttpComponentsMessageSender.RemoveSoapHeadersInterceptor());
        HttpHost proxy = new HttpHost("127.0.0.1", 8080);
        builder.setProxy(proxy);


        CloseableHttpClient httpClient = builder.build();

        HttpComponentsMessageSender messageSender = new HttpComponentsMessageSender(httpClient);

        WebServiceTemplate webServiceTemplate = new WebServiceTemplate();
        webServiceTemplate.setMessageSender(messageSender);
        webServiceTemplate.setDefaultUri("http://your webservice address path");
        webServiceTemplate.setUnmarshaller(marshaller);
        webServiceTemplate.setMarshaller(marshaller);


        commerceService.setDefaultUri("https://your webservice address path");
        commerceService.setWebServiceTemplate(webServiceTemplate);

        return commerceService;
    }
Habchi
  • 1,921
  • 2
  • 22
  • 50