• 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Bear Bibeault
  • Liutauras Vilda
  • Devaka Cooray
  • Knute Snortum
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
  • salvin francis
  • Frits Walraven
  • Piet Souris

Resolving the webApp root from the context of a REST Resource Object

Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

This is my first post on the boards, so please be kind I guess my questions is already answered somewhere, but I'm still a little helpless with the search.
I have written REST APIs for database access before and I'm familiar with Servlets and Web Services. The work here is part of my diploma thesis and i could really need a hint or two ;)

It was easy to find out, how to resolve the webapp root from a simple Servlet (ServletContext#getRealPath(url)), but for a Rest Resource... no clue^^ I'm sure it must be possible in a few lines of code, but i didn't find anything on the net yet. Thanks in advance!

The ultimate goal is to store files (sent by a java applet) on the server (a Tomcat6.0) with a simple HTTP PUT command. The files are placed in a subdirectory of WEB-INF. The Rest API should list all files under the URL "MyWebAppRoot/messages/" and later i want to store and get files by the URL "MyWebAppRoot/messages/{message}".
The whole story is, that a Java Applet records voice and sends it to the server (The processing part is not my construction site). Using files is only a quick'n'dirty fallback, personally i would prefer a streaming solution, but since i have no experience with that, it would just bloat things up at the moment. Anyway, i would be thankful for hints on that topic too.
The big picture is, there's a set of tools developed at our university for generating user interfaces from in-house XML models - including previous work of mine. My work consists of 1) creating a generator for GWT interfaces, 2) adding sound input/output to the XML models, and 3) GWT elements for sound I/O.
I have already implemented the Java applet for recording (.wav files) and a wrapping GWT element. The job is now to bring the recording to the server. If a realtime streaming thing would be possible without too much overhead, that would be just great! But my time is limited and there's other work to do, so i think i will stick with the Rest API.

Ranch Hand
Posts: 2198
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not sure I understand your question, but I will nevertheless make an attempt at providing what I hope will be some clues to an answer.
Have you seen then JAX-RS specification, chapter 6?
Using the @Context annotation, you can inject objects of the type ServletContext, HttpServletRequest etc into instances of your resource-handling class(es).
Perhaps this is of help.
Best wishes!
Felix Woitzel
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm new to uploading files and i have just found a way, with one Servlet for saving form uploads and the REST Resource using this Servlet over a HttpClient object. I came up with the idea that the Resource object makes use of a dedicated file upload Servlet like the CommonsFileUploadServlet with extended renaming options.

I'm using the Restlet implementation and Eclipse with the WTP and GWT plugins. The servlets get deployed on a Tomcat6.0.

But i have not answered the thread title's question yet. It was a good learning session for me, but it would have been quicker if the org.restlet.resource.Resource object had an obvious way to resolve the root directory of the nesting web application on the server or a dynamic path pointing on the WEB-INF directory. Maybe the annotation thing is the key, but I'm working on the HttpClient.

anyway, thank you!
This one time, at bandcamp, I had relations with a tiny ad.
Java file APIs (DOC, XLS, PDF, and many more)
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!