1

Hi

I need to develop simple web service on java. I'm new to java tech and based on several articles decided to use JAX-RS (Jersey) with embedded http server (Grizzly2), because it looks suitable for building REST services and deployment seems to be trivial.

In my dev environment all works perfect (using IntllijIdea).

But when I try to deploy on test server every request returns "500 Internal Error" (even /application.wadl)

Here more info:

Simple resource

@Path("resource")
public class SpeechRecognition {
    @GET
    public Response test() {
        Logger.getGlobal().log(Level.INFO, "resource test");
        return Response.ok("success", MediaType.TEXT_PLAIN).build();
    }
}

Simple resource config

public class SimpleApiServer extends ResourceConfig {
    public SimpleApiServer() {
        register(MultiPartFeature.class);
        register(LoggingFilter.class);
        register(JacksonFeature.class);

        property(ServerProperties.TRACING, "ALL");
        property(ServerProperties.TRACING_THRESHOLD, "VERBOSE");

        packages("com.mydomain");
    }
}

Simple app start

public static void main(String[] args) throws IOException {
    final HttpServer server = GrizzlyHttpServerFactory.createHttpServer("http://0.0.0.0:80", new SimpleApiServer());

    System.out.println(String.format("Jersey app started with WADL available at "
            + "%sapplication.wadl\nHit enter to stop it...", serverUri.toString()));
    System.in.read();
    server.stop();
}

Exception mapping

@Provider
public class AppExceptionMapper implements ExceptionMapper<Throwable> {
    @Override
    public Response toResponse(Throwable ex) {
        Logger.getGlobal().log(Level.WARNING, "exception response");

        ex.printStackTrace();

        return Response.status(500).entity(Exceptions.getStackTraceAsString(ex)).type("text/plain")
            .build();
    }
}

What is happening

For every request I see in console

- that grizzly accepts it (prints all information about headers etc.) - and that resource code is executed ("resource test" is printed) And nothing more.

In postman I receive "500 Request Failed" with no trace from Jersey in headers (though I specified property(ServerProperties.TRACING, "ALL");)

No information printed in server console about any exceptions.

I have an idea, that something bad happens when jersey tries to pass response to grizzly.

Does anyone has any thoughts about where should I look to troubleshoot this problem? I really stuck with it.

And I really don't want to rewrite everything (not this simple ill example, but lots more) to traditional java servlet-oriented code ('cause it's another piece of tech to learn about)

P.S.

Test server - is the docker container on azure linux VM. Requests are proxied by nginx to exposed docker port. Got web-site on Rails using the same scheme, which works fine.

When grizzly prints info about request it prints incorrect hostname. I.e. actual host name is test.api.mydomain.com and grizzly writes GET http://test.api:80/resource

Will Shao - MSFT
  • 1,189
  • 7
  • 14
Alex Shtuk
  • 325
  • 3
  • 9

1 Answers1

4

Ok.
It was the Jersey version mismatch in dev and test environments.

Remote debugging (with IntellijIdea) showed, that in process of forming response

Exception: AbstractMethodError: javax.ws.rs.core.Response.getStatusInfo()Ljavax/ws/rs/core/Response$StatusType;

is thrown, wich led me to this post.
After fixing the dependencies all works fine.

Community
  • 1
  • 1
Alex Shtuk
  • 325
  • 3
  • 9