Skip to content
This repository has been archived by the owner on Apr 5, 2022. It is now read-only.

OkHttpClientHttpRequestFactory prevents usings OkHttp interceptors #24

Closed
clemp6r opened this issue Feb 19, 2015 · 14 comments
Closed

OkHttpClientHttpRequestFactory prevents usings OkHttp interceptors #24

clemp6r opened this issue Feb 19, 2015 · 14 comments

Comments

@clemp6r
Copy link

clemp6r commented Feb 19, 2015

OkHttpClientHttpRequestFactory uses OkUrlFactory.

With OkHttp 2.2.0 comes a new great feature: Interceptors. Interceptors won't work when using OkUrlFactory, as explained here: /~https://github.com/square/okhttp/wiki/Interceptors

Can you provide a different implementation of OkHttpClientHttpRequestFactory that don't use OkUrlFactory so we can use interceptors?

(FYI http://facebook.github.io/stetho/ needs OkHttp interceptors)

@gmarques33
Copy link

I'm also trying to use Stetho with interceptors and I have this problem too.
I'm trying to use StethoURLConnectionManager with a custom ClientHttpRequestFactory, but I can get only request on chrome dev tools.

@WonderCsabo
Copy link
Contributor

Guys, how an other implementation should look like? I assume it cannot be achieved easily.

@royclarkson
Copy link
Contributor

Spring Framework recently included OkHttp support. It can probably be adapted for android.

Sent from my iPad

On Jun 20, 2015, at 07:53, Csaba Kozák notifications@github.com wrote:

Guys, how an other implementation should look like? I assume it could not be achieved easily.


Reply to this email directly or view it on GitHub.

@WonderCsabo
Copy link
Contributor

Can you reference the changeset which did that?

@WonderCsabo
Copy link
Contributor

@royclarkson can you point me to the changeset? :)

@WonderCsabo
Copy link
Contributor

Never mind. 😉 Thanks for fixing this!

@royclarkson
Copy link
Contributor

@WonderCsabo I spent some time last night and modified the implementation from Spring Framework. It should be in a good place now.

@royclarkson
Copy link
Contributor

I pushed 2.0.0.M3 with the latest OkHttp support. It's available for testing from the spring repository.

@WonderCsabo
Copy link
Contributor

@royclarkson i am getting this exception:

java.lang.IllegalArgumentException: method POST must have a request body.
    at com.squareup.okhttp.Request$Builder.method(Request.java:244)
    at org.springframework.http.client.OkHttpClientHttpRequest.executeInternal(OkHttpClientHttpRequest.java:85)
    at org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal(AbstractBufferingClientHttpRequest.java:48)
    at org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:84)
    at org.springframework.http.client.InterceptingClientHttpRequest$RequestExecution.execute(InterceptingClientHttpRequest.java:91)
    at my.super.secret.package.AuthorizationInterceptor.intercept(AuthorizationInterceptor.java:29)
    at org.springframework.http.client.InterceptingClientHttpRequest$RequestExecution.execute(InterceptingClientHttpRequest.java:81)
    at org.springframework.http.client.InterceptingClientHttpRequest.executeInternal(InterceptingClientHttpRequest.java:67)
    at org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal(AbstractBufferingClientHttpRequest.java:48)
    at org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:84)
    at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:536)
    at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:499)
    at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:447)

The same call worked with M2.

@royclarkson
Copy link
Contributor

Hmm. Looks like there was a change in OkHttp 2.4 to require a request body. The dependency was updated from 2.1.0 to 2.4.0 in the M3 release. Would you mind opening a new issue please? We can probably handle this situation.

@WonderCsabo
Copy link
Contributor

@royclarkson i am not sure about that. I was already using OkHttp 2.4 and i experienced no problems with the old OkHttpRequestFactory implementation in M2.

@royclarkson
Copy link
Contributor

M2 was using the UrlConnection API, instead of a proper implementation. That might be why it was still working. I'm guessing at this point.

@WonderCsabo
Copy link
Contributor

Yeah, i know that. :) I opened #25.

@royclarkson
Copy link
Contributor

Heh. Thanks for the reminder. :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

4 participants