CXF
  1. CXF
  2. CXF-4224

Custom HTTP methods (HttpMethod annot) not supported?

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Cannot Reproduce
    • Affects Version/s: 2.5.3
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None
    • Estimated Complexity:
      Unknown

      Description

      I wanted to save myself some typing and introduce a custom method annotation for use with a response handler:

      @Target(value = METHOD)
      @Retention(value = RUNTIME)
      @HttpMethod(value = POST)
      public @interface POST_create {

      }

      since HATEOS resource creation is done with POST.

      However a method:

      @POST_create
      @Consumes(CONTENT_FORM_URLENCODED)
      @Description(title = "Factory method")
      Dto createSomething( ... );

      is not found as valid resource method.

      When I annotate it with regular POST annot. it works:

      @POST
      @POST_create
      @Consumes(CONTENT_FORM_URLENCODED)
      @Description(title = "Factory method")
      Dto createSomething( ... );

      BTW. While trying to debug this I noticed that the HttpMethod annotation is still recognized as a valid resource method annotation ( c.f. CXF-1007 ) in org.apache.cxf.jaxrs.utils.AnnotationUtils.initMethodAnnotationClasses() line 114

        Activity

        Hide
        Sergey Beryozkin added a comment -

        np, thanks for confirming it, and having a new test added did not 'harm' the CXF too

        Show
        Sergey Beryozkin added a comment - np, thanks for confirming it, and having a new test added did not 'harm' the CXF too
        Hide
        Jakub Bocheński added a comment -

        Thanks, I tried this again and must say that it is working now - at least with 2.5.3-20120403.080549-37.

        Sorry for the hassle - most likely there was something wrong with auto publishig to my dev Tomcat.

        Show
        Jakub Bocheński added a comment - Thanks, I tried this again and must say that it is working now - at least with 2.5.3-20120403.080549-37. Sorry for the hassle - most likely there was something wrong with auto publishig to my dev Tomcat.
        Hide
        Sergey Beryozkin added a comment -

        Jakub, I'm resolving it as Cannot Reproduce for now given that I have a working test now, as opposed to Won't Fix. Please feel free to reopen it - but I would need more help from you on reproducing it. Please either debug further or provide a test maven based project. Cheers

        Show
        Sergey Beryozkin added a comment - Jakub, I'm resolving it as Cannot Reproduce for now given that I have a working test now, as opposed to Won't Fix. Please feel free to reopen it - but I would need more help from you on reproducing it. Please either debug further or provide a test maven based project. Cheers
        Hide
        Sergey Beryozkin added a comment -

        That is not enough for me to reproduce this issue, @Path annotations have nothing to do with the issue.
        I've added the test confirming custom HTTP method annotations are handled properly.
        If you think this is still a real issue then please attach a maven test project, thanks

        Show
        Sergey Beryozkin added a comment - That is not enough for me to reproduce this issue, @Path annotations have nothing to do with the issue. I've added the test confirming custom HTTP method annotations are handled properly. If you think this is still a real issue then please attach a maven test project, thanks
        Hide
        Jakub Bocheński added a comment -

        The method has no @Path annotation - just what you see in the example: @Consumes, @Description, @POST_create.

        I already checked that the method is not returned in the list of resource method during matching (resource class is selected, but no match is found b/c of this).

        Show
        Jakub Bocheński added a comment - The method has no @Path annotation - just what you see in the example: @Consumes, @Description, @POST_create. I already checked that the method is not returned in the list of resource method during matching (resource class is selected, but no match is found b/c of this).
        Hide
        Sergey Beryozkin added a comment -

        This issue appears to be invalid, see
        http://svn.apache.org/viewvc?rev=1309733&view=rev

        What is different in your case, can you enable the debug logging ?

        Show
        Sergey Beryozkin added a comment - This issue appears to be invalid, see http://svn.apache.org/viewvc?rev=1309733&view=rev What is different in your case, can you enable the debug logging ?
        Hide
        Jakub Bocheński added a comment - - edited

        PS. Another workaround I just tested (and it seems to work) is to name the annotation POST, e.g.

        package my.stuff;
        
        public abstract class Create {
        	@Target(value = METHOD)
        	@Retention(value = RUNTIME)
        	@HttpMethod(value = POST)
        	public @interface POST {
        
        	}
        }

        The Create class wrapper is so that I don't have to write the fully qualified my.stuff.POST, now I do:

        @Create.POST 
        @Consumes(CONTENT_FORM_URLENCODED)
        @Description(title = "Factory method")
        Dto createSomething( ... ); 
        Show
        Jakub Bocheński added a comment - - edited PS. Another workaround I just tested (and it seems to work) is to name the annotation POST, e.g. package my.stuff; public abstract class Create { @Target(value = METHOD) @Retention(value = RUNTIME) @HttpMethod(value = POST) public @ interface POST { } } The Create class wrapper is so that I don't have to write the fully qualified my.stuff.POST, now I do: @Create.POST @Consumes(CONTENT_FORM_URLENCODED) @Description(title = "Factory method" ) Dto createSomething( ... );
        Hide
        Jakub Bocheński added a comment -

        I implemented a custom ResponseHandler that will change the status code to 201 and add Location header - but it needs a custom annotation to identify the resource-creating methods.

        Since those methods are always invoked via the POST verb I figured I will create an annotataion that would do both things at once (identify factory method and define the HTTP verb).

        Of course I could do sth like:

        @POST
        @RestFactory

        with @RestFactory being a simple runtime annotation.

        Anyway I assume this is a rather simple fix when you know where to change it (OK - I didn't look for it too long) - maybe do it just for the sake of being spec-compilant?

        Show
        Jakub Bocheński added a comment - I implemented a custom ResponseHandler that will change the status code to 201 and add Location header - but it needs a custom annotation to identify the resource-creating methods. Since those methods are always invoked via the POST verb I figured I will create an annotataion that would do both things at once (identify factory method and define the HTTP verb). Of course I could do sth like: @POST @RestFactory with @RestFactory being a simple runtime annotation. Anyway I assume this is a rather simple fix when you know where to change it (OK - I didn't look for it too long) - maybe do it just for the sake of being spec-compilant?
        Hide
        Sergey Beryozkin added a comment -

        or let me ask it differently, why would not you simply use @POST instead of marking a method handling POST with @POST_create ?

        Show
        Sergey Beryozkin added a comment - or let me ask it differently, why would not you simply use @POST instead of marking a method handling POST with @POST_create ?
        Hide
        Jakub Bocheński added a comment - - edited

        If I understand you correctly then my example clearly shows they can be diferent.

        I think what I've done is valid acording to the jax-rs spec.
        OTOH I have no idea where the assumtion that annotation [class-]name must much the HttpMethods argument came from.

        Show
        Jakub Bocheński added a comment - - edited If I understand you correctly then my example clearly shows they can be diferent. I think what I've done is valid acording to the jax-rs spec. OTOH I have no idea where the assumtion that annotation [class-] name must much the HttpMethods argument came from.
        Hide
        Sergey Beryozkin added a comment -

        Interesting, at the moment the assumption is the name of the annotation should match that of @HttpMethod's value.
        Can they be different ?

        Show
        Sergey Beryozkin added a comment - Interesting, at the moment the assumption is the name of the annotation should match that of @HttpMethod's value. Can they be different ?

          People

          • Assignee:
            Sergey Beryozkin
            Reporter:
            Jakub Bocheński
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development