jax-ws redirect http / https

1.4k views Asked by At

I am having problem with jax-ws making it work if the server return 301 on http to https. I got an exception, and after debugging it with charles it seems that the redirect doesn't work. I also noticed that there is some trick for http to https[*], but i am not sure if it still apply to java8

That's the pseudo-code that i would like to use with a dirty fix that i found online

    TestImplService service = new TestImplService();
    Test test = service.getTestImplPort();
    Map<String, Object> tmp = ((BindingProvider) test).getRequestContext();

    /*dirty fix*/
    tmp.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, tmp.get(BindingProvider.ENDPOINT_ADDRESS_PROPERTY).toString().replace("http:", "https:")
    );


    test.dosomething();

Replacing http with https work, but i am not 100% sure that's the correct way.

Let's suppose that the server decide to stop to support https, disable the 301 for http, then my fix won't work anymore.

Can i force the follow redirect in another way?

[*] https://docs.oracle.com/javase/6/docs/technotes/guides/deployment/deployment-guide/upgrade-guide/article-17.html

1

There are 1 answers

0
oner.unal On

BindingProvider class BindingProvider.ENDPOINT_ADDRESS_PROPERTY property is usable for change endpoint URL; Sometimes HTTPS connection ended with network switches/routers. Therefor application server cannot realize the path of https.

service = new ....(url, SERVICE_NAME);
port = service.get...BasicHttpEndpoint();
BindingProvider provider = ((BindingProvider) port);
Map<String, Object> map = provider.getRequestContext();
String current = map.get(BindingProvider.ENDPOINT_ADDRESS_PROPERTY).toString();
map.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, current.replace("http:", "https:"));