1 Reply Latest reply on Aug 29, 2016 9:08 PM by eudriscabrera-JavaNet

    jax-rs RESTful web service with Glassfish

    BeRoots

      Hi everybody

       

      I have buid a RESTful web service with using jax-rs. Its a simple RESTful that returns an entity from a database. This entity is a simple user (id ; email ; password ; adress ; ...). Everything works well and if i call url http://localhost:8080/myNetBeansProject/user i have an xml with all user in the table


      I would like to create another @GET method from path "email" to return just the user email list. It is possible from the same entity ?

      I have a 500 internal server error with this code and i have no error in the glassfish output:
      http://pastebin.com/KDeunQ24


      The problem is with the findAllEmail namedQuery (line 38), call in the AbstractFacade.java (line 275) and fired by the method @GET findAllEmail() (line 334).

       

      The full project: https://github.com/BeRoots/WebServiceREST


      If you have any issue for this problem

      Thank in advance...

       

      Ce message a été modifié par : 80af4bb6-a969-4405-86f7-d48ebf72e06c

       

      Ce message a été modifié par : Deschamps Sébastien

        • 1. Re: jax-rs RESTful web service with Glassfish
          eudriscabrera-JavaNet

          You are using a named query "WpUsers.findAllEmail" where you are trying to return only the "userEmail" field ("SELECT w.userEmail FROM WpUsers w"). userEmail field is a String and your method return a List of WpUsers objects.

           

          public List<T> findAllEmail() {
                  return getEntityManager().createNamedQuery("WpUsers.findAllEmail").getResultList();
          }
          

          You can use the findAll() method, iterate the returned list and just return the userEmail field.

           

          You must define a custom MessageBodyWriter to parse the List, if you got the following error

          "MessageBodyWriter not found for media type=application/xml, type=class java.util.ArrayList, genericType=java.util.List<java.lang.String>"
          

          .