Tuesday, May 15, 2012

Web service client with basic authentication. Via jaxws-maven-plugin

If you need to generate a web service client from WSDL which requires HTTP basic authentication with help of maven - taking advantage of jaxws-maven-plugin might be a really good idea.


In order to use jaxws-maven-plugin in your project just add the following dependencies into pom file:

XML>
  
    com.sun.xml.ws
    jaxws-tools
    2.1.4
  
  
    org.jvnet
    mimepull
    1.3
  


Then you have to configure jaxws-maven-pluginin:


 
    
        org.codehaus.mojo
        jaxws-maven-plugin
        1.12
        
          
            
              wsimport
            
          
        
        
           
             -Xauthfile
             ${basedir}/src/main/resources/authFile
            

            
              https://host.com?wsdl
            

            true            
        
    
 


Then just create authFile under ${basedir}/src/main/resources which should contain the following line:

https://username:password@host.com?wsdl


Last step - build your project:

mvn clean install


Find generated classes within /target/jaxws


Useful links:


http://mojo.codehaus.org/jaxws-maven-plugin/wsimport-mojo.html