2

I am new to Restlets. Trying to configure the web.xml (on JBoss). I have 2 entries, one for a servlet (got nothing to do with webservices) other for webservices, using Restlet. Here are the entries..

 <servlet>
  <servlet-name>AuthenticationServlet</servlet-name>
  <servlet-class>com.safeid.web.server.api.servlet.AuthenticationServlet</servlet-class>
  <load-on-startup>2</load-on-startup>
 </servlet>

 <servlet-mapping>
  <servlet-name>AuthenticationServlet</servlet-name>
  <url-pattern>/authenticate/*</url-pattern>
 </servlet-mapping>


<!--  Start of Entries for the REST Web Services. -->

  <context-param>
   <param-name>org.restlet.application</param-name>
   <param-value>com.safeid.web.server.SafeIDRouterApplication</param-value>
  </context-param>

 <servlet>
  <servlet-name>RestletServlet</servlet-name>
  <servlet-class>com.noelios.restlet.ext.servlet.ServerServlet</servlet-class>
  <load-on-startup>1</load-on-startup>
 </servlet>


 <servlet-mapping>
  <servlet-name>RestletServlet</servlet-name>
  <url-pattern>/*</url-pattern>
 </servlet-mapping>
<!-- END of Entries for the REST Web Services.-->

Both don't work together. In the above setup the Restlet works. However when I change the

RestletServlet /*

to something like

<servlet-mapping>
  <servlet-name>RestletServlet</servlet-name>
  <url-pattern>/credential/*</url-pattern>
 </servlet-mapping>

the Restlet stop working and the AuthenticationServlet works fine. What am I missing here?

2
  • 1
    The last mapping should work. What do you mean with "the restlet stop working"? What exactly happens? Did you invoke the right URL's and were the resources at the right locations? Please elaborate in developer's perspective, not in enduser's perspective. Commented Jun 15, 2010 at 13:04
  • By not working, I mean it's a 404 error. Commented Jun 15, 2010 at 16:13

2 Answers 2

3

I had a similar frustration. Perhaps what I found out may help.

I had Router entries in my Application class like this:

router.attach("/users", UsersResource.class);

And things worked fine when my servlet mapping was like this:

<servlet-mapping>
    <servlet-name>Sandbox</servlet-name>
    <url-pattern>/*</url-pattern>
</servlet-mapping>

When I changed it to something like this:

<servlet-mapping>
    <servlet-name>Sandbox</servlet-name>
    <url-pattern>/users/*</url-pattern>
</servlet-mapping>

it stopped working.

The problem is that the servlet container "consumes" or removes the part of the URL that it matched. In this case, it removes "/users". So if you were using a url like this:

http://www.mywebsite.com/users

you would have to change it to be:

http://www.mywebsite.com/users/users

Of course, you can make the url-pattern be whatever you want:

<servlet-mapping>
    <servlet-name>Sandbox</servlet-name>
    <url-pattern>/rest/*</url-pattern>
</servlet-mapping>

and then you'd access it like this:

http://www.mywebsite.com/rest/users

The url-pattern gets stripped off, and you get whatever is leftover in your Application class for your own routing purposes.

HTH

Sign up to request clarification or add additional context in comments.

Comments

1

Looks like you're missing the init-params as in the example below.

<servlet>
    <servlet-name>MyApplication</servlet-name> 
    <servlet-class>org.restlet.ext.servlet.ServerServlet</servlet-class>
    <init-param>
        <param-name>org.restlet.application</param-name>
        <param-value>my.class.that.extends.Application.MyApplication</param-value>
    </init-param> 
</servlet>

You need a class that extends org.restlet.Application (at least in Restlet 2.0 anyway).

1 Comment

Oh.. I do have it. The above snippet of the web.xml is the one that is relevant to the problem I am facing. I am now thinking of separating the webservice from rest of the servlet/war code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.