1

I am using Jboss RestEasy web services, and I need to multiple url to map to that web service. Is there any possibility that I can set multiple prefixes for 'resteasy.servlet.mapping.prefixconfigured

here is my configuration in web.xml

 <servlet-name>REST Service</servlet-name>
      <servlet-class>org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher</servletclass>
      </servlet>

      <servlet-mapping>
        <servlet-name>REST Service</servlet-name>
        <url-pattern>/rest/*</url-pattern>
      </servlet-mapping>

      <servlet-mapping>
        <servlet-name>REST Service</servlet-name>
        <url-pattern>/service/*</url-pattern>
      </servlet-mapping> 

      <context-param>
        <param-name>resteasy.servlet.mapping.prefix</param-name>
        <param-value>/rest</param-value>
      </context-param>

I want service for both "/rest" and "/service" prefixes

Cloud Newbie
  • 61
  • 1
  • 6

2 Answers2

5

For a quick test, I changed your <context-param> into <init-param> inside <servlet> and in RESTeasy 3.0.5 it worked for me.

So a workaround might be to define two servlets with the same configuration and differing only on resteasy.servlet.mapping.prefix value of <init-param>'s, and define two mappings for them.

Beware that now you have two servlets that live their own lives (e.g. separate contexts and lifecycles), which might be unacceptable in some scenarios.

UPDATE: Also take a look at this answer, similar to mine although more elaborated (I haven't tried it myself): https://stackoverflow.com/a/25487574/283519

Community
  • 1
  • 1
pwes
  • 2,040
  • 21
  • 30
1

@pwes Thanks a lot! I was looking to expose two RESTful services. Say /api1 and /api2 . Your suggestion works for both what the OP wants and what I wanted too.

Here's how each servelet is configured:

<servlet>
    <servlet-name>entity-manager</servlet-name>
    <servlet-class>
        org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher
    </servlet-class>
    <init-param>
        <param-name>resteasy.servlet.mapping.prefix</param-name>
        <param-value>/api1</param-value>
    </init-param>
</servlet>

Second one:

<servlet>
    <servlet-name>entity-manager</servlet-name>
    <servlet-class>
        org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher
    </servlet-class>
    <init-param>
        <param-name>resteasy.servlet.mapping.prefix</param-name>
        <param-value>/api2</param-value>
    </init-param>
</servlet>
HellRa
  • 21
  • 3
  • Please don't add "thank you" as an answer. Once you have sufficient [reputation](http://stackoverflow.com/help/whats-reputation), you will be able to [vote up questions and answers](http://stackoverflow.com/help/privileges/vote-up) that you found helpful. – Matthew Green Apr 21 '14 at 14:04
  • @MatthewGreen - What you're correct with your comment's content, I feel this answer could actually add some value. Sometimes it's very handy to have an example of exactly how to use some code. – Mike Apr 21 '14 at 16:23
  • My intention is not only to thank you. But if someone else gets stuck configuring multiple REST APIs like me, I thought this answer would help. Since "multiple services RESTEasy" has this in the top 5 results. – HellRa Apr 22 '14 at 17:28