If I'm going to run Restlets inside Tomcat or any Servlet container........
New to Restlets and have a question. Apologies if it's come up before, I couldn't find it in the archives Do I need to create a Component instance and attach the Application to it if I'm going to run Restlests inside a Servlet container? I looked at the example com.testServlet.TestServletApplication and it wasn't clear to me why there is a main() in there and why a Component is created. The First Steps example didn't have any of that. The way I understand the architecture is that you only need to create a Component and have a main() is if you are going to run stand alone. Is this correct? Thanks for any assistance and would appreciate any guidance or places to look in the archives about best practices for running inside a Servlet container. Ted
Re: If I'm going to run Restlets inside Tomcat or any Servlet container........
Hello Ted, The way I understand the architecture is that you only need to create a Component and have a main() is if you are going to run stand alone. Is this correct? Yes, you're right. There is no need of main() when running in servlet container. However, if you find such methods in code intended to be run inside servlet container, it's only in the purpose of tests. best regards, Thierry Boileau On Thu, Feb 28, 2008 at 5:05 PM, TA [EMAIL PROTECTED] wrote: New to Restlets and have a question. Apologies if it's come up before, I couldn't find it in the archives Do I need to create a Component instance and attach the Application to it if I'm going to run Restlests inside a Servlet container? I looked at the example com.testServlet.TestServletApplication and it wasn't clear to me why there is a main() in there and why a Component is created. The First Steps example didn't have any of that. The way I understand the architecture is that you only need to create a Component and have a main() is if you are going to run stand alone. Is this correct? Thanks for any assistance and would appreciate any guidance or places to look in the archives about best practices for running inside a Servlet container. Ted
Re: If I'm going to run Restlets inside Tomcat or any Servlet container........
You want Component's plumbing for any server code, in a servlet container or not. A default Component will be transparently supplied by the ServerServlet. You'll also want to use the Application as a place to set up the handling of your RESTful requests. Restlet 1.1 (trunk) has handy initialization parameters for specifying a custom Component and Application class to use with your Servlet. I'm not sure whether the custom Component facility existed in 1.0 -- check the Javadoc for the version you're using. The main method is not used when binding the Component to a servlet, but at our shop we typically use the same Component classes both for standalone and servlet container use -- so we have the main() method there for standalone invocation -- in addition to the test use case Thierry gave. On Thu, Feb 28, 2008 at 11:05 AM, TA [EMAIL PROTECTED] wrote: Do I need to create a Component instance and attach the Application to it if I'm going to run Restlests inside a Servlet container?
Re: If I'm going to run Restlets inside Tomcat or any Servlet container........
Thank you both for the info. Rob Heittman rob.heittman at solertium.com writes: You want Component's plumbing for any server code, in a servlet container or not. A default Component will be transparently supplied by the ServerServlet. You'll also want to use the Application as a place to set up the handling of your RESTful requests. Restlet 1.1 (trunk) has handy initialization parameters for specifying a custom Component and Application class to use with your Servlet. I'm not sure whether the custom Component facility existed in 1.0 -- check the Javadoc for the version you're using.The main method is not used when binding the Component to a servlet, but at our shop we typically use the same Component classes both for standalone and servlet container use -- so we have the main() method there for standalone invocation -- in addition to the test use case Thierry gave. On Thu, Feb 28, 2008 at 11:05 AM, TA tedaetc at yahoo.com wrote: Do I need to create a Component instance and attach the Application to it if I'm going to run Restlests inside a Servlet container?
Re: setting the location header
Thierry, Thanks once again. The supplied code snippet worked with a slight modification Reference reference = new Reference(http://localhost/exchange;); reference.setBaseRef(http://localhost;); Request request = new Request(Method.POST, reference); cheers /jima Thierry Boileau wrote: Hi Jim, The application must handle absolute URIs. You can update your code as follow : Reference reference = new Reference(/exchange); reference.setBaseRef(http://localhost;); Request request = new Request(Method.POST, reference); By doing so, the application still handles a reference with a relative part equals to /exchange. best regards, Thierry Boileau On Wed, Feb 27, 2008 at 8:49 PM, Jim Alateras [EMAIL PROTECTED] wrote: Thierry, Just some additional info. I am getting this error in a test case scenario so I may not be priming the 'request' with all the correct info Here is the code that I am using Request request = new Request(Method.POST, /exchange); Response response = application.handle(request); assertTrue(response.getStatus() == Status.SUCCESS_CREATED); assertTrue(response.getLocationRef().getPath() != null); Do i need to do anything extra to the request object before i pass it across to application.handle. cheers /jima Thierry Boileau wrote: Hello Jim, when passing a relative URI, the location reference is resolved against the base reference of the request's resource reference (getRequest().getResourceRef().getBaseRef()). Could you check the values of getRequest().getResourceRef() and getRequest().getResourceRef().getBaseRef()? best regards, Thierry Boileau On Wed, Feb 27, 2008 at 10:42 AM, Jim Alateras [EMAIL PROTECTED] wrote: Hi, I am trying to set the location header after a post to communicate the URL of the created resource. I basically use the following piece of code to set the location passing a relative uri getResponse().setLocationRef(sessionId); but i get the following error java.lang.IllegalArgumentException: Relative references are only usable when a base reference is set. Any ideas? cheers /jima
servlet mapping question
New user and I'm playing around with the firstStepsApplication using it in a tomcat web container. I'm trying to play with the routing. Instead of Router router = new Router(getContext()); router.attachDefault(HelloWorldResource.class); I'm trying to do router.attach(/testServlet,HelloWorldResource.class); and correspondingly, I've changed the entry in web.xml from servlet-mapping servlet-nameRestletServlet/servlet-name url-pattern/*/url-pattern /servlet-mapping to url-pattern/testServlet/*/url-pattern and I can't get it to work, keep getting 404 error. I don't want to default route to the app for all URIs in the url mapping, just ones that start with /testServlet Appreciate any help. Ted
Re: servlet mapping question
Helo TA, try to request /testServlet/testServlet/*, because you give the testServlet double: one times in the web.xml and one times while attaching to the router. I think, you should remove the testServlet from the attach method. best regards Stephan TA schrieb: New user and I'm playing around with the firstStepsApplication using it in a tomcat web container. I'm trying to play with the routing. Instead of Router router = new Router(getContext()); router.attachDefault(HelloWorldResource.class); I'm trying to do router.attach(/testServlet,HelloWorldResource.class); and correspondingly, I've changed the entry in web.xml from servlet-mapping servlet-nameRestletServlet/servlet-name url-pattern/*/url-pattern /servlet-mapping to url-pattern/testServlet/*/url-pattern and I can't get it to work, keep getting 404 error. I don't want to default route to the app for all URIs in the url mapping, just ones that start with /testServlet Appreciate any help. Ted
Re: setting the location header
great! regards, Thierry Boileau On Thu, Feb 28, 2008 at 7:53 PM, Jim Alateras [EMAIL PROTECTED] wrote: Thierry, Thanks once again. The supplied code snippet worked with a slight modification Reference reference = new Reference(http://localhost/exchange;); reference.setBaseRef(http://localhost;); Request request = new Request(Method.POST, reference); cheers /jima Thierry Boileau wrote: Hi Jim, The application must handle absolute URIs. You can update your code as follow : Reference reference = new Reference(/exchange); reference.setBaseRef(http://localhost;); Request request = new Request(Method.POST, reference); By doing so, the application still handles a reference with a relative part equals to /exchange. best regards, Thierry Boileau On Wed, Feb 27, 2008 at 8:49 PM, Jim Alateras [EMAIL PROTECTED] wrote: Thierry, Just some additional info. I am getting this error in a test case scenario so I may not be priming the 'request' with all the correct info Here is the code that I am using Request request = new Request(Method.POST, /exchange); Response response = application.handle(request); assertTrue(response.getStatus() == Status.SUCCESS_CREATED); assertTrue(response.getLocationRef().getPath() != null); Do i need to do anything extra to the request object before i pass it across to application.handle. cheers /jima Thierry Boileau wrote: Hello Jim, when passing a relative URI, the location reference is resolved against the base reference of the request's resource reference (getRequest().getResourceRef().getBaseRef()). Could you check the values of getRequest().getResourceRef() and getRequest().getResourceRef().getBaseRef()? best regards, Thierry Boileau On Wed, Feb 27, 2008 at 10:42 AM, Jim Alateras [EMAIL PROTECTED] wrote: Hi, I am trying to set the location header after a post to communicate the URL of the created resource. I basically use the following piece of code to set the location passing a relative uri getResponse().setLocationRef(sessionId); but i get the following error java.lang.IllegalArgumentException: Relative references are only usable when a base reference is set. Any ideas? cheers /jima
Re:re servlet mapping question
Hi Stephan, Thanks for the reply. I tried it with /testServlet/testServlet/ and that did not work. I'm not sure I follow your suggestion - if I remove the url mapping from the defaultAttach call, all URLs will map to the servlet/restlet and I don't want that because I have other servlets running the web container. Ted
Re: re servlet mapping question
Hi Ted, On Feb 28, 2008, at 5:11 PM, TA wrote: I'm not sure I follow your suggestion - if I remove the url mapping from the defaultAttach call, all URLs will map to the servlet/restlet and I don't want that because I have other servlets running the web container. What Stephan was pointing out is that that _won't_ happen because the container will continue to route requests to the other servlets -- even if your restlet servlet wanted to handle the other requests, it won't ever see them. I'm not sure, but if I had to guess I'd suggest that your problem is that your servlet was mapped to /testServlet/* and you were trying to request /testServlet. The containers I've used (okay, just Tomcat) are very literal minded. Try requesting /testServlet/ or /testServlet/ somethingElse. Rhett
First steps with Restlets in Equinox OSGi
Hi, the Restlet jars are nicely bundled as bundles ;-) but I could not find a way to run the first steps example without deploying a webapp. I'm looking for a pure OSGi+servlets, no webapp, solution. Equinox provides an extension point where I can register the ServerServlet. But Equinox does not have an extension point for an application. What do I do with the FirstStepsApplication so that the initialization code gets executed? Frank.
Ran into difficulty getting servlet connector working.
Hello, I have been writing an application using the Restlet API (and a very pleasant API I might add) and ran into a problem. Initially I was using the 1.0 release and everything was working fine. Eventually I found myself in the situation where I needed to either parse the request body into a DOM multiple times. Once at the Filter level to initially determine if authentication were required and again at a the specific Resource level. Or parse the request body into a DOM once in the Filter and store the DOM as part of the request attributes. Multiple parsing of the DOM did not work in 1.0 for me, and there wasn't a facility to set request attributes, so I upgraded to 1.1. I am still investigating this on my own and just thought I would see if someone else had run into this problem and already had an answer to it. When I try and use my 1.1 Restlet with Tomcat, I am getting the following stack trace: SEVERE: Allocate exception for servlet IDS java.lang.NullPointerException at java.util.concurrent.CopyOnWriteArrayList.init( CopyOnWriteArrayList.java:91) at org.restlet.Connector.init(Connector.java:69) at org.restlet.Client.init(Client.java:49) at com.noelios.restlet.ext.servlet.ServletWarClient.init( ServletWarClient.java:52) at com.noelios.restlet.ext.servlet.ServerServlet.createApplication( ServerServlet.java:215) at com.noelios.restlet.ext.servlet.ServerServlet.getApplication( ServerServlet.java:313) at com.noelios.restlet.ext.servlet.ServerServlet.init( ServerServlet.java:418) at javax.servlet.GenericServlet.init(GenericServlet.java:211) at org.apache.catalina.core.StandardWrapper.loadServlet( StandardWrapper.java:1105) at org.apache.catalina.core.StandardWrapper.allocate( StandardWrapper.java:757) at org.apache.catalina.core.StandardWrapperValve.invoke( StandardWrapperValve.java:130) at org.apache.catalina.core.StandardContextValve.invoke( StandardContextValve.java:178) at org.apache.catalina.core.StandardHostValve.invoke( StandardHostValve.java:126) at org.apache.catalina.valves.ErrorReportValve.invoke( ErrorReportValve.java:105) at org.apache.catalina.core.StandardEngineValve.invoke( StandardEngineValve.java:107) at org.apache.catalina.connector.CoyoteAdapter.service( CoyoteAdapter.java:148) at org.apache.coyote.http11.Http11Processor.process( Http11Processor.java:869) at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection (Http11BaseProtocol.java:664) at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket( PoolTcpEndpoint.java:527) at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt( LeaderFollowerWorkerThread.java:80) at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run( ThreadPool.java:684) at java.lang.Thread.run(Thread.java:619) I was running Tomcat 5.5.20 with JDK 1.6.0. I also tried and encountered the same problem using a Tomcat 6 version. I tried having the Restlet get connected using both the Component and Application classes. -Eben
riap: isConfidential()?
Interesting question came up in one of our implementations today. We check isConfidential() in a Filter and redirect people to https in certain circumstances where the response should not be transmitted in the clear. Some requests are transported over the riap: pseudoprotocol. It seems to me isConfidential() should return true for riap: requests, since the internal requests are not transmitted in the clear. Thoughts? - R
Re: Ran into difficulty getting servlet connector working.
I believe this was a bug in ServerServlet in the 1.1M1 snapshot that has since been corrected. I usually work out of trunk and it doesn't affect me any more. This thread describes it and has a patch: http://www.mail-archive.com/discuss@restlet.tigris.org/msg03451.html There should be a new milestone snapshot imminently. I am still investigating this on my own and just thought I would see if someone else had run into this problem and already had an answer to it.
Re: Restlet and Velocity template location.
Thanks Vincent,that's pretty way for restlet-1.1snapshot.I used this way in restlet or resource: TemplateRepresentation templateRepr= new TemplateRepresentation( /people.vm, MediaType.TEXT_HTML); ... templateRepr.setDataModel(dataModel); templateRepr.getEngine().setProperty( VelocityEngine.FILE_RESOURCE_LOADER_PATH, E:/eclipse3.1RC3/workspace/RestletPractice/templates ); response.setEntity(templateRepr); I have a lot of problem about it: 1.How to use the relative path to set file resource loader path property of velocity engine?It must to fullfill all of path? 2.How to set once when a Velocitytemplate is initialized,without set again when you use this template? On Thu, Feb 28, 2008 at 5:03 AM, Vincent [EMAIL PROTECTED] wrote: Stuart, I'm trying to use the TemplateRepresentation for the Velocity extension as part of a webapp, but I am having problems configuring the template location. Have you tried this: org.restlet.ext.velocity.TemplateRepresentation r = new org.restlet.ext.velocity.TemplateRepresentation(...); r.getEngine().setProperty(VelocityEngine.FILE_RESOURCE_LOADER_PATH, /path/to/resources); -vincent. -- cleverpig Location: Beijing Address: Room 4018,No.A2 South Avenue Fuxingmen Beijing,P.R.China Zipcode: 100031 Phone: 010-66415588-1113 MSN: [EMAIL PROTECTED] QQ: 149291732 Skepe: cleverpigatmatrix My Facebook ID:cleverpig My Blog: hihere.sohu.com My Tags: del.icio.us/cleverpig My Twitter: twitter.com/cleverpig My Organization: www.beijing-open-party.org 一些值得关注的唧歪: http://jiwai.de/t/jmatrix/ http://jiwai.de/t/db4o/ http://jiwai.de/t/matrix-community/