0

I am new to Java based Web Development.

I am using Eclipse Version: 2018-09 (4.9.0), JDK 1.8, Tomcat v9.0

I am currently building a tutorial Jersey Maven project. I just created an API endpoint but am getting status 500. The problem is I don't know how to debug it.

here is the controller code

@Path("aliens")
public class AlienResource {

    @GET
    @Produces(MediaType.APPLICATION_XML)
    public Alien getAlien() {
        Alien a1 = new Alien();
        a1.setName("hello");
        a1.setPoint(23);
        System.out.println("*****");
        System.out.println(a1);
        return a1;
    }
}

The eclipse console has no errors. It does have the System.out.println("*****") and System.out.println(a1);, which means that the function getAlien() is being called. Upon researching the internet I found that Tomcat in eclipse prints out the server logs in the console itself, however, using this link I did try to redirect the logs to some other file, catalina.out which I created inside my workspace. I also did a sudo chmod a+w catalina.out in order to avoid any permissions issue. But catalina.out remains empty.

I don't understand how do I debug the 500 error and where will I get the error log?

PS: the default API endpoint provided by jersey works ie. http://localhost:8080/demorest/webapi/myresource works fine.

coda
  • 2,188
  • 2
  • 22
  • 26
  • 1
    when you run the application. is all you get the `*******` and the a1 output or do you see other stuff as the application comes up? My guess is it has something to do with serializing the object to the response. set a break point on your log statements and see where it goes after your method. some exception is happening. – mavriksc Jan 10 '19 at 22:05
  • 1
    Are you launching with Debug? Can you set breakpoints on those lines and keep stepping until the 500 is generated? – nitind Jan 10 '19 at 22:21
  • 1
    Did you check the other logs ? – Eugène Adell Jan 10 '19 at 22:31
  • @EugèneAdell yes I did nothing else where – coda Jan 10 '19 at 22:35
  • @mavriksc I get other stuff as the project build up like ....................................... Jan 11, 2019 4:02:36 AM org.apache.catalina.core.StandardContext reload INFO: Reloading Context with name [/demorest] is completed Jan 11, 2019 4:03:06 AM org.apache.catalina.core.StandardContext reload – coda Jan 10 '19 at 22:36
  • @nitind no i am not launching as debug but shouldn't error msges be printed given that the build messages are getting printed and the System.out msges too? – coda Jan 10 '19 at 22:39
  • Maybe there is some logging config for jersey. This seems pretty minimal and generic can you post on GIT ? – mavriksc Jan 10 '19 at 22:45
  • Search Stacy Overflow for "DebugExceptionMapper" in the jersey tag. One of my answers should come up where this is an ExceptionMapper you can try to register. Maybe the exception is being swallowed up. If that's the case, with the mapper, you might be able to print the stack trace. – Paul Samsotha Jan 12 '19 at 17:41

0 Answers0