DataDog/datadog-api-client-java

java.lang.NoSuchMethodException: org.glassfish.jersey.message.DeflateEncoder when init v1 API

yaakov-berkovitch opened this issue · 5 comments

Describe the bug
Got java.lang.NoSuchMethodException: org.glassfish.jersey.message.DeflateEncoder.() when initializing v1 API
BTW, the error is understandable because the DeflateEncoder class has no default constructor, but I'm probably missing something else a lot of people should have report for the same.

The initialization code is as follows:

// Configure authorization
Map<String, String> secrets = new HashMap<>();
secrets.put("apiKeyAuth", System.getenv("DD_API_KEY"));
secrets.put("appKeyAuth", System.getenv("DD_API_KEY"));
// initialize V1 API
v1Client = com.datadog.api.v1.client.Configuration.getDefaultApiClient().configureApiKeys(secrets);

To Reproduce
It occurs all the time in my application.

Expected behavior
API must be initialized correctly.

Screenshots

Caused by: java.lang.RuntimeException: java.lang.InstantiationException: org.glassfish.jersey.message.DeflateEncoder
	at org.apache.cxf.jaxrs.impl.ConfigurationImpl.createProvider(ConfigurationImpl.java:240)
	at org.apache.cxf.jaxrs.impl.ConfigurationImpl.<init>(ConfigurationImpl.java:66)
	at org.apache.cxf.jaxrs.client.spec.ClientConfigurableImpl.<init>(ClientConfigurableImpl.java:37)
	at org.apache.cxf.jaxrs.client.spec.ClientBuilderImpl.withConfig(ClientBuilderImpl.java:160)
	at com.datadog.api.v1.client.ApiClient.buildHttpClient(ApiClient.java:1521)
	at com.datadog.api.v1.client.ApiClient.<init>(ApiClient.java:321)
	at com.datadog.api.v1.client.ApiClient.<init>(ApiClient.java:311)
	at com.datadog.api.v1.client.Configuration.getDefaultApiClient(Configuration.java:29)
	at com.algosec.shared.issuescenter.client.IssuesCenterClient.<init>(IssuesCenterClient.java:35)
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
	at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:204)
	... 215 common frames omitted
Caused by: java.lang.InstantiationException: org.glassfish.jersey.message.DeflateEncoder
	at java.base/java.lang.Class.newInstance(Class.java:571)
	at org.apache.cxf.jaxrs.impl.ConfigurationImpl.createProvider(ConfigurationImpl.java:238)
	... 228 common frames omitted
Caused by: java.lang.NoSuchMethodException: org.glassfish.jersey.message.DeflateEncoder.<init>()
	at java.base/java.lang.Class.getConstructor0(Class.java:3349)
	at java.base/java.lang.Class.newInstance(Class.java:556)
	... 229 common frames omitted

Environment and Versions (please complete the following information):
A clear and precise description of your setup:

  • java 11
  • datadog-api-client v1.5.0.

Additional context
Application is deployed in apache tomcat 9.0.54 on linux.

AFAIU the inject decorator should tell Apache CXF to pass the parameter: https://github.com/eclipse-ee4j/jersey/blob/c5e71d03a02f0f79a3df451c4d325d90a5953542/core-common/src/main/java/org/glassfish/jersey/message/DeflateEncoder.java#L55. Maybe some configuration is telling it to not take that into account? I'll try to reproduce it.

@therve in the meantime I also tried to isolate the issue in a simple test, and failed to reproduce it.
Also, looked at the pom.xml, and saw that the jersey version is 2.27, but in my project we are using 2.30.1.
Do you think it may be the root cause of my issue ? BTW, 2.27 is quite old (04/2018), with vulnerabilities (see https://mvnrepository.com/artifact/org.glassfish.jersey.core/jersey-client/2.27)

The vulnerability is in JUnit so I don't think it's very important, but we should upgrade anyway. I doubt that's the source though.

Thanks for your contribution!

This issue has been automatically marked as stale because it has not had activity in the last 30 days. Note that the issue will not be automatically closed, but this notification will remind us to investigate why there's been inactivity. Thank you for participating in the Datadog open source community.

If you would like this issue to remain open:

  1. Verify that you can still reproduce the issue in the latest version of this project.

  2. Comment that the issue is still reproducible and include updated details requested in the issue template.

We upgraded the deps and have a shaded jar now which could help. Let us know if you're still getting the issue, thanks.