0

I've upgraded to ReastEasy 4 on my client, but there are several errors reported depending on the configuration.

If I use only resteasy-core-spi and resteasy-client-api, I get

Exception in thread "main" java.lang.RuntimeException: java.lang.ClassNotFoundException: org.glassfish.jersey.client.JerseyClientBuilder

If I add resteasy-client, I get instead

javax.ws.rs.ProcessingException: RESTEASY004655: Unable to invoke request: 
javax.ws.rs.ProcessingException: RESTEASY003215: could not find writer for content-type application/json type: java.lang.String

Adding resteasy-core does not help. The documentation specifies only resteasy-client and resteasy-core, but I still get the error above.

Additionally, I use Jackson in my client, so I specified resteasy-jackson2-provider.

All versions are 4.5.8.Final.

Things used to work fine with version 3 using resteasy-jaxrs, but it was removed from 4 apparently.

I've looked at javax.ws.rs.ProcessingException: could not find writer for content-type application/json and Why is there no maven resteasy-jaxrs package for version 4.2.0?, but there is no solution there.

What are the needed dependencies for a version 4 client?

Update: build.gradle

repositories {
    jcenter()
    mavenCentral()
}

apply plugin: 'java'
apply plugin: 'eclipse'

sourceCompatibility = 14
targetCompatibility = 14

ext.resteasyVersion = "4.5.8.Final";

dependencies {
//  compile "org.jboss.resteasy:resteasy-core:$resteasyVersion"
//  compile "org.jboss.resteasy:resteasy-core-spi:$resteasyVersion"
//  compile "org.jboss.resteasy:resteasy-client-api:$resteasyVersion"
    compile "org.jboss.resteasy:resteasy-client:$resteasyVersion"
    compile "org.jboss.resteasy:resteasy-jackson2-provider:$resteasyVersion"

    compileOnly "org.projectlombok:lombok:1.18.12"
    annotationProcessor 'org.projectlombok:lombok:1.18.12'

    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.5.2'
    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.5.2'
    testCompile 'org.junit.platform:junit-platform-launcher:1.5.2'
}

Call site:

String stateString = MAPPER.writeValueAsString(state); // Mapper is ObjectMapper
Entity entity = Entity.entity(clientStateString, MediaType.TEXT_PLAIN); // or other media type
Response response = target.request().put(entity);
user1803551
  • 12,965
  • 5
  • 47
  • 74
  • Can you send plain text (text/plain) with a String? – Paul Samsotha Sep 29 '20 at 14:30
  • 1
    Trying to send a String with any content-type should be possible out of gate. There must be something you're _not_ telling us that is causing the problem. I just tested with just those two dependencies from your documentation link and it works fine for me. – Paul Samsotha Sep 29 '20 at 14:53
  • @PaulSamsotha `MediaType.TEXT_PLAIN` gives the same error, and yes, String should work without any configuration. I added the `build.gradle` and tried all sorts of combinations. So, what could I not be telling? What could affect it? I'm running the application from a fat jar, could it be that the dependencies were not packaged correctly? What should I be seeing inside? – user1803551 Sep 29 '20 at 15:27
  • That's it. The fat jar. That's what you weren't telling us. I bet it runs fine from your IDE, right? [Here](https://stackoverflow.com/q/53751401/2587435). Once you finish reading, [here](https://github.com/resteasy/Resteasy/blob/master/resteasy-core/src/main/resources/META-INF/services/javax.ws.rs.ext.Providers) is the service file that doesn't get added to the fat jar. The StringTextStar is the provider that handles all Strings. Just FYI. – Paul Samsotha Sep 29 '20 at 15:39
  • Actually, in this case, since it's application/json, it's the provider from the resteasy-jackson2-provider that doesn't get autoregistered. Before you added the Jackson provider, it would've been the generic StringTextStar Provider that would've been used. – Paul Samsotha Sep 29 '20 at 15:45
  • @PaulSamsotha This seems to be the case, however, I'm not using the ShadowJar plugin, I'm using https://github.com/openjfx/javafx-gradle-plugin, so I guess I will have to ask there. Thanks. By the way, what *are* the minimal dependencies that I need? I need the `jackson2-provider` and `client`? Or `core` also? – user1803551 Sep 30 '20 at 11:35
  • 1
    client pulls in core. So you just need the client and the jackson for JSON/POJO support. – Paul Samsotha Sep 30 '20 at 16:00

0 Answers0