Invoking a http basic authenticated jax ws client from Play Framework 2.2.1

678 views Asked by At

Currently I am developing a project where I have a Play Framework and I need some external services to work with me.

Unfortunately these services are ALL SOAP web services and I need to call them somehow. So for the task at hand, I already have produced SoapExecutionContext and used the scala.concurrent.future blocks appropriately to provide some asynchronous for the system.

But I am stuck at the authorization part. The development web service that I try to execute relies on basic HTTP authentication. So after searching the web I come up with the following solution:

def userLogin(userLogin: UserLogin): LoginOutput = {
    val service = setCredentials( new ProjectWebService().getProjectWebServiceSoap)

    service.userLogin(userLogin.getUserName, userLogin.getPassword, userLogin.getUserIP)
  }

  def setCredentials(service: ProjectWebServiceSoap):ProjectWebServiceSoap = {
    val requestContext = service.asInstanceOf[BindingProvider].getRequestContext

    requestContext.put(BindingProvider.USERNAME_PROPERTY, Config.getxxxUsername())
    requestContext.put(BindingProvider.PASSWORD_PROPERTY, Config.getxxxPassword())

    service
  }

The client classes are generated using Jax-WS. But this solution does not work, I get the error: Caused by: com.sun.xml.internal.ws.client.ClientTransportException: The server sent HTTP status code 401: Unauthorized

I could not figure out the reason. Does anyone know why this Jax-WS basic http authentication with Play Framework does not work? What's the missing point here?

Thanks in advance

0

There are 0 answers