2017-02-24 121 views
1

我有一個Jersey客戶端配置,使請求如下:Jersey客戶端的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$1.call(JerseyInvocation.java:684) 
at org.glassfish.jersey.client.JerseyInvocation$1.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,但沒有接受的答案,我已經使用jersey-client & jersey-media-json-jackson版本2.25.1。此外,該方法似乎可以根據此版本的documentation獲得。

一切工作正常,但我正在嘗試遷移到澤西2.x,不知道這是否重要。

回答

4

您得到的方法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> 
+0

太謝謝你了! – mbsingh