JAXWS CLIENT ALWAYS SEND HTTP NOT HTTPS

454 Views Asked by At

Hi I use jaxws to generate wsdl in my java project.I use java 11 and jaxws-maven-plugin to import mywsdl Myproblem in my wsdl there is a http://myservice block.And I want to use https://myservice as url. I generate and import wsdl.And this always try to reach http address not https.How can I force my webclient to consume http address.

/**
 * This class was generated by the JAX-WS RI.
 * JAX-WS RI 2.3.2
 * Generated source version: 2.2
 * 
 */
@WebServiceClient(name =

  MyResponse response=reply.getMyService().MyRequest(request);


   <groupId>org.codehaus.mojo</groupId>
                    <artifactId>jaxws-maven-plugin</artifactId>
                    <version>2.6</version>
2

There are 2 best solutions below

0
Bilgehan On

BindingProvider is the solution.

  QName qname2 = new QName("http://myschema", "MYserviceImpl");
                Service service = MYserviceImpl.create(new URL("https://mysiteRequest"), qname2);
                MYservice reply=   service.getPort(MYservice.class);
                BindingProvider bindingProvider = (BindingProvider)reply;
                bindingProvider.getRequestContext().put(
                        BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
                        "https://mysite");

                MyResponse response=  reply.myRequest(request2);
0
Daniil On

Have you tried the good old security constraint in web.xml?

   <security-constraint>
        <display-name>SecurityConstraint</display-name>
        <web-resource-collection>
            <web-resource-name>Secure Area</web-resource-name>
            <url-pattern>/your-webservice-url</url-pattern>
        </web-resource-collection>
        <user-data-constraint>
            <transport-guarantee>CONFIDENTIAL</transport-guarantee>
        </user-data-constraint>
    </security-constraint>