Java 客户端有两个不同版本的球衣服务器

Java client with two different versions jersey servers

我有一个 java 客户端连接到 java 服务器(服务器 A),该服务器使用 jersey 1.19 版实现,所以我将相同版本的 jersey 客户端添加到我的 pom一切正常。 不,我的客户端需要连接使用 jersey 2.17 版实现的其他 java 服务器(服务器 B),然后问题就开始了…… 当我试图向服务器 B 发送请求时,我得到 org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException 并且对于服务器 A,所有请求都工作正常。经过一番研究,我明白我需要更改我的 pom 文件中的球衣客户端版本。 然后对服务器 B 的请求工作正常,但对服务器 A 的请求出现相同的异常,我试图在我的 pom 中放入两个球衣客户端版本,只有服务器 B 工作正常。 有什么方法可以使用两种版本的球衣服务器吗?

我在 pom 文件中的依赖项

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>javax.ws.rs</groupId>
        <artifactId>javax.ws.rs-api</artifactId>
        <version>2.0</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jersey.core</groupId>
        <artifactId>jersey-client</artifactId>
        <version>2.17</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jersey.media</groupId>
        <artifactId>jersey-media-moxy</artifactId>
        <version>2.17</version>
    </dependency>
    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-client</artifactId>
        <version>1.19</version>
    </dependency>

我得到的异常堆栈跟踪:

        Jan 03, 2017 5:03:22 PM org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor aroundWriteTo
    SEVERE: MessageBodyWriter not found for media type=application/json, type=class com.sun.jersey.api.representation.Form, genericType=class com.sun.jersey.api.representation.Form.
    [ERROR] 2017-01-03 17:03:23 [JavaFX Application Thread] controller.login(76) - Unable To Connect to the server.
    org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException: MessageBodyWriter not found for media type=application/json, type=class com.sun.jersey.api.representation.Form, genericType=class com.sun.jersey.api.representation.Form.
        at org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor.aroundWriteTo(WriterInterceptorExecutor.java:247) ~[jersey-common-2.17.jar:?]
        at org.glassfish.jersey.message.internal.WriterInterceptorExecutor.proceed(WriterInterceptorExecutor.java:162) ~[jersey-common-2.17.jar:?]
        at org.glassfish.jersey.filter.LoggingFilter.aroundWriteTo(LoggingFilter.java:302) ~[jersey-common-2.17.jar:?]
        at org.glassfish.jersey.message.internal.WriterInterceptorExecutor.proceed(WriterInterceptorExecutor.java:162) ~[jersey-common-2.17.jar:?]
        at org.glassfish.jersey.message.internal.MessageBodyFactory.writeTo(MessageBodyFactory.java:1128) ~[jersey-common-2.17.jar:?]
        at org.glassfish.jersey.client.ClientRequest.writeEntity(ClientRequest.java:502) ~[jersey-client-2.17.jar:?]
        at org.glassfish.jersey.client.HttpUrlConnector._apply(HttpUrlConnector.java:329) ~[jersey-client-2.17.jar:?]
        at org.glassfish.jersey.client.HttpUrlConnector.apply(HttpUrlConnector.java:242) ~[jersey-client-2.17.jar:?]
        at org.glassfish.jersey.client.ClientRuntime.invoke(ClientRuntime.java:245) ~[jersey-client-2.17.jar:?]
        at org.glassfish.jersey.client.JerseyInvocation.call(JerseyInvocation.java:671) ~[jersey-client-2.17.jar:?]
        at org.glassfish.jersey.client.JerseyInvocation.call(JerseyInvocation.java:668) ~[jersey-client-2.17.jar:?]
        at org.glassfish.jersey.internal.Errors.process(Errors.java:315) ~[jersey-common-2.17.jar:?]
        at org.glassfish.jersey.internal.Errors.process(Errors.java:297) ~[jersey-common-2.17.jar:?]
        at org.glassfish.jersey.internal.Errors.process(Errors.java:228) ~[jersey-common-2.17.jar:?]

我通过使用另一个名为 Unirest 的休息客户端成功解决了这个问题,该客户端在两台服务器上都运行良好。谢谢