You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@wink.apache.org by Bryant Luk <br...@gmail.com> on 2009/07/02 01:09:00 UTC

Multiple RestServlets in single web application?

Hi,

Does the RestServlet support multiple servlet instances in the same
web application?

It seems that only the first servlet (in alphabetical order) is fired
up correctly.  If I have two instances of the servlet, say
MessageBodyWriterExceptions and MessageBodyReaderExceptions, only
MessageBodyReaderExceptions seems to work.  If I then rename
MessageBodyReaderExceptions to "Z" (or comment out the servlet
definition), then my MessageBodyWriterExceptions servlet JAX-RS app
works.

My web.xml:

<web-app>
    <display-name>Archetype Created Web Application</display-name>
    <servlet>
        <servlet-name>MessageBodyWriterExceptions</servlet-name>
        <servlet-class>org.apache.wink.server.internal.servlet.RestServlet</servlet-class>
        <init-param>
            <param-name>javax.ws.rs.Application</param-name>
            <param-value>org.apache.wink.jaxrs.test.providers.writerexceptions.Application</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet>
        <servlet-name>MessageBodyReaderExceptions</servlet-name>
        <servlet-class>org.apache.wink.server.internal.servlet.RestServlet</servlet-class>
        <init-param>
            <param-name>javax.ws.rs.Application</param-name>
            <param-value>org.apache.wink.jaxrs.test.providers.readerexceptions.Application</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>MessageBodyWriterExceptions</servlet-name>
        <url-pattern>/writerexceptions/*</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>MessageBodyReaderExceptions</servlet-name>
        <url-pattern>/readerexceptions/*</url-pattern>
    </servlet-mapping>
</web-app>

-- 

- Bryant Luk

RE: Multiple RestServlets in single web application?

Posted by "Baram, Eliezer" <eb...@hp.com>.
Hi
Let's remember that when we have one RestServlet in a war no attribute configuration should be configured.

Usually there is no reason to register more then one RestServlet in a single war, one engine can handle many resources and even many applications.
In the example below, I would recommend to register the all resources and providers in a single application or to register both application in single engine.

Regarding the concern  Bryant mention about having the Wink libraries in the application servers shared libs, I do not see the problem there since each requestProcessor is saved on a different srevletContext.

We could have generate a random  attribute name and use it but this would cause problem. In the Spring  for instance the RequestProcessor is been initiate by the spring framework and is been set on the ServletContext  by a listener. In such situation the attribute name need to be synchronized between the listener who put the requestProcessor on the ServletContext and the RestServlet who try to get it from there.

Something that we can improve however is to be able to register multiple application classes from the web.xml.  Today if  you want to register several applications you need either to use the SimpleApplication to load resources/providers from several files, or to register the additional applications from java code. We should enabling specifying the application classes in the web.xml, mybe with a semicolon  between the different classes.

Regarding Nick question, I do not see a reason why 2 servlets would not be able to work with the same engine, though we did not try it. in such case only the first servelt will init the requestProcessor. I believe that what happened in Bryant test.

--Eli






From: Nicholas L Gallardo [mailto:nlgallar@us.ibm.com]
Sent: Thursday, July 02, 2009 5:03 PM
To: wink-dev@incubator.apache.org
Subject: Re: Multiple RestServlets in single web application?


+1 to auto populating a new parameter and enabling it by default.

Question, does the runtime work when two servlets share the same request processor? My impression from Bryant's note was no, but Eli seemed to indicate that they did. Or, is it that only one servlet needs to be fired because the config that existed for both applications is now smashed together?

Looking at how the servlets are defined in Bryant's example, it seems more intuitive to have the configs separated out on a per servlet basis. If I want them together, then I can just add the resources/providers to a single Application class and be done with it.

-Nick



Nicholas Gallardo
WebSphere - REST & WebServices Development
nlgallar@us.ibm.com
Phone: 512-286-6258
Building: 903 / 5G-016
[cid:1__=08BBFF74DFDF34918f9e8a93df938@us.ibm.com]Bryant Luk <br...@gmail.com>

Bryant Luk <br...@gmail.com>

07/02/2009 08:51 AM
Please respond to
wink-dev@incubator.apache.org



To


wink-dev@incubator.apache.org


cc




Subject


Re: Multiple RestServlets in single web application?








Hi Eli,

Just curious why we need the application developer to add that
parameter.  Is there any way that we can autogenerate that parameter
within the runtime?  The reasons why I think we should autogenerate:

1)  Application portability.  If other implementations take their
JAX-RS application and switch to Wink (or start with Wink), the first
impression may be that we don't work out of the box.
2)  I haven't tested this but if we use Wink as a shared library
across a container's applications (such as Geronimo/WebSphere), I
think this would cause some administration headaches since every
parameter value (I'm assuming) has to be unique.  Some application
developers might not communicate their unique attribute names, and
this would be a really hard thing to find out when an application
doesn't work correctly.

I think we can have it as an optional attribute if you want to use the
same RequestProcessor across two servlet instances, just that by
default, we generate a unique one per servlet instance.

Thoughts?

On Thu, Jul 2, 2009 at 3:34 AM, Baram, Eliezer<eb...@hp.com> wrote:
> Hi Bryant
> The RestServlet stores the requestProcessor on the servletContext, by default it saves it under an attribute named RequestProcessor.class.getName()
>
> If you register more then one servlet and you want each to have a separate RequestProcessor you need to indicate the RestServlet to save the RequestProcessor under a different attribute.
>
> You can specify the attribute name by setting the "symphony.requestProcessorAttribute" init parameter of the RestServlet.
> See modification below.
>
> --Eli
>
>
>
> -----Original Message-----
> From: Bryant Luk [mailto:bryant.luk@gmail.com]
> Sent: Thursday, July 02, 2009 2:09 AM
> To: wink-dev@incubator.apache.org
> Subject: Multiple RestServlets in single web application?
>
> Hi,
>
> Does the RestServlet support multiple servlet instances in the same
> web application?
>
> It seems that only the first servlet (in alphabetical order) is fired
> up correctly.  If I have two instances of the servlet, say
> MessageBodyWriterExceptions and MessageBodyReaderExceptions, only
> MessageBodyReaderExceptions seems to work.  If I then rename
> MessageBodyReaderExceptions to "Z" (or comment out the servlet
> definition), then my MessageBodyWriterExceptions servlet JAX-RS app
> works.
>
> My web.xml:
>
> <web-app>
>    <display-name>Archetype Created Web Application</display-name>
>    <servlet>
>        <servlet-name>MessageBodyWriterExceptions</servlet-name>
>        <servlet-class>org.apache.wink.server.internal.servlet.RestServlet</servlet-class>
>        <init-param>
>            <param-name>javax.ws.rs.Application</param-name>
>            <param-value>org.apache.wink.jaxrs.test.providers.writerexceptions.Application</param-value>
>        </init-param>
>        <load-on-startup>1</load-on-startup>
>    </servlet>
>    <servlet>
>        <servlet-name>MessageBodyReaderExceptions</servlet-name>
>        <servlet-class>org.apache.wink.server.internal.servlet.RestServlet</servlet-class>
>        <init-param>
>            <param-name>javax.ws.rs.Application</param-name>
>            <param-value>org.apache.wink.jaxrs.test.providers.readerexceptions.Application</param-value>
>        </init-param>
> [E.B] <init-param>
>            <param-name>symphony.requestProcessorAttribute</param-name>
>            <param-value>requestProcessorAttribute_2</param-value>
>        </init-param>
>        <load-on-startup>1</load-on-startup>
>    </servlet>
>    <servlet-mapping>
>        <servlet-name>MessageBodyWriterExceptions</servlet-name>
>        <url-pattern>/writerexceptions/*</url-pattern>
>    </servlet-mapping>
>    <servlet-mapping>
>        <servlet-name>MessageBodyReaderExceptions</servlet-name>
>        <url-pattern>/readerexceptions/*</url-pattern>
>    </servlet-mapping>
> </web-app>
>
> --
>
> - Bryant Luk
>



--

- Bryant Luk

Re: Multiple RestServlets in single web application?

Posted by Bryant Luk <br...@gmail.com>.
On Sun, Jul 5, 2009 at 2:35 AM, Michael Elman<ta...@gmail.com> wrote:
> We don't have support for multiple applications yet. We discussed it as a
> "nice to have" feature and didn't dive into the details yet.
> I think the main idea was to be able to load multiple applications, but  to
> try resolving paths conflicts.
> Anyway it's just an idea, we can continue discussing it, but anyway I don't
> think we'll want it for 0.1

Right, not something for 0.1, and right now I prefer that the
developer should just combine everything into a single Application
class.

> If I understand your use-case correctly, you can use the Wink with multiple
> servlets using the symphony.requestProcessorAttribute parameter. I think
> using this parameter for testing is ok and we don't need to develop anything
> to generate it. The servlet-mapping will resolve possible paths conflicts.

Right, the parameter works,  I was just hoping that we might invert
the default behavior if possible (i.e. if you wanted to use the
AdminServlet, you would have to specify the requestProcessorAttribute
for both RestServlet and AdminServlet) since people migrating over
would have multiple RestServlets rather than any of the Wink specific
features (obviously).

Just throwing a use case pattern out here, some developers may develop
a single WAR that had a context root of something like "/restapi/" and
then have one JAX-RS Application with a servlet mapping of "/v1" and
then another JAX-RS Application with a servlet mapping of "/v2" for
versions 1 and 2 of their API respectively.  The motivation is that
they could re-use their existing resource classes where the code
doesn't need to be changed between Applications (since the @Path
wouldn't allow 2 different "/v1/Item" and "/v2/Item").

I don't consider this a good (nor bad) practice but something that I
was thinking about.  I think using subresource locators as an
alternate means to achieve the above becomes somewhat more difficult
if you ever wanted to use anything beyond method injection.

In the end we need to document this somewhere (I couldn't find it in
the original PDF but it's probably in the site documentation) and if
users start complaining, we can re-investigate the options.

> What do you think?

Also, I think if it became an issue, we could always have the
container integration layers use their own RestServlet and then they
would have the luxury of generating their own unique attribute.  I
would prefer it if we could have things work out of the box for the
vast majority of use cases obviously so integration layers don't have
to do too many special things.

Maybe thinking too far ahead, but there would have to be customized
RestServlet behavior for EE 6 container aware integration layers
anyway so it's better for them to go ahead and either extend off the
internal one or to create their own.

> On Thu, Jul 2, 2009 at 11:22 PM, Bryant Luk <br...@gmail.com> wrote:
>
>> Thanks, I think I understand the reasoning and the implementation
>> better between Eli and your messages.  Let me think about this for a
>> bit.
>>
>> For the basic improvement that Eli suggested where multiple JAX-RS
>> Applications are allowed via a ; or something else, is the assumption
>> that you could find a common url pattern and make the @Path values be
>> "right"?  For instance, if I had a bookstore application and a
>> shoestore application with (context root)/bookstore/item1 and (context
>> root)/shoestore/item1 as two intended URLs, you would have the URL
>> pattern be /* and all bookstore resources pre-pended with
>> @Path("/bookstore/{item}") and shoestore resources pre-pended with
>> @Path("/shoestore/{item}") (and also hope that there aren't
>> "undefined" scenarios where 2 paths are unknowingly exactly the same)?
>>  An unlikely example but just making sure I understand the suggestion
>> and the implications.
>>
>> In any case, yes, I would hope the normal situation would be only one
>> RestServlet per war.  I was trying to isolate some of the JAX-RS
>> Applications because I don't want some of the @Providers to cross
>> Applications.  Originally the tests were written in numerous small
>> applications but in order to limit the number of Maven submodules, I
>> wanted to combine the applications together without the @Providers
>> crossing over.
>>
>> As far as the shared library point, I think both Eli and Michael have
>> answered my question.
>>
>> On Thu, Jul 2, 2009 at 12:56 PM, Michael Elman<ta...@gmail.com> wrote:
>> > Hi Bryant ,
>> >
>> > this parameter is used in order to provide an additional functionality,
>> like
>> > Administration Servlet and a runtime registration.
>> > The reason is simple: we want be able to access the RequestProcessor
>> > instance from sources that are different that the RestServlet: other
>> > servlets, JMX, spring beans and so on.
>> > Of cause if this functionality is not required, we can use an
>> autogenerated
>> > value.
>>
>>
>>
>> >
>> >
>> > On Thu, Jul 2, 2009 at 4:51 PM, Bryant Luk <br...@gmail.com> wrote:
>> >
>> >> Hi Eli,
>> >>
>> >> Just curious why we need the application developer to add that
>> >> parameter.  Is there any way that we can autogenerate that parameter
>> >> within the runtime?  The reasons why I think we should autogenerate:
>> >>
>> >> 1)  Application portability.  If other implementations take their
>> >> JAX-RS application and switch to Wink (or start with Wink), the first
>> >> impression may be that we don't work out of the box.
>> >
>> >
>> > The parameter is needed only if there are multiple RestServlet instances
>> > within the same war. I believe that a normal situation is to have a
>> single
>> > RestServlet per war. If this is the case, such a parameter is not needed.
>> So
>> > it won't work out of the box only in a complex cases.
>> >
>> >
>> >>
>> >> 2)  I haven't tested this but if we use Wink as a shared library
>> >> across a container's applications (such as Geronimo/WebSphere), I
>> >> think this would cause some administration headaches since every
>> >> parameter value (I'm assuming) has to be unique.  Some application
>> >> developers might not communicate their unique attribute names, and
>> >> this would be a really hard thing to find out when an application
>> >> doesn't work correctly.
>> >>
>> >
>> > What do you mean by using Wink as a shared library? If you mean sharing
>> it
>> > between wars (putting it in a parent classloader), it won't cause any
>> > problems, since the parameter should be unique per ServletConfig, meaning
>> it
>> > should be unique in the same war, but different wars can use the same
>> name.
>> >
>> >
>> >>
>> >> I think we can have it as an optional attribute if you want to use the
>> >> same RequestProcessor across two servlet instances, just that by
>> >> default, we generate a unique one per servlet instance.
>> >>
>> >> Thoughts?
>> >>
>> >> On Thu, Jul 2, 2009 at 3:34 AM, Baram, Eliezer<eb...@hp.com> wrote:
>> >> > Hi Bryant
>> >> > The RestServlet stores the requestProcessor on the servletContext, by
>> >> default it saves it under an attribute named
>> >> RequestProcessor.class.getName()
>> >> >
>> >> > If you register more then one servlet and you want each to have a
>> >> separate RequestProcessor you need to indicate the RestServlet to save
>> the
>> >> RequestProcessor under a different attribute.
>> >> >
>> >> > You can specify the attribute name by setting the
>> >> "symphony.requestProcessorAttribute" init parameter of the RestServlet.
>> >> > See modification below.
>> >> >
>> >> > --Eli
>> >> >
>> >> >
>> >> >
>> >> > -----Original Message-----
>> >> > From: Bryant Luk [mailto:bryant.luk@gmail.com]
>> >> > Sent: Thursday, July 02, 2009 2:09 AM
>> >> > To: wink-dev@incubator.apache.org
>> >> > Subject: Multiple RestServlets in single web application?
>> >> >
>> >> > Hi,
>> >> >
>> >> > Does the RestServlet support multiple servlet instances in the same
>> >> > web application?
>> >> >
>> >> > It seems that only the first servlet (in alphabetical order) is fired
>> >> > up correctly.  If I have two instances of the servlet, say
>> >> > MessageBodyWriterExceptions and MessageBodyReaderExceptions, only
>> >> > MessageBodyReaderExceptions seems to work.  If I then rename
>> >> > MessageBodyReaderExceptions to "Z" (or comment out the servlet
>> >> > definition), then my MessageBodyWriterExceptions servlet JAX-RS app
>> >> > works.
>> >> >
>> >> > My web.xml:
>> >> >
>> >> > <web-app>
>> >> >    <display-name>Archetype Created Web Application</display-name>
>> >> >    <servlet>
>> >> >        <servlet-name>MessageBodyWriterExceptions</servlet-name>
>> >> >
>> >>
>>  <servlet-class>org.apache.wink.server.internal.servlet.RestServlet</servlet-class>
>> >> >        <init-param>
>> >> >            <param-name>javax.ws.rs.Application</param-name>
>> >> >
>> >>
>>  <param-value>org.apache.wink.jaxrs.test.providers.writerexceptions.Application</param-value>
>> >> >        </init-param>
>> >> >        <load-on-startup>1</load-on-startup>
>> >> >    </servlet>
>> >> >    <servlet>
>> >> >        <servlet-name>MessageBodyReaderExceptions</servlet-name>
>> >> >
>> >>
>>  <servlet-class>org.apache.wink.server.internal.servlet.RestServlet</servlet-class>
>> >> >        <init-param>
>> >> >            <param-name>javax.ws.rs.Application</param-name>
>> >> >
>> >>
>>  <param-value>org.apache.wink.jaxrs.test.providers.readerexceptions.Application</param-value>
>> >> >        </init-param>
>> >> > [E.B] <init-param>
>> >> >            <param-name>symphony.requestProcessorAttribute</param-name>
>> >> >            <param-value>requestProcessorAttribute_2</param-value>
>> >> >        </init-param>
>> >> >        <load-on-startup>1</load-on-startup>
>> >> >    </servlet>
>> >> >    <servlet-mapping>
>> >> >        <servlet-name>MessageBodyWriterExceptions</servlet-name>
>> >> >        <url-pattern>/writerexceptions/*</url-pattern>
>> >> >    </servlet-mapping>
>> >> >    <servlet-mapping>
>> >> >        <servlet-name>MessageBodyReaderExceptions</servlet-name>
>> >> >        <url-pattern>/readerexceptions/*</url-pattern>
>> >> >    </servlet-mapping>
>> >> > </web-app>
>> >> >
>> >> > --
>> >> >
>> >> > - Bryant Luk
>> >> >
>> >>
>> >>
>> >>
>> >> --
>> >>
>> >> - Bryant Luk
>> >>
>> >
>>
>>
>>
>> --
>>
>> - Bryant Luk
>>
>



-- 

- Bryant Luk

Re: Multiple RestServlets in single web application?

Posted by Michael Elman <ta...@gmail.com>.
We don't have support for multiple applications yet. We discussed it as a
"nice to have" feature and didn't dive into the details yet.
I think the main idea was to be able to load multiple applications, but  to
try resolving paths conflicts.
Anyway it's just an idea, we can continue discussing it, but anyway I don't
think we'll want it for 0.1

If I understand your use-case correctly, you can use the Wink with multiple
servlets using the symphony.requestProcessorAttribute parameter. I think
using this parameter for testing is ok and we don't need to develop anything
to generate it. The servlet-mapping will resolve possible paths conflicts.

What do you think?


On Thu, Jul 2, 2009 at 11:22 PM, Bryant Luk <br...@gmail.com> wrote:

> Thanks, I think I understand the reasoning and the implementation
> better between Eli and your messages.  Let me think about this for a
> bit.
>
> For the basic improvement that Eli suggested where multiple JAX-RS
> Applications are allowed via a ; or something else, is the assumption
> that you could find a common url pattern and make the @Path values be
> "right"?  For instance, if I had a bookstore application and a
> shoestore application with (context root)/bookstore/item1 and (context
> root)/shoestore/item1 as two intended URLs, you would have the URL
> pattern be /* and all bookstore resources pre-pended with
> @Path("/bookstore/{item}") and shoestore resources pre-pended with
> @Path("/shoestore/{item}") (and also hope that there aren't
> "undefined" scenarios where 2 paths are unknowingly exactly the same)?
>  An unlikely example but just making sure I understand the suggestion
> and the implications.
>
> In any case, yes, I would hope the normal situation would be only one
> RestServlet per war.  I was trying to isolate some of the JAX-RS
> Applications because I don't want some of the @Providers to cross
> Applications.  Originally the tests were written in numerous small
> applications but in order to limit the number of Maven submodules, I
> wanted to combine the applications together without the @Providers
> crossing over.
>
> As far as the shared library point, I think both Eli and Michael have
> answered my question.
>
> On Thu, Jul 2, 2009 at 12:56 PM, Michael Elman<ta...@gmail.com> wrote:
> > Hi Bryant ,
> >
> > this parameter is used in order to provide an additional functionality,
> like
> > Administration Servlet and a runtime registration.
> > The reason is simple: we want be able to access the RequestProcessor
> > instance from sources that are different that the RestServlet: other
> > servlets, JMX, spring beans and so on.
> > Of cause if this functionality is not required, we can use an
> autogenerated
> > value.
>
>
>
> >
> >
> > On Thu, Jul 2, 2009 at 4:51 PM, Bryant Luk <br...@gmail.com> wrote:
> >
> >> Hi Eli,
> >>
> >> Just curious why we need the application developer to add that
> >> parameter.  Is there any way that we can autogenerate that parameter
> >> within the runtime?  The reasons why I think we should autogenerate:
> >>
> >> 1)  Application portability.  If other implementations take their
> >> JAX-RS application and switch to Wink (or start with Wink), the first
> >> impression may be that we don't work out of the box.
> >
> >
> > The parameter is needed only if there are multiple RestServlet instances
> > within the same war. I believe that a normal situation is to have a
> single
> > RestServlet per war. If this is the case, such a parameter is not needed.
> So
> > it won't work out of the box only in a complex cases.
> >
> >
> >>
> >> 2)  I haven't tested this but if we use Wink as a shared library
> >> across a container's applications (such as Geronimo/WebSphere), I
> >> think this would cause some administration headaches since every
> >> parameter value (I'm assuming) has to be unique.  Some application
> >> developers might not communicate their unique attribute names, and
> >> this would be a really hard thing to find out when an application
> >> doesn't work correctly.
> >>
> >
> > What do you mean by using Wink as a shared library? If you mean sharing
> it
> > between wars (putting it in a parent classloader), it won't cause any
> > problems, since the parameter should be unique per ServletConfig, meaning
> it
> > should be unique in the same war, but different wars can use the same
> name.
> >
> >
> >>
> >> I think we can have it as an optional attribute if you want to use the
> >> same RequestProcessor across two servlet instances, just that by
> >> default, we generate a unique one per servlet instance.
> >>
> >> Thoughts?
> >>
> >> On Thu, Jul 2, 2009 at 3:34 AM, Baram, Eliezer<eb...@hp.com> wrote:
> >> > Hi Bryant
> >> > The RestServlet stores the requestProcessor on the servletContext, by
> >> default it saves it under an attribute named
> >> RequestProcessor.class.getName()
> >> >
> >> > If you register more then one servlet and you want each to have a
> >> separate RequestProcessor you need to indicate the RestServlet to save
> the
> >> RequestProcessor under a different attribute.
> >> >
> >> > You can specify the attribute name by setting the
> >> "symphony.requestProcessorAttribute" init parameter of the RestServlet.
> >> > See modification below.
> >> >
> >> > --Eli
> >> >
> >> >
> >> >
> >> > -----Original Message-----
> >> > From: Bryant Luk [mailto:bryant.luk@gmail.com]
> >> > Sent: Thursday, July 02, 2009 2:09 AM
> >> > To: wink-dev@incubator.apache.org
> >> > Subject: Multiple RestServlets in single web application?
> >> >
> >> > Hi,
> >> >
> >> > Does the RestServlet support multiple servlet instances in the same
> >> > web application?
> >> >
> >> > It seems that only the first servlet (in alphabetical order) is fired
> >> > up correctly.  If I have two instances of the servlet, say
> >> > MessageBodyWriterExceptions and MessageBodyReaderExceptions, only
> >> > MessageBodyReaderExceptions seems to work.  If I then rename
> >> > MessageBodyReaderExceptions to "Z" (or comment out the servlet
> >> > definition), then my MessageBodyWriterExceptions servlet JAX-RS app
> >> > works.
> >> >
> >> > My web.xml:
> >> >
> >> > <web-app>
> >> >    <display-name>Archetype Created Web Application</display-name>
> >> >    <servlet>
> >> >        <servlet-name>MessageBodyWriterExceptions</servlet-name>
> >> >
> >>
>  <servlet-class>org.apache.wink.server.internal.servlet.RestServlet</servlet-class>
> >> >        <init-param>
> >> >            <param-name>javax.ws.rs.Application</param-name>
> >> >
> >>
>  <param-value>org.apache.wink.jaxrs.test.providers.writerexceptions.Application</param-value>
> >> >        </init-param>
> >> >        <load-on-startup>1</load-on-startup>
> >> >    </servlet>
> >> >    <servlet>
> >> >        <servlet-name>MessageBodyReaderExceptions</servlet-name>
> >> >
> >>
>  <servlet-class>org.apache.wink.server.internal.servlet.RestServlet</servlet-class>
> >> >        <init-param>
> >> >            <param-name>javax.ws.rs.Application</param-name>
> >> >
> >>
>  <param-value>org.apache.wink.jaxrs.test.providers.readerexceptions.Application</param-value>
> >> >        </init-param>
> >> > [E.B] <init-param>
> >> >            <param-name>symphony.requestProcessorAttribute</param-name>
> >> >            <param-value>requestProcessorAttribute_2</param-value>
> >> >        </init-param>
> >> >        <load-on-startup>1</load-on-startup>
> >> >    </servlet>
> >> >    <servlet-mapping>
> >> >        <servlet-name>MessageBodyWriterExceptions</servlet-name>
> >> >        <url-pattern>/writerexceptions/*</url-pattern>
> >> >    </servlet-mapping>
> >> >    <servlet-mapping>
> >> >        <servlet-name>MessageBodyReaderExceptions</servlet-name>
> >> >        <url-pattern>/readerexceptions/*</url-pattern>
> >> >    </servlet-mapping>
> >> > </web-app>
> >> >
> >> > --
> >> >
> >> > - Bryant Luk
> >> >
> >>
> >>
> >>
> >> --
> >>
> >> - Bryant Luk
> >>
> >
>
>
>
> --
>
> - Bryant Luk
>

Re: Multiple RestServlets in single web application?

Posted by Bryant Luk <br...@gmail.com>.
Thanks, I think I understand the reasoning and the implementation
better between Eli and your messages.  Let me think about this for a
bit.

For the basic improvement that Eli suggested where multiple JAX-RS
Applications are allowed via a ; or something else, is the assumption
that you could find a common url pattern and make the @Path values be
"right"?  For instance, if I had a bookstore application and a
shoestore application with (context root)/bookstore/item1 and (context
root)/shoestore/item1 as two intended URLs, you would have the URL
pattern be /* and all bookstore resources pre-pended with
@Path("/bookstore/{item}") and shoestore resources pre-pended with
@Path("/shoestore/{item}") (and also hope that there aren't
"undefined" scenarios where 2 paths are unknowingly exactly the same)?
 An unlikely example but just making sure I understand the suggestion
and the implications.

In any case, yes, I would hope the normal situation would be only one
RestServlet per war.  I was trying to isolate some of the JAX-RS
Applications because I don't want some of the @Providers to cross
Applications.  Originally the tests were written in numerous small
applications but in order to limit the number of Maven submodules, I
wanted to combine the applications together without the @Providers
crossing over.

As far as the shared library point, I think both Eli and Michael have
answered my question.

On Thu, Jul 2, 2009 at 12:56 PM, Michael Elman<ta...@gmail.com> wrote:
> Hi Bryant ,
>
> this parameter is used in order to provide an additional functionality, like
> Administration Servlet and a runtime registration.
> The reason is simple: we want be able to access the RequestProcessor
> instance from sources that are different that the RestServlet: other
> servlets, JMX, spring beans and so on.
> Of cause if this functionality is not required, we can use an autogenerated
> value.



>
>
> On Thu, Jul 2, 2009 at 4:51 PM, Bryant Luk <br...@gmail.com> wrote:
>
>> Hi Eli,
>>
>> Just curious why we need the application developer to add that
>> parameter.  Is there any way that we can autogenerate that parameter
>> within the runtime?  The reasons why I think we should autogenerate:
>>
>> 1)  Application portability.  If other implementations take their
>> JAX-RS application and switch to Wink (or start with Wink), the first
>> impression may be that we don't work out of the box.
>
>
> The parameter is needed only if there are multiple RestServlet instances
> within the same war. I believe that a normal situation is to have a single
> RestServlet per war. If this is the case, such a parameter is not needed. So
> it won't work out of the box only in a complex cases.
>
>
>>
>> 2)  I haven't tested this but if we use Wink as a shared library
>> across a container's applications (such as Geronimo/WebSphere), I
>> think this would cause some administration headaches since every
>> parameter value (I'm assuming) has to be unique.  Some application
>> developers might not communicate their unique attribute names, and
>> this would be a really hard thing to find out when an application
>> doesn't work correctly.
>>
>
> What do you mean by using Wink as a shared library? If you mean sharing it
> between wars (putting it in a parent classloader), it won't cause any
> problems, since the parameter should be unique per ServletConfig, meaning it
> should be unique in the same war, but different wars can use the same name.
>
>
>>
>> I think we can have it as an optional attribute if you want to use the
>> same RequestProcessor across two servlet instances, just that by
>> default, we generate a unique one per servlet instance.
>>
>> Thoughts?
>>
>> On Thu, Jul 2, 2009 at 3:34 AM, Baram, Eliezer<eb...@hp.com> wrote:
>> > Hi Bryant
>> > The RestServlet stores the requestProcessor on the servletContext, by
>> default it saves it under an attribute named
>> RequestProcessor.class.getName()
>> >
>> > If you register more then one servlet and you want each to have a
>> separate RequestProcessor you need to indicate the RestServlet to save the
>> RequestProcessor under a different attribute.
>> >
>> > You can specify the attribute name by setting the
>> "symphony.requestProcessorAttribute" init parameter of the RestServlet.
>> > See modification below.
>> >
>> > --Eli
>> >
>> >
>> >
>> > -----Original Message-----
>> > From: Bryant Luk [mailto:bryant.luk@gmail.com]
>> > Sent: Thursday, July 02, 2009 2:09 AM
>> > To: wink-dev@incubator.apache.org
>> > Subject: Multiple RestServlets in single web application?
>> >
>> > Hi,
>> >
>> > Does the RestServlet support multiple servlet instances in the same
>> > web application?
>> >
>> > It seems that only the first servlet (in alphabetical order) is fired
>> > up correctly.  If I have two instances of the servlet, say
>> > MessageBodyWriterExceptions and MessageBodyReaderExceptions, only
>> > MessageBodyReaderExceptions seems to work.  If I then rename
>> > MessageBodyReaderExceptions to "Z" (or comment out the servlet
>> > definition), then my MessageBodyWriterExceptions servlet JAX-RS app
>> > works.
>> >
>> > My web.xml:
>> >
>> > <web-app>
>> >    <display-name>Archetype Created Web Application</display-name>
>> >    <servlet>
>> >        <servlet-name>MessageBodyWriterExceptions</servlet-name>
>> >
>>  <servlet-class>org.apache.wink.server.internal.servlet.RestServlet</servlet-class>
>> >        <init-param>
>> >            <param-name>javax.ws.rs.Application</param-name>
>> >
>>  <param-value>org.apache.wink.jaxrs.test.providers.writerexceptions.Application</param-value>
>> >        </init-param>
>> >        <load-on-startup>1</load-on-startup>
>> >    </servlet>
>> >    <servlet>
>> >        <servlet-name>MessageBodyReaderExceptions</servlet-name>
>> >
>>  <servlet-class>org.apache.wink.server.internal.servlet.RestServlet</servlet-class>
>> >        <init-param>
>> >            <param-name>javax.ws.rs.Application</param-name>
>> >
>>  <param-value>org.apache.wink.jaxrs.test.providers.readerexceptions.Application</param-value>
>> >        </init-param>
>> > [E.B] <init-param>
>> >            <param-name>symphony.requestProcessorAttribute</param-name>
>> >            <param-value>requestProcessorAttribute_2</param-value>
>> >        </init-param>
>> >        <load-on-startup>1</load-on-startup>
>> >    </servlet>
>> >    <servlet-mapping>
>> >        <servlet-name>MessageBodyWriterExceptions</servlet-name>
>> >        <url-pattern>/writerexceptions/*</url-pattern>
>> >    </servlet-mapping>
>> >    <servlet-mapping>
>> >        <servlet-name>MessageBodyReaderExceptions</servlet-name>
>> >        <url-pattern>/readerexceptions/*</url-pattern>
>> >    </servlet-mapping>
>> > </web-app>
>> >
>> > --
>> >
>> > - Bryant Luk
>> >
>>
>>
>>
>> --
>>
>> - Bryant Luk
>>
>



-- 

- Bryant Luk

Re: Multiple RestServlets in single web application?

Posted by Michael Elman <ta...@gmail.com>.
Hi Bryant ,

this parameter is used in order to provide an additional functionality, like
Administration Servlet and a runtime registration.
The reason is simple: we want be able to access the RequestProcessor
instance from sources that are different that the RestServlet: other
servlets, JMX, spring beans and so on.
Of cause if this functionality is not required, we can use an autogenerated
value.


On Thu, Jul 2, 2009 at 4:51 PM, Bryant Luk <br...@gmail.com> wrote:

> Hi Eli,
>
> Just curious why we need the application developer to add that
> parameter.  Is there any way that we can autogenerate that parameter
> within the runtime?  The reasons why I think we should autogenerate:
>
> 1)  Application portability.  If other implementations take their
> JAX-RS application and switch to Wink (or start with Wink), the first
> impression may be that we don't work out of the box.


The parameter is needed only if there are multiple RestServlet instances
within the same war. I believe that a normal situation is to have a single
RestServlet per war. If this is the case, such a parameter is not needed. So
it won't work out of the box only in a complex cases.


>
> 2)  I haven't tested this but if we use Wink as a shared library
> across a container's applications (such as Geronimo/WebSphere), I
> think this would cause some administration headaches since every
> parameter value (I'm assuming) has to be unique.  Some application
> developers might not communicate their unique attribute names, and
> this would be a really hard thing to find out when an application
> doesn't work correctly.
>

What do you mean by using Wink as a shared library? If you mean sharing it
between wars (putting it in a parent classloader), it won't cause any
problems, since the parameter should be unique per ServletConfig, meaning it
should be unique in the same war, but different wars can use the same name.


>
> I think we can have it as an optional attribute if you want to use the
> same RequestProcessor across two servlet instances, just that by
> default, we generate a unique one per servlet instance.
>
> Thoughts?
>
> On Thu, Jul 2, 2009 at 3:34 AM, Baram, Eliezer<eb...@hp.com> wrote:
> > Hi Bryant
> > The RestServlet stores the requestProcessor on the servletContext, by
> default it saves it under an attribute named
> RequestProcessor.class.getName()
> >
> > If you register more then one servlet and you want each to have a
> separate RequestProcessor you need to indicate the RestServlet to save the
> RequestProcessor under a different attribute.
> >
> > You can specify the attribute name by setting the
> "symphony.requestProcessorAttribute" init parameter of the RestServlet.
> > See modification below.
> >
> > --Eli
> >
> >
> >
> > -----Original Message-----
> > From: Bryant Luk [mailto:bryant.luk@gmail.com]
> > Sent: Thursday, July 02, 2009 2:09 AM
> > To: wink-dev@incubator.apache.org
> > Subject: Multiple RestServlets in single web application?
> >
> > Hi,
> >
> > Does the RestServlet support multiple servlet instances in the same
> > web application?
> >
> > It seems that only the first servlet (in alphabetical order) is fired
> > up correctly.  If I have two instances of the servlet, say
> > MessageBodyWriterExceptions and MessageBodyReaderExceptions, only
> > MessageBodyReaderExceptions seems to work.  If I then rename
> > MessageBodyReaderExceptions to "Z" (or comment out the servlet
> > definition), then my MessageBodyWriterExceptions servlet JAX-RS app
> > works.
> >
> > My web.xml:
> >
> > <web-app>
> >    <display-name>Archetype Created Web Application</display-name>
> >    <servlet>
> >        <servlet-name>MessageBodyWriterExceptions</servlet-name>
> >
>  <servlet-class>org.apache.wink.server.internal.servlet.RestServlet</servlet-class>
> >        <init-param>
> >            <param-name>javax.ws.rs.Application</param-name>
> >
>  <param-value>org.apache.wink.jaxrs.test.providers.writerexceptions.Application</param-value>
> >        </init-param>
> >        <load-on-startup>1</load-on-startup>
> >    </servlet>
> >    <servlet>
> >        <servlet-name>MessageBodyReaderExceptions</servlet-name>
> >
>  <servlet-class>org.apache.wink.server.internal.servlet.RestServlet</servlet-class>
> >        <init-param>
> >            <param-name>javax.ws.rs.Application</param-name>
> >
>  <param-value>org.apache.wink.jaxrs.test.providers.readerexceptions.Application</param-value>
> >        </init-param>
> > [E.B] <init-param>
> >            <param-name>symphony.requestProcessorAttribute</param-name>
> >            <param-value>requestProcessorAttribute_2</param-value>
> >        </init-param>
> >        <load-on-startup>1</load-on-startup>
> >    </servlet>
> >    <servlet-mapping>
> >        <servlet-name>MessageBodyWriterExceptions</servlet-name>
> >        <url-pattern>/writerexceptions/*</url-pattern>
> >    </servlet-mapping>
> >    <servlet-mapping>
> >        <servlet-name>MessageBodyReaderExceptions</servlet-name>
> >        <url-pattern>/readerexceptions/*</url-pattern>
> >    </servlet-mapping>
> > </web-app>
> >
> > --
> >
> > - Bryant Luk
> >
>
>
>
> --
>
> - Bryant Luk
>

Re: Multiple RestServlets in single web application?

Posted by Nicholas L Gallardo <nl...@us.ibm.com>.
+1 to auto populating a new parameter and enabling it by default.

Question, does the runtime work when two servlets share the same request
processor?  My impression from Bryant's note was no, but Eli seemed to
indicate that they did.  Or, is it that only one servlet needs to be fired
because the config that existed for both applications is now smashed
together?

Looking at how the servlets are defined in Bryant's example, it seems more
intuitive to have the configs separated out on a per servlet basis.  If I
want them together, then I can just add the resources/providers to a single
Application class and be done with it.

-Nick



Nicholas Gallardo
WebSphere  - REST & WebServices Development
nlgallar@us.ibm.com
Phone: 512-286-6258
Building: 903 / 5G-016


                                                                           
             Bryant Luk                                                    
             <bryant.luk@gmail                                             
             .com>                                                      To 
                                       wink-dev@incubator.apache.org       
             07/02/2009 08:51                                           cc 
             AM                                                            
                                                                   Subject 
                                       Re: Multiple RestServlets in single 
             Please respond to         web application?                    
             wink-dev@incubato                                             
               r.apache.org                                                
                                                                           
                                                                           
                                                                           
                                                                           




Hi Eli,

Just curious why we need the application developer to add that
parameter.  Is there any way that we can autogenerate that parameter
within the runtime?  The reasons why I think we should autogenerate:

1)  Application portability.  If other implementations take their
JAX-RS application and switch to Wink (or start with Wink), the first
impression may be that we don't work out of the box.
2)  I haven't tested this but if we use Wink as a shared library
across a container's applications (such as Geronimo/WebSphere), I
think this would cause some administration headaches since every
parameter value (I'm assuming) has to be unique.  Some application
developers might not communicate their unique attribute names, and
this would be a really hard thing to find out when an application
doesn't work correctly.

I think we can have it as an optional attribute if you want to use the
same RequestProcessor across two servlet instances, just that by
default, we generate a unique one per servlet instance.

Thoughts?

On Thu, Jul 2, 2009 at 3:34 AM, Baram, Eliezer<eb...@hp.com> wrote:
> Hi Bryant
> The RestServlet stores the requestProcessor on the servletContext, by
default it saves it under an attribute named RequestProcessor.class.getName
()
>
> If you register more then one servlet and you want each to have a
separate RequestProcessor you need to indicate the RestServlet to save the
RequestProcessor under a different attribute.
>
> You can specify the attribute name by setting the
"symphony.requestProcessorAttribute" init parameter of the RestServlet.
> See modification below.
>
> --Eli
>
>
>
> -----Original Message-----
> From: Bryant Luk [mailto:bryant.luk@gmail.com]
> Sent: Thursday, July 02, 2009 2:09 AM
> To: wink-dev@incubator.apache.org
> Subject: Multiple RestServlets in single web application?
>
> Hi,
>
> Does the RestServlet support multiple servlet instances in the same
> web application?
>
> It seems that only the first servlet (in alphabetical order) is fired
> up correctly.  If I have two instances of the servlet, say
> MessageBodyWriterExceptions and MessageBodyReaderExceptions, only
> MessageBodyReaderExceptions seems to work.  If I then rename
> MessageBodyReaderExceptions to "Z" (or comment out the servlet
> definition), then my MessageBodyWriterExceptions servlet JAX-RS app
> works.
>
> My web.xml:
>
> <web-app>
>    <display-name>Archetype Created Web Application</display-name>
>    <servlet>
>        <servlet-name>MessageBodyWriterExceptions</servlet-name>
>
<servlet-class>org.apache.wink.server.internal.servlet.RestServlet</servlet-class>

>        <init-param>
>            <param-name>javax.ws.rs.Application</param-name>
>
<param-value>org.apache.wink.jaxrs.test.providers.writerexceptions.Application</param-value>

>        </init-param>
>        <load-on-startup>1</load-on-startup>
>    </servlet>
>    <servlet>
>        <servlet-name>MessageBodyReaderExceptions</servlet-name>
>
<servlet-class>org.apache.wink.server.internal.servlet.RestServlet</servlet-class>

>        <init-param>
>            <param-name>javax.ws.rs.Application</param-name>
>
<param-value>org.apache.wink.jaxrs.test.providers.readerexceptions.Application</param-value>

>        </init-param>
> [E.B] <init-param>
>            <param-name>symphony.requestProcessorAttribute</param-name>
>            <param-value>requestProcessorAttribute_2</param-value>
>        </init-param>
>        <load-on-startup>1</load-on-startup>
>    </servlet>
>    <servlet-mapping>
>        <servlet-name>MessageBodyWriterExceptions</servlet-name>
>        <url-pattern>/writerexceptions/*</url-pattern>
>    </servlet-mapping>
>    <servlet-mapping>
>        <servlet-name>MessageBodyReaderExceptions</servlet-name>
>        <url-pattern>/readerexceptions/*</url-pattern>
>    </servlet-mapping>
> </web-app>
>
> --
>
> - Bryant Luk
>



--

- Bryant Luk

Re: Multiple RestServlets in single web application?

Posted by Bryant Luk <br...@gmail.com>.
Hi Eli,

Just curious why we need the application developer to add that
parameter.  Is there any way that we can autogenerate that parameter
within the runtime?  The reasons why I think we should autogenerate:

1)  Application portability.  If other implementations take their
JAX-RS application and switch to Wink (or start with Wink), the first
impression may be that we don't work out of the box.
2)  I haven't tested this but if we use Wink as a shared library
across a container's applications (such as Geronimo/WebSphere), I
think this would cause some administration headaches since every
parameter value (I'm assuming) has to be unique.  Some application
developers might not communicate their unique attribute names, and
this would be a really hard thing to find out when an application
doesn't work correctly.

I think we can have it as an optional attribute if you want to use the
same RequestProcessor across two servlet instances, just that by
default, we generate a unique one per servlet instance.

Thoughts?

On Thu, Jul 2, 2009 at 3:34 AM, Baram, Eliezer<eb...@hp.com> wrote:
> Hi Bryant
> The RestServlet stores the requestProcessor on the servletContext, by default it saves it under an attribute named RequestProcessor.class.getName()
>
> If you register more then one servlet and you want each to have a separate RequestProcessor you need to indicate the RestServlet to save the RequestProcessor under a different attribute.
>
> You can specify the attribute name by setting the "symphony.requestProcessorAttribute" init parameter of the RestServlet.
> See modification below.
>
> --Eli
>
>
>
> -----Original Message-----
> From: Bryant Luk [mailto:bryant.luk@gmail.com]
> Sent: Thursday, July 02, 2009 2:09 AM
> To: wink-dev@incubator.apache.org
> Subject: Multiple RestServlets in single web application?
>
> Hi,
>
> Does the RestServlet support multiple servlet instances in the same
> web application?
>
> It seems that only the first servlet (in alphabetical order) is fired
> up correctly.  If I have two instances of the servlet, say
> MessageBodyWriterExceptions and MessageBodyReaderExceptions, only
> MessageBodyReaderExceptions seems to work.  If I then rename
> MessageBodyReaderExceptions to "Z" (or comment out the servlet
> definition), then my MessageBodyWriterExceptions servlet JAX-RS app
> works.
>
> My web.xml:
>
> <web-app>
>    <display-name>Archetype Created Web Application</display-name>
>    <servlet>
>        <servlet-name>MessageBodyWriterExceptions</servlet-name>
>        <servlet-class>org.apache.wink.server.internal.servlet.RestServlet</servlet-class>
>        <init-param>
>            <param-name>javax.ws.rs.Application</param-name>
>            <param-value>org.apache.wink.jaxrs.test.providers.writerexceptions.Application</param-value>
>        </init-param>
>        <load-on-startup>1</load-on-startup>
>    </servlet>
>    <servlet>
>        <servlet-name>MessageBodyReaderExceptions</servlet-name>
>        <servlet-class>org.apache.wink.server.internal.servlet.RestServlet</servlet-class>
>        <init-param>
>            <param-name>javax.ws.rs.Application</param-name>
>            <param-value>org.apache.wink.jaxrs.test.providers.readerexceptions.Application</param-value>
>        </init-param>
> [E.B] <init-param>
>            <param-name>symphony.requestProcessorAttribute</param-name>
>            <param-value>requestProcessorAttribute_2</param-value>
>        </init-param>
>        <load-on-startup>1</load-on-startup>
>    </servlet>
>    <servlet-mapping>
>        <servlet-name>MessageBodyWriterExceptions</servlet-name>
>        <url-pattern>/writerexceptions/*</url-pattern>
>    </servlet-mapping>
>    <servlet-mapping>
>        <servlet-name>MessageBodyReaderExceptions</servlet-name>
>        <url-pattern>/readerexceptions/*</url-pattern>
>    </servlet-mapping>
> </web-app>
>
> --
>
> - Bryant Luk
>



-- 

- Bryant Luk

RE: Multiple RestServlets in single web application?

Posted by "Baram, Eliezer" <eb...@hp.com>.
Hi Bryant
The RestServlet stores the requestProcessor on the servletContext, by default it saves it under an attribute named RequestProcessor.class.getName()
 
If you register more then one servlet and you want each to have a separate RequestProcessor you need to indicate the RestServlet to save the RequestProcessor under a different attribute.

You can specify the attribute name by setting the "symphony.requestProcessorAttribute" init parameter of the RestServlet. 
See modification below. 

--Eli



-----Original Message-----
From: Bryant Luk [mailto:bryant.luk@gmail.com] 
Sent: Thursday, July 02, 2009 2:09 AM
To: wink-dev@incubator.apache.org
Subject: Multiple RestServlets in single web application?

Hi,

Does the RestServlet support multiple servlet instances in the same
web application?

It seems that only the first servlet (in alphabetical order) is fired
up correctly.  If I have two instances of the servlet, say
MessageBodyWriterExceptions and MessageBodyReaderExceptions, only
MessageBodyReaderExceptions seems to work.  If I then rename
MessageBodyReaderExceptions to "Z" (or comment out the servlet
definition), then my MessageBodyWriterExceptions servlet JAX-RS app
works.

My web.xml:

<web-app>
    <display-name>Archetype Created Web Application</display-name>
    <servlet>
        <servlet-name>MessageBodyWriterExceptions</servlet-name>
        <servlet-class>org.apache.wink.server.internal.servlet.RestServlet</servlet-class>
        <init-param>
            <param-name>javax.ws.rs.Application</param-name>
            <param-value>org.apache.wink.jaxrs.test.providers.writerexceptions.Application</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet>
        <servlet-name>MessageBodyReaderExceptions</servlet-name>
        <servlet-class>org.apache.wink.server.internal.servlet.RestServlet</servlet-class>
        <init-param>
            <param-name>javax.ws.rs.Application</param-name>
            <param-value>org.apache.wink.jaxrs.test.providers.readerexceptions.Application</param-value>
        </init-param>
[E.B] <init-param>
            <param-name>symphony.requestProcessorAttribute</param-name>
            <param-value>requestProcessorAttribute_2</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>MessageBodyWriterExceptions</servlet-name>
        <url-pattern>/writerexceptions/*</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>MessageBodyReaderExceptions</servlet-name>
        <url-pattern>/readerexceptions/*</url-pattern>
    </servlet-mapping>
</web-app>

-- 

- Bryant Luk