0

I'm developing a RESTful web-service using Jersey. I am using maven to manage my dependencies and eclipse export method to create the jar. When running the jar on my Ubuntu pc, everything is working fine, but when I'm executing the same jar on a remote Openshift server I'm experiencing this weird thing:

  • The server start and running, executing a GET request returns the expected answer.
  • Executing a POST method return a 500 server error, when on my local machine it returns the expected result.

Diving into this problem I have realised the following facts:

The last line the program is printing is validate.fullmessage: ... and the correct String message representation of the JSONObject. The "1" line is not printed to the log. No exception is thrown or written to the log as well!

public static boolean validate(String fullMessage) {
...
try {
        System.out.println("validate.fullmessage: " + fullMessage);
        JSONObject jsonMessage = new JSONObject(fullMessage);
        System.out.println("1");
        ...

    } catch (Exception e) {
        System.out.println("validation exception");
        e.printStackTrace();
    }
...
}

Moreover, whenever I return 200 ok or server error I'm writing it to the log, but no error is written to the log. It seems like the server return 500 server error with no reason and not from my code...

RESTHandler:

@POST
@Consumes(MediaType.APPLICATION_JSON)
@Path("/createPlayer")
public Response createUser(String strPlayer) {
    System.out.println("createPlayer. strPlayer: " + strPlayer);
    Response r;

    System.out.println("validating");
    if (!ValidateHandler.validate(strPlayer)) {
        System.out.println("validation failed!");
        r = Response.serverError().build();
    }

    ...

    System.out.println("finished");

    return r;
}

The "finished" is also not written to the log. Can anyone help me figure out this weird behaviour?

itaied
  • 6,827
  • 13
  • 51
  • 86
  • Could you please provide Openshift server console log? Different server sometimes give different output. – Saikat Biswas Nov 06 '15 at 11:02
  • If GET is OK in Openshift then try the validate method in any test GET handler method to know if the POST request processing is different in Openshift server. Please look into this : https://developers.openshift.com/en/managing-environment-variables.html – Saikat Biswas Nov 06 '15 at 11:10
  • 1
    You might be getting some RuntimeError in that line. _Just temporarily_ change your exception handling to catch `Throwable` except `Exception`, and see if you get any error logged. – Gergely Bacso Nov 06 '15 at 11:13
  • There is nothing interesting there, since I'm working on a Do It Yourself instance, and I'm pushing my jar with git, logging to the server and run the jar using `java -jar my-app.jar`. – itaied Nov 06 '15 at 11:14
  • @GergelyBacso you were right! I changed it to `Throwable` and now I see the error, it is a `major minor` one. Why didn't the `Exception` catch the error? – itaied Nov 06 '15 at 11:20
  • This post explains the difference very well: http://stackoverflow.com/questions/2274102/difference-between-using-throwable-and-exception-in-a-try-catch – Gergely Bacso Nov 06 '15 at 11:30
  • what is _"eclipse export method to create the jar"_ supposed to mean? Doesnt make any sense, eclipse doesnt _"export"_ anything. You're **building** with maven or with the eclipse JDT - which simply invokes javac and whatnot ... and building with eclipse while you got maven is kinda ... weird ... Maven does compilation exceptionally good, eclipse on the other hand ... not so much; which is logical since eclipse is focused on many other things, the final artifact representation being only a minor one, of course – specializt Nov 06 '15 at 11:51

1 Answers1

2

Ok. So after temporarily changing the Exception handling to catch all Throwables (this way catching RuntimeErrors also, not only Exceptions), the problem turned out to be java versioning issue.

On the remote machine you are using a different version of java, probably older than the one which was used to compile one of your libraries.

  • The easy solution (if this is available) is upgrading your remote server java version to the one that is used on your computer locally.

  • If that is not an option, then you need to analyze the error and find and downgrade the library which is incompatible with your outdated server java version.

Gergely Bacso
  • 14,243
  • 2
  • 44
  • 64