Uploaded image for project: 'Tools (JBoss Tools)'
  1. Tools (JBoss Tools)
  2. JBIDE-18823

Invalid generated code in JAX-RS Endpoint

    XMLWordPrintable

Details

    Description

      The generated code in the 'create' method contains something like this:

      return Response.created(
        UriBuilder.fromResource(Session.class)
        .path(String.valueOf(session.getId())).build()).build();
      

      but the Session.class should be SessionEndpoint.class since it must be the resource class annotated with @Path

      Also, after discussion with manderse@redhat.com, here the plan to fix this issue:

      • if the create method generation is selected and the target entity is selected and contains a 'getId()' method, then generate the following method body:
        //TODO: process the given pojo 
        
        // here we use Pojo#getId(), assuming it provides the end-user with the identifier to retrieve the created Pojo resource
        Response.created(UriBuilder.fromResource(PojoEndpoint.class).path(String.valueOf(pojo.getId())).build())
        				.build();
        
      • if the create method generation is selected and the target entity is selected and does not contain a 'getId()' method, then generate the following method body:
        //TODO: process the given pojo 
        
        // you may want to do something like this
        // return Response.created(UriBuilder.fromResource(PojoEndpoint.class).path(String.valueOf(pojo.getId())).build();
        // assuming that Pojo#getId() or a similar method would provide the end-user with the identifier to retrieve the created Pojo resource
        Response.created(null).build();
        

      If no target entity is provided, there is no way to generate the method skeletons.

      The goal if this change is to make sure we generate code that compiles (that was not the case if the target entity class did not have a getId() method) and that returns a sensitive Response object (hence, we don't return null).

      Attachments

        Issue Links

          Activity

            People

              xcoulon@redhat.com Xavier Coulon
              xcoulon@redhat.com Xavier Coulon
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: