Basic http auth of soap service…

484 views
Skip to first unread message

Viktor Hedefalk

unread,
Jan 13, 2012, 5:54:23 AM1/13/12
to sca...@googlegroups.com
I'm consuming a soap service that uses basic http auth. Is this the
right way to add credentials:


val service = (new ServiceSoap11Bindings with scalaxb.Soap11Clients
with scalaxb.DispatchHttpClients {
override val httpClient = new DispatchHttpClient {
override def request(in: String, address: java.net.URI, headers:
Map[String, String]): String = {
val http = new Http
http x (url(address.toString) << (in) <:< headers as
("username", "password") as_str)
}
}
...
}


Thanks,
Viktor

eugene yokota

unread,
Jan 13, 2012, 8:39:19 AM1/13/12
to sca...@googlegroups.com
That's an intended use case for the cake pattern.

-eugene

David Portabella

unread,
Mar 19, 2013, 2:15:29 PM3/19/13
to sca...@googlegroups.com
what is the version of net.databinder.dispatch that we should use?

I am using as follows in order to use soap authentication:
    val remote = new MyServicePortBindings with Soap11Clients with DispatchHttpClients {
      override def baseAddress = new java.net.URI(myEndpointURI)
      import dispatch._

      override val httpClient = new DispatchHttpClient {
        override def request(in: String, address: java.net.URI, headers: Map[String, String]): String = {
          println("URL: " + address);
          println("REQUEST: " + in);
          val req = url(address.toString) << in <:< headers as(myLogin, myPassword)
          val s = Http(req OK as.String)
          val out = s()
          println("RESPONSE: " + out);
          out
        }
      }
    };

and this works with:
      <dependency>
        <groupId>net.databinder.dispatch</groupId>
        <artifactId>core_2.10</artifactId>
        <version>0.9.1</version>
      </dependency>

is this the right way? 
(but i have some other strange problems)


however, this example fails to compile with the last correct version of net.databinder.dispatch.
(this is the last correct version of net.databinder.dispatch, right?)
    <dependency>
      <groupId>net.databinder.dispatch</groupId>
      <artifactId>dispatch-core_2.9.2</artifactId>
      <version>0.9.5</version>
    </dependency>

do you know how I should modify the example to make it work?

I also didn't manage to compile the example of Viktor (It does not find the 'x' method for Http).

or, can you please provide an example of calling a soap service with authentication?


Regards,
David

eugene yokota

unread,
Mar 19, 2013, 2:32:48 PM3/19/13
to sca...@googlegroups.com
The release note for 1.0.0 says "The default http client for SOAP binding is upgraded to Dispatch 0.9.5,"
so I think that's what should be used. (http://scalaxb.org/scalaxb-100)

Since Viktor's override was based on older version with Dispatch Classic, you might have to tweak it a little.

-eugene

--
You received this message because you are subscribed to the Google Groups "scalaxb" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scalaxb+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

David Portabella

unread,
Mar 19, 2013, 2:53:50 PM3/19/13
to sca...@googlegroups.com
If I use the standard dispatch used by scalaxb (so, without authentication):
 val remote = new MyServicePortBindings with Soap11Clients with DispatchHttpClients {};

with 
    <dependency>
      <groupId>net.databinder.dispatch</groupId>
      <artifactId>dispatch-core_2.9.2</artifactId>
      <version>0.9.5</version>
    </dependency>

I get the following runtime error:
Exception in thread "main" java.lang.NoSuchMethodError: scala.util.control.Exception$Catch.either(Lscala/Function0;)Lscala/Either;
at scalaxb.DispatchHttpClients$DispatchHttpClient$class.request(httpclients_dispatch.scala:12)
package scalaxb


this is the source generated by scalaxb-maven-plugin 1.0.1:

trait DispatchHttpClients extends HttpClients {
  val httpClient = new DispatchHttpClient {}

  trait DispatchHttpClient extends HttpClient {
    import dispatch._

    def request(in: String, address: java.net.URI, headers: Map[String, String]): String = {
      val req = url(address.toString) << in <:< headers
      val s = Http(req OK as.String)
      s()    // <<< httpclients_dispatch.scala:12), error in the stack trace
    }
  }
}

---
any idea on this?

eugene yokota

unread,
Mar 19, 2013, 3:09:39 PM3/19/13
to sca...@googlegroups.com

On Tue, Mar 19, 2013 at 2:53 PM, David Portabella <david.po...@gmail.com> wrote:
I get the following runtime error:
Exception in thread "main" java.lang.NoSuchMethodError: scala.util.control.Exception$Catch.either(Lscala/Function0;)Lscala/Either;
at scalaxb.DispatchHttpClients$DispatchHttpClient$class.request(httpclients_dispatch.scala:12)
package scalaxb


You're hitting NoSuchMethodError for standard lib stuff. I suspect there's Scala version mixup that's happening somewhere.
Are you using 2.9.2 for everything?

-eugene
 

David Portabella

unread,
Mar 19, 2013, 3:16:14 PM3/19/13
to sca...@googlegroups.com
scala 2.10.0

David Portabella

unread,
Mar 19, 2013, 3:50:13 PM3/19/13
to sca...@googlegroups.com
ieppp, i see your point,

it works correctly with:
    <dependency>
      <groupId>net.databinder.dispatch</groupId>
      <artifactId>dispatch-core_2.10</artifactId>
      <version>0.9.5</version>
    </dependency>

thanks,
David

Viktor Hedefalk

unread,
May 21, 2013, 5:09:15 AM5/21/13
to sca...@googlegroups.com
I just upgraded to dispatch 0.9.5 so the tweak became this:

/** Override http binding to use basic http auth creds */
override lazy val httpClient = new DispatchHttpClient {
override def request(in: String, address: java.net.URI, headers:
Map[String, String]): String = {
import dispatch._
val http = new Http
val req = (Config.CrmSettings.user, Config.CrmSettings.password) match {
case (Some(user), Some(pwd)) => url(address.toString) <<
(in) <:< headers as (user, pwd)
case _ => url(address.toString) << (in) <:< headers
}
val s = Http(req > as.String)
s()
}
}

Thanks,
Viktor





On Tue, Mar 19, 2013 at 8:50 PM, David Portabella

David Portabella

unread,
May 22, 2013, 4:30:26 AM5/22/13
to sca...@googlegroups.com
cool, thanks for sharing.

Leonor Boga

unread,
Oct 24, 2016, 8:47:54 AM10/24/16
to scalaxb
Hi all, 

The code shared by Viktor Hedefalk is quite old.

How would this code look like for dispatch version 0.11.3?

Thanks!

Leonor
Reply all
Reply to author
Forward
0 new messages