• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Chapter 3 from REST O'Reiley Book Issue

 
Bartender
Posts: 1973
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 491
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Bartender
Posts: 1973
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
These are not the droids you are looking for. Perhaps I can interest you in a tiny ad?
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic