How do I consume a web service protected with HTTP basic authentication using the CXF framework?

后端 未结 3 1996
渐次进展
渐次进展 2020-12-17 14:48

I tried to get it to work using the CXF User Guide, but I\'ve had no luck.

I\'m trying to call the web service using java code.

3条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-17 14:49

    You can provide your own Authenticator. That way it will work if the WDSL itself is protected by basic HTTP authentication.

    @WebServiceRef(wsdlLocation = "https://laka/sito?wsdl")
    static XxxService service;
    
    public static void main(String[] args) {
    
        Authenticator.setDefault(new Authenticator() {
            @Override
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication("user", "password".toCharArray());
            }
        });
    
        service = new XxxService();
        Xxx port = service.getXxxPort();
    
        // invoke webservice and print response
        XxxResponse resp = port.foo();
        System.out.println(resp.toString());
    
    }
    

提交回复
热议问题