users@jersey.java.net

Re: [Jersey] Using _at_FormParam value to specify/call resource method

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Thu, 15 Jan 2009 10:50:39 +0100

Hi Dmitry,

Unfortunately it is not possible in JAX-RS to switch on @*Param. And
since @FormParam is defined in the JAX-RS API it is not possible to
change it to support "action" parameters. It is only possible to
switch on @Path and @Consumes/Produces.

It is not possible to directly extend Jersey to support this. It is
possible to extend Jersey to support different matching and
dispatching to a single resource method but it is not possible to
extend to a group of methods.

If this is very common you could define an abstract class that has
support the the look up and process, for example

   @Path("/query")
   public class MyFormActionDispatcher extends FormActionDispatcher {
      @FormAction("postQuery")
      public void postQuery() { ... }

      @FormAction("postQueryGroup")
      public void postQuery() { ... }
   }

The class FormActionDispatcher could analyze using reflection the
methods annotated with @FormAction, for example:

   public abstract class FormActionDispatcher {
      private static boolean initiated;
      private static Map<String, Processor> processorMap;

      public FormActionDispatcher() {
          syncrhonized(this) {
              if (initiated == false) {
                  // Perform reflection on concrete class
              }
          }
      }

      @Cosumes(MediaType.APPLICATION_FORM_URLENCODED_TYPE)
      public void post(@FormParam("action") String action) {
          processorMap.get(action).process();
      }
   }

Hope this helps,
Paul.

On Jan 15, 2009, at 9:58 AM, shaper_at_sibmail.com wrote:

> Hello,
>
> We have pack of front-end javascript code based on ExtJS library and
> we
> are going to use Jersey in a project instead of own framework, so to
> reduce the changes just want to extend easily Jersey. Is it possible
> to
> implement through Jersey API the extension with functionality as shown
> from the code below? Could you clarify in short the approach to
> implementation the extension?
>
>
> @Path("/query")
> @Consumes("application/json")
> @Produces("application/json")
> public class QueryResource {
>
> @POST
> @FormParam(action=”postQuery”) // Action parameter value
> “postQuery”
> in POST
> public void postQuery() {
> …
> }
>
> @POST
> @FormParam(action=”postQueryGroup”) // Action parameter value
> “postQueryGroup” in POST
> public void postQueryGroup() {
> …
> }
> }
>
>
> Thanks in advance,
> Dmitry S.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>