Jersey Client NoSuchMethodError: org.glassfish.jersey.client.ClientRequest.getLengthLong()J

Jersey Client NoSuchMethodError: org.glassfish.jersey.client.ClientRequest.getLengthLong()J

我有一个球衣客户端配置并发出如下请求:

private Response getResponse(Authorization authInstance, String filePath) {
    return webResourceInstance.request().header("Authorization", 
            encode(authInstance)).put(Entity.entity(getFileInStream(filePath), MediaType.APPLICATION_OCTET_STREAM));
}

获取此异常:

javax.ws.rs.ProcessingException: org.glassfish.jersey.client.ClientRequest.getLengthLong()J
at org.glassfish.jersey.client.ClientRuntime.invoke(ClientRuntime.java:261)
at org.glassfish.jersey.client.JerseyInvocation.call(JerseyInvocation.java:684)
at org.glassfish.jersey.client.JerseyInvocation.call(JerseyInvocation.java:681)
at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
at org.glassfish.jersey.internal.Errors.process(Errors.java:228)
at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:444)
at org.glassfish.jersey.client.JerseyInvocation.invoke(JerseyInvocation.java:681)
at org.glassfish.jersey.client.JerseyInvocation$Builder.method(JerseyInvocation.java:437)
at org.glassfish.jersey.client.JerseyInvocation$Builder.put(JerseyInvocation.java:326)
at oracle.esscs.rest.core.REST_PUTProcessor.getResponse(REST_PUTProcessor.java:139)
at oracle.esscs.rest.core.REST_PUTProcessor.execRequest(REST_PUTProcessor.java:123)
at oracle.esscs.rest.setup.FilesUtils.uploadFiletoUserDir(FilesUtils.java:73)
at oracle.esscs.rest.tests.cubedesigner.TestBSOTemplates.testBSOTemplates(TestBSOTemplates.java:73)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:104)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:645)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:851)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1177)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112)
at org.testng.TestRunner.privateRun(TestRunner.java:756)
at org.testng.TestRunner.run(TestRunner.java:610)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:387)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:382)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:340)
at org.testng.SuiteRunner.run(SuiteRunner.java:289)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1293)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1218)
at org.testng.TestNG.runSuites(TestNG.java:1133)
at org.testng.TestNG.run(TestNG.java:1104)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:236)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:81)
Caused by: java.lang.NoSuchMethodError: org.glassfish.jersey.client.ClientRequest.getLengthLong()J
at org.glassfish.jersey.client.internal.HttpUrlConnector._apply(HttpUrlConnector.java:364)
at org.glassfish.jersey.client.internal.HttpUrlConnector.apply(HttpUrlConnector.java:285)
at org.glassfish.jersey.client.ClientRuntime.invoke(ClientRuntime.java:252)
... 38 more

我看到了这个版本的相同问题 here but there is no accepted answer and I am already using jersey-client & jersey-media-json-jackson version 2.25.1. Also, the method seems to be available as per documentation

早些时候一切正常,但我正在尝试迁移到泽西岛 2.x,不确定这是否重要。

方法 org.glassfish.jersey.client.ClientRequest.getLengthLong() 中出现的错误出现在 jersey-common-2.25.1.jar 中。

因此,如果您使用 maven,请在 pom.xml -

中包含以下依赖项
<dependency>
    <groupId>org.glassfish.jersey.core</groupId>
    <artifactId>jersey-common</artifactId>
    <version>2.25.1</version>
</dependency>