具有两个不同版本的服务器的java客户机

vngu2lb8  于 2021-07-09  发布在  Java
关注(0)|答案(1)|浏览(402)

我有一个java客户机,它连接到一个java服务器(servera),这个服务器是用jersey版本1.19实现的,所以我在pom中添加了相同版本的jersey客户机,一切正常。没有我的客户端需要连接到其他java服务器(服务器b),这是实现使用泽西版本2.17,然后问题开始。。。当我试图向服务器b发送请求时,我发现 org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException 在服务器a上,所有的请求都正常工作。经过一点研究,我明白了我需要更改pom文件中的jersey客户端版本。然后对服务器b的请求正常工作,但是对服务器a的请求得到了相同的异常,我尝试在我的pom中输入两个jersey客户端版本,只有服务器b正常工作。有什么方法可以让我使用两种版本的jersey服务器吗?
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:?]
yyyllmsg

yyyllmsg1#

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

相关问题