This week's book giveaway is in the HTML Pages with CSS and JavaScript forum.
We're giving away four copies of Testing JavaScript Applications and have Lucas da Costa on-line!
See this thread for details.
Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Help getting REST service to receive json and stop saying cannot find a mesage body reader or writer

 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am exhausted. I have tried for a couple days now to get something working with REST service.

I am making a non-gui REST solution used to receive from whatever REST client people will use some json to create a ticket. I did not plan to run this in Tomcat or Weblogic. The issue is it receives the JSON and then shows the content on stdout, but it then throws if I just try and put String ticket in :

Starting http server
May 06, 2016 11:26:41 AM com.sun.jersey.api.core.PackagesResourceConfig init
INFO: Scanning for root resource and provider classes in the packages:
com.sas.msds.des.servicenow
May 06, 2016 11:26:42 AM com.sun.jersey.api.core.ScanningResourceConfig logClasses
INFO: Root resource classes found:
class com.sas.msds.des.servicenow.ChangeticketRESTResource
May 06, 2016 11:26:42 AM com.sun.jersey.api.core.ScanningResourceConfig init
INFO: No provider classes found.
May 06, 2016 11:26:42 AM com.sun.jersey.server.impl.application.WebApplicationImpl _initiate
INFO: Initiating Jersey application, version 'Jersey: 1.19.1 03/11/2016 02:42 PM'
May 06, 2016 11:26:48 AM com.sun.jersey.spi.container.ContainerRequest getEntity
SEVERE: A message body reader for Java class java.lang.String, and Java type class java.lang.String, and MIME media type applicati
on/json was not found.
The registered message body readers compatible with the MIME media type are: // If I try and receive in POST ChangeTicket ticket instead of String ticket, it complains instead about no writer.
*/* ->
com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider


I have no clue on how to setup providers, message body readers, or message body writers. I am not sure about the right dependencies or order to put them in pom.xml.



It starts a HttpServer and listens on a port.
It has a class called ChangeTicket, which is basically public ChangeTicket() with a lot of set and gets for things to make a ticket. It does have an @override for toString() that returns the json used to make a ticket.

Then, there is a class called ChangeticketRESTResource with:


There is web.xml:



and a pom.xml for maven:




 
Marshal
Posts: 3150
466
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It lloks like the problem is that in line 28 you state that MediaType.APPLICATION_JSON type entity will be produced/returned, but in line 41 you are actually returning a String.
 
I'm not dead! I feel happy! I'd like to go for a walk! I'll even read a tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic