Reputation: 77
I'm having a java client that connected to a java server(Server A) that implemented with jersey version 1.19, so i add to my pom the jersey client of the same version and everything worked fine.
No my client needed to connect with other java server(Server B) that was implemented using jersey version 2.17, then the problems begins...
When i tried to sent requests to sever B, i was getting org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException
and with server A all the request worked fine. After a little research, i understood that i needed to change the jersey client version in my pom file.
Then the requests to Server B were working fine, but the requests to Server A were getting the same exception, i tried to put in my pom both of jersey client version and only server B was working fine.
Is there any way that i can work with two kind of version of jersey servers?
My dependencies in the pom file
<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>
The exception stack trace that i'm getting:
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:?]
Upvotes: 1
Views: 866
Reputation: 77
I succeeded to solve this by using a another rest client named Unirest that worked fine with both servers. Thanks
Upvotes: 1