aspose file tools*
The moose likes Web Services and the fly likes Chapter 3 from REST O'Reiley Book Issue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "Chapter 3 from REST O Watch "Chapter 3 from REST O New topic
Author

Chapter 3 from REST O'Reiley Book Issue

Mike London
Ranch Hand

Joined: Jul 12, 2002
Posts: 1066
Hello,

I'm having an issue getting even the basic REST example from the Chapter 3 ("Restful Java with JAX-RS") code to work.
It looks like everything is set up correctly, and I've spent the requisite 40 or so (mind-numbing, hair pulling, head banging against the table, etc.) hours
wresting with what "should" be simple code to get working.

The basic idea is that you would do a POST to add a new customer to the service's internal Java ConcurrentHashMap.

So, the service has the service side and the testing side. The author of the book uses maven and test cases and all works (of course) fine in the book.

I'm really starting to wonder how many people are using REST, because it seems incredibly difficult to get working.

=================

Here's the server logic (note that even the constructor log4j output is not writing an initial message).



---------------------------------------------

Here's the web.xml to set things up:



---------------------------------------------------

Finally, here's a test case (that doesn't work, but doesn't crash, doesn't log, etc.)



Not sure why this basic example doesn't work, but I'd appreciate any suggestions or replies.

Thanks,

-mike
H Paul
Ranch Hand

Joined: Jul 26, 2011
Posts: 460
    
    4
To debug, I would do different ways:

0. Change catch (IOException e) to catch (Exception e) and run the test. Look at server log as well.

1. Use TCP/IP mon that you can download and watch for the request sent to the server
and the response sent back to the client.

2. Without using the code, Use Restclient from Firefox brower, send a POST and xml request body.
OR use SOAP UI

Good luck.
Mike London
Ranch Hand

Joined: Jul 12, 2002
Posts: 1066
H Paul wrote:To debug, I would do different ways:

0. Change catch (IOException e) to catch (Exception e) and run the test. Look at server log as well.

1. Use TCP/IP mon that you can download and watch for the request sent to the server
and the response sent back to the client.

2. Without using the code, Use Restclient from Firefox brower, send a POST and xml request body.
OR use SOAP UI

Good luck.


Thanks for your reply. No Exceptions were thrown even with Exception instead of IOException.

I finally got everything working. The reason Intellij was putting up a Invalid format RESPONSE was that
the REST method was expecting a Stream and I was just sending it nothing from the REST POST test.
Intellij was correct. In any case, that error let me know things were getting close.

I was getting a 201 (HTTP "Created") in my client test code, so it was really confusing why nothing was happening....

This other problem was that the URL test code above was not connecting for some reason to the server REST logic.
I created the log4j setup to try see what was going on, but no log entries were being created. The problem there turned out
to be that I was running the test code too many times and the URL wasn't reachable.
Once I closed down each test program each time, it worked like a charm.

A few little tweaks here and there (like removing the spaces from readCustomer() fields read from the DOM), but otherwise, it works ... finally.

Test code works and Log4j is spitting out log entries like crazy!

Thanks very much for your reply.

-mike
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Chapter 3 from REST O'Reiley Book Issue