Thursday, March 25, 2010

Basic authentication - CXF Tips and Tricks Part 1

I'm starting a new blog post series with Apache CXF tips and tricks. In this first post I'll show you how to do communicate with a Web Service together with HTTP Basic authentication.

Below is an example of HTTP Basic authentication with username 'johnsmith' and password 'sesame99'.


URL wsdl = getClass().getResource("myservice.wsdl.xml");
MyService service = new MyService(wsdl).getMyServicePort();
BindingProvider bp = (BindingProvider)service;
bp.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "johnsmith");
bp.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "sesame99");

3 comments:

  1. Hi Henning,


    Would you provide a very simple cxf HTTP basic authentication webservice?


    Thanks

    ReplyDelete
  2. Hi! Take a look at this article http://www.avajava.com/tutorials/lessons/how-do-i-use-basic-authentication-with-tomcat.html

    ReplyDelete
  3. How you get service from port getter?
    MyService service = new MyService(wsdl).getMyServicePort();

    ReplyDelete