Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
406 views
in Technique[技术] by (71.8m points)

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

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This is covered by the JAX-WS Specification. Basically, set the username/password as properties on the request context:

((BindingProvider)proxy).getRequestContext().put(
    BindingProvider.USERNAME_PROPERTY, "joe");
((BindingProvider)proxy).getRequestContext().put(
    BindingProvider.PASSWORD_PROPERTY, "pswd");

The runtime puts them into the HTTP header.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...