Uploaded image for project: 'CXF'
  1. CXF
  2. CXF-7267

Member names must match bean attribute for BeanParam to work

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 3.1.4
    • 3.1.11, 3.2.0
    • None
    • None
    • Unknown

    Description

      I just ran into this problem on my first attempt to use @BeanParam and got this exception:

      java.lang.IllegalArgumentException: Unresolved variables; only 0 value(s) given for 2 unique variable(s)
      	at org.apache.cxf.jaxrs.impl.UriBuilderImpl.substituteVarargs(UriBuilderImpl.java:285)
      	at org.apache.cxf.jaxrs.impl.UriBuilderImpl.doBuildUriParts(UriBuilderImpl.java:121)
      ...
      

      My parameter bean looked like this:

      package com.recommind.common.rest;
      
      import javax.ws.rs.PathParam;
      
      public final class ApplicationIdentifierParameter
      {
      
        @PathParam("applicationId")
        private String mApplicationId;
      
        @PathParam("projectId")
        private String mProjectId;
      
        public String getApplicationId()
        {
          return mApplicationId;
        }
      
        public void setApplicationId(String aApplicationId)
        {
          mApplicationId = aApplicationId;
        }
      
        public String getProjectId()
        {
          return mProjectId;
        }
      
        public void setProjectId(String aProjectId)
        {
          mProjectId = aProjectId;
        }
      }
      

      I debugged UriBuilderImpl and found that in ClientProxyImpl:514 the to be evaluated members are identified by the names of the corresponding setters.

      I think this is wrong - or at least inconvenient - as it is totally valid for a bean's internals fields to have different names than the corresponding bean attribute. To my knowledge the Bean spec only requires setters and getters to match and does not care about the internal representation of the attributes.

      Rather than looking at the setters ClientProxyImpl should iterate over the bean's fields, look for fields annotated with @PathParam and update the field using reflection.

      Workaround:
      Annotate the setters with the @XXXParam annotations.

      Attachments

        Activity

          People

            sergey_beryozkin Sergey Beryozkin
            daniel@peger.de Daniel H. Peger
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: