1

In my current project, I have to implement a client to call a SOAP service. I chose to use ScalaXB in order to generate the client and its model from WSDL files. I managed to compile the project and generate the model but I am stuck in making HTTP calls.

This is my DispatchHttpClientsAsync trait and the question is how I can actually make an Http call?

trait DispatchHttpClientsAsync extends HttpClientsAsync {
  lazy val httpClient = new DispatchHttpClient {}
  // https://github.com/AsyncHttpClient/async-http-client/blob/1.9.x/src/main/java/com/ning/http/client/AsyncHttpClientConfigDefaults.java
  def requestTimeout: Duration = 60.seconds
  def connectionTimeout: Duration = 5.seconds

  trait DispatchHttpClient extends HttpClient {
    import dispatch._

    // Keep it lazy. See https://github.com/eed3si9n/scalaxb/pull/279
    lazy val http = Http.configure(_.
      setRequestTimeout(requestTimeout.toMillis.toInt).
      setConnectTimeout(connectionTimeout.toMillis.toInt))

    def request(in: String, address: java.net.URI, headers: Map[String, String])(implicit ec: ExecutionContext): Future[String] = {
      val req = url(address.toString).setBodyEncoding("UTF-8") <:< headers << in
      http(req > as.String)
    }
  }
}
pik4
  • 1,283
  • 3
  • 21
  • 56

1 Answers1

0

DispatchHttpClientsAsync is just a trait under the hood. The actual client implementation you can call is generated elsewhere. I don't know the name of your SOAP service and its operations, but look at the WSDL example http://scalaxb.org/wsdl-support:

This should generate the following 9 files:

  • scalaxb/httpclients_async.scala
  • scalaxb/httpclients_dispatch_async.scala
  • scalaxb/scalaxb.scala
  • scalaxb/soap12_async.scala
  • soapenvelope12/soapenvelope12.scala
  • soapenvelope12/soapenvelope12_xmlprotocol.scala
  • stockquote/stockquote.scala
  • stockquote/stockquote_type1.scala
  • stockquote/xmlprotocol.scala

Have a look at stockquote/ folder, there should be a trait and a method for your SOAP service. In the example you should extend the trait StockQuoteSoap12Binding - there is an implementation of the required method.

mirelon
  • 4,896
  • 6
  • 40
  • 70