Java客户端有两个不同版本的泽西服务器

时间:2017-01-04 07:41:55

标签: java jersey jersey-client

我有一个java客户端连接到使用jersey版本1.19实现的java服务器(服务器A),所以我向我的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$1.call(JerseyInvocation.java:671) ~[jersey-client-2.17.jar:?]
        at org.glassfish.jersey.client.JerseyInvocation$1.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:?]

1 个答案:

答案 0 :(得分:1)

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