0

I am just starting with Glassfish, and trying to set up a restful web service that can take a JSON string and parse it and return proper results. The web service looks like this:

@Path("/process")
public class SurveyResponseProcessor
{
    @GET
    @Produces("text/plain")
    public String getReferrals()
    {
        return "Only POST operation are supported.";
    }

    @POST
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)
    public String postReferrals(ResponseDetails details)
    {
        return "done - " + details.getSurveyId();
    }
}

The class that I expected to get the JSON:

@XmlRootElement
public class ResponseDetails
{
    @XmlElement String providerId;
    @XmlElement String surveyId;
    @XmlElement String respondentId;

    public String getProviderId()
    {
        return providerId;
    }


    public void setProviderId(String providerId)
    {
        this.providerId = providerId;
    }

    public String getSurveyId()
    {
        return surveyId;
    }

    public void setSurveyId(String surveyId)
    {
        this.surveyId = surveyId;
    }

    public String getRespondentId()
    {
        return respondentId;
    }

    public void setRespondentId(String respondentId)
    {
        this.respondentId = respondentId;
    }
}

The POST body: {"providerId":"1","surveyId":"5","respondentId":"23"}

The error message:

<p><b>message</b>Internal Server Error</p><p><b>description</b>The server encountered an internal error that prevented it from fulfilling this request.</p>

Nothing shows up in any of the logs.

EDIT TO ADD: If I set it to consume text and change the arguments, this works just fine, telling me it is not a routing issue. Is it possible I haven't set JAXB or Jersey somewhere? I am using IntelliJ, if that matters.

Wige
  • 3,788
  • 8
  • 37
  • 58
  • 500 is an internal Server error. Look into the Server logfiles and you find the exception which is the reason. – Jens Aug 28 '17 at 14:28
  • BTW: JSON != XML. You have a lot of XML annotations in the class which should consume the json, but no JSON related annotations – Jens Aug 28 '17 at 14:29
  • This may be of help, they don't seem to return a String, rather a JsonObject > https://stackoverflow.com/a/14621300/8041461 – jrtapsell Aug 28 '17 at 14:33
  • @Jens None of the Glassfish logs have anything about the request in them. The XML annotations are what I have seen used in every example and question on this topic I have found, such as https://stackoverflow.com/questions/28983048/how-to-consume-json-parameter-in-java-restful-service – Wige Aug 28 '17 at 14:40

0 Answers0