rickfast / consul-client

Java Client for Consul HTTP API
Other
571 stars 240 forks source link

Exception in thread "main" java.lang.NoSuchMethodError: okhttp3.Interceptor$Chain.readTimeoutMillis()I #326

Open peterlai-roboops opened 6 years ago

peterlai-roboops commented 6 years ago

When ever i tried to register, i get this error. Exception in thread "main" java.lang.NoSuchMethodError: okhttp3.Interceptor$Chain.readTimeoutMillis()I at com.orbitz.consul.cache.TimeoutInterceptor.intercept(TimeoutInterceptor.java:28) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67) at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:185) at okhttp3.RealCall.execute(RealCall.java:69) at retrofit2.OkHttpCall.execute(OkHttpCall.java:180) at com.orbitz.consul.AgentClient.ping(AgentClient.java:61) at com.orbitz.consul.Consul$Builder.build(Consul.java:617) at Application.main(Application.java:40) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)

`
Consul consul = Consul.builder().build(); // connect to Consul on localhost AgentClient agentClient = consul.agentClient();

    String serviceName = "MyService";
    String serviceId = "MyService-Peter1";

    agentClient.register(8080, 3L, serviceName, serviceId); // registers with a TTL of 3 seconds
    try {
        agentClient.pass(serviceId);
    } catch (NotRegisteredException e) {
        System.out.println("peter " + e);
    }

`

yfouquet commented 6 years ago

Hi @tiny-cababge,

Can you please give us more details?

It looks like you are not using (at runtime) the same version of okhttp. Note that:

peterlai-roboops commented 6 years ago

Yea, adding the following dep works.

    <dependency>
        <groupId>com.squareup.okhttp3</groupId>
        <artifactId>okhttp</artifactId>
        <version>3.9.0</version>
    </dependency>

How come these wasn't packaged as part of the build?

yfouquet commented 6 years ago

I cannot tell you without without knowing what you use. Which version of consul-client do you use? Do you use the shaded artifact? Is there any other version on okhttp in your dependency tree?

Seeing the exception (NoSuchMethodError), you found the class, so you had a okhttp in your classpath. My guess is that an older version of okhttp was used (maybe because of other dependencies) and you got a dependency conflict. You should find out the reason as your fix may add new issues. Note that the shaded version protects you from such conflicts.

yfouquet commented 6 years ago

Hi @tiny-cababge, Is there any update on your issue? Either you consider it fixed and you can close the issue; or you still have issue and we'll be glad to help you.

peterlai-roboops commented 6 years ago

So i think the package uploaded to maven central is wrong, but ive just not got round to checking it.

Get Outlook for Androidhttps://aka.ms/ghei36


From: Yoann Fouquet notifications@github.com Sent: Tuesday, April 24, 2018 8:20:10 AM To: rickfast/consul-client Cc: tiny-cababge; Mention Subject: Re: [rickfast/consul-client] Exception in thread "main" java.lang.NoSuchMethodError: okhttp3.Interceptor$Chain.readTimeoutMillis()I (#326)

Hi @tiny-cababgehttps://github.com/tiny-cababge, Is there any update on your issue? Either you consider it fixed and you can close the issue; or you still have issue and we'll be glad to help you.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/rickfast/consul-client/issues/326#issuecomment-383829484, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ALAcRM1o6oLyrZaAVF8sOk9ni6Fw1fv5ks5trtIqgaJpZM4TbhAI.

bearrito commented 6 years ago

I can replicate this is the latest release.