eed3si9n / scalaxb

scalaxb is an XML data binding tool for Scala.
http://scalaxb.org/
MIT License
337 stars 154 forks source link

How do you stub the service for generated soap client? #312

Open mirelon opened 9 years ago

mirelon commented 9 years ago

I want to generate a soap client and test it, using service stub. I see there is an option to specify dispatch version, but still there is InternalDefaults.client used, making it unstubbable: http://stackoverflow.com/questions/28966315/stubbing-soap-requests-in-scala

Specifying --blocking parameter uses the same AsyncHttpClient ignoring proxy settings, so it is still unstubbable.

mirelon commented 9 years ago

You cannot use InternalDefaults of Dispatch. Instead use e.g.

lazy val asyncHttpClient: AsyncHttpClient = new AsyncHttpClient(
  new NettyAsyncHttpProvider(new AsyncHttpClientConfig.Builder().setUseProxyProperties(true).build()));

lazy val http = new Http(asyncHttpClient)

Should I make a pull request?

mirelon commented 9 years ago

I don't know which files should be modified in here: https://github.com/eed3si9n/scalaxb/tree/master/cli/src/main/resources

There are various httpclients_dispatch0100_async.scala.template. I think any template should provide a way to configure proxy through settings. I will add it to all of them.

eed3si9n commented 9 years ago

I was going to add similar change to templates, but for timeout. See #304.

    lazy val http = Http.configure(_.
      setRequestTimeoutInMs(requestTimeout.toMillis.toInt).
      setConnectionTimeoutInMs(connectionTimeout.toMillis.toInt))

Maybe you could do something like that?

mirelon commented 9 years ago

That would be great, but I was not able to make it work. Tried:

lazy val http = Http.configure(_.setUseProxyProperties(true))

But the proxy settings are ignored. They are not ignored when I use the following: (I am a bit lost now)

lazy val http = new Http(new AsyncHttpClient(new NettyAsyncHttpProvider(new AsyncHttpClientConfig.Builder().setUseProxyProperties(true).build())))
mirelon commented 9 years ago

The source code of Dispatch:

if (proxyServerSelector == null && useProxyProperties) {
  proxyServerSelector = ProxyUtils.createProxyServerSelector(System.getProperties());
}

if (proxyServerSelector == null) {
  proxyServerSelector = ProxyServerSelector.NO_PROXY_SELECTOR;
}

This is the cause why Http.configure(_.setUseProxyProperties(true)) won't work. First time Http.apply() creates NO_PROXY_SELECTOR. and configure() calls build() second time causing proxyServerSelector == null && useProxyProperties to be false.

mirelon commented 9 years ago

I suggest modifying Http.configure to not call build() twice