开发者

Configuring web.xml for webservices and servlet

开发者 https://www.devze.com 2023-01-03 23:34 出处:网络
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..

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>

th开发者_如何学Pythone Restlet stop working and the AuthenticationServlet works fine. What am I missing here?


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


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).

0

精彩评论

暂无评论...
验证码 换一张
取 消