jsr311
  1. jsr311
  2. JSR311-27

Allow HttpMethod annotation directly on method

    Details

    • Type: Improvement Improvement
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Won't Fix
    • Affects Version/s: current
    • Fix Version/s: current
    • Component/s: www
    • Labels:
      None
    • Environment:

      Operating System: All
      Platform: All
      URL: http://www.joshdevins.net

    • Issuezilla Id:
      27

      Description

      Currently the HttpMethod annotation is applied only to other annotations. So now
      there are @HEAD and @GET type annotations. This gets a bit confusing since it
      allows someone to put a @HEAD and @GET annotation both on the same method. It
      seems it would make much more sense to just have the HttpMethod annotation's
      value be an HttpMethodType enumeration. Then you can only have one HttpMethod
      per method. Simple, concise, and a lot easier to understand and code to.

        Activity

        Hide
        Jakub Podlesak added a comment -

        Also implementing custom HTTP methods could be
        easier with possibility to annotate java methods directly with
        @HttpMethod annotation.

        e.g. the following code to implement CUSTOM method
        a bit complex:

        @Path("myresource") public class MyResource {

        @Target(

        {ElementType.METHOD}

        )
        @Retention(RetentionPolicy.RUNTIME)
        @HttpMethod("CUSTOM")
        public @interface CUSTOM {
        }

        @CUSTOM
        @ProduceMime("text/plain")
        public String myMethod()

        { return "hello"; }

        }

        Show
        Jakub Podlesak added a comment - Also implementing custom HTTP methods could be easier with possibility to annotate java methods directly with @HttpMethod annotation. e.g. the following code to implement CUSTOM method a bit complex: @Path("myresource") public class MyResource { @Target( {ElementType.METHOD} ) @Retention(RetentionPolicy.RUNTIME) @HttpMethod("CUSTOM") public @interface CUSTOM { } @CUSTOM @ProduceMime("text/plain") public String myMethod() { return "hello"; } }
        Hide
        mhadley added a comment -

        The current approach was adopted in response to negative feedback on the original approach of directly
        annotating methods with @HttpMethod. Compile time or runtime validation can warn of cases where
        multiple HTTP methods are specified for the same Java method and such a capability may even be
        desirable in some circumstances.

        Adding an annotation to support a custom method is not very onerous and is unlikely to be required
        often.

        Show
        mhadley added a comment - The current approach was adopted in response to negative feedback on the original approach of directly annotating methods with @HttpMethod. Compile time or runtime validation can warn of cases where multiple HTTP methods are specified for the same Java method and such a capability may even be desirable in some circumstances. Adding an annotation to support a custom method is not very onerous and is unlikely to be required often.

          People

          • Assignee:
            jsr311-issues
            Reporter:
            joshdevins
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: