You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by bacalv <br...@vcint.com> on 2012/03/10 18:30:27 UTC

WADL Generation : Misses parameters of Bean types that have a static valueOf(String)

Hi,

I read  http://docs.huihoo.com/apache/cxf/2.2.4/jax-rs.html here  (under the
"Dealing With Parameters" section) that you can use types like the following
as parameters in a JAX-RS method...

public class SomeClass {
   public static SomeClass valueOf(String str) {
        SomeClass someClass = new SomeClass();

        . . .

        return someClass;
   }
}

For example...

public class MyService implements MyServiceImpl {
    public void doSomething(SomeClass somethingToDo) {
      . . .
    }
}

I can call this fine - the "valueOf" method gets called and the desired
object is passed in to the service method.

However, when I generate the WADL for such a service, it does not list my
"somethingToDo" parameter in the "<request>" section.

I traced through the WadlGenerator code and it appears that this case is not
being caught...

(line 455)
    private void doWriteBeanParam(StringBuilder sb, Class<?> type, Parameter
pm, String parentName) {
        Map<Parameter, Class&lt;?>> pms =
InjectionUtils.getParametersFromBeanClass(type, pm.getType(), true);
        for (Map.Entry<Parameter, Class&lt;?>> entry : pms.entrySet()) {
            String name = entry.getKey().getName();
            if (parentName != null) {
                name = parentName + "." + name;
            }
            if (*InjectionUtils.isPrimitive(entry.getValue())*) {
                doWriteParam(sb, entry.getKey(), entry.getValue(), name, new
Annotation[]{});
            } else {
                doWriteBeanParam(sb, entry.getValue(), entry.getKey(),
name);
            }
        }
    }

It seems to me that this method should treat the parameter type as a string
primitive if it has such a method.

As all of these methods are marked as private, I cannot override this
behaviour to fix the problem.

Has anyone else found another way around this?

I may resort to copying the entire class and making this modification
myself.

Thanks in advance


--
View this message in context: http://cxf.547215.n5.nabble.com/WADL-Generation-Misses-parameters-of-Bean-types-that-have-a-static-valueOf-String-tp5553328p5553328.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: WADL Generation : Misses parameters of Bean types that have a static valueOf(String)

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi
On 10/03/12 17:30, bacalv wrote:
> Hi,
>
> I read  http://docs.huihoo.com/apache/cxf/2.2.4/jax-rs.html here  (under the
> "Dealing With Parameters" section) that you can use types like the following
> as parameters in a JAX-RS method...
>
> public class SomeClass {
>     public static SomeClass valueOf(String str) {
>          SomeClass someClass = new SomeClass();
>
>          . . .
>
>          return someClass;
>     }
> }
>
> For example...
>
> public class MyService implements MyServiceImpl {
>      public void doSomething(SomeClass somethingToDo) {
>        . . .
>      }
> }
>
> I can call this fine - the "valueOf" method gets called and the desired
> object is passed in to the service method.
>
> However, when I generate the WADL for such a service, it does not list my
> "somethingToDo" parameter in the"<request>" section.
>
Is it annotated with @PathParam ? If yes it can be located immediately 
under the "resource" tag...

> I traced through the WadlGenerator code and it appears that this case is not
> being caught...
>
> (line 455)
>      private void doWriteBeanParam(StringBuilder sb, Class<?>  type, Parameter
> pm, String parentName) {
>          Map<Parameter, Class&lt;?>>  pms =
> InjectionUtils.getParametersFromBeanClass(type, pm.getType(), true);
>          for (Map.Entry<Parameter, Class&lt;?>>  entry : pms.entrySet()) {
>              String name = entry.getKey().getName();
>              if (parentName != null) {
>                  name = parentName + "." + name;
>              }
>              if (*InjectionUtils.isPrimitive(entry.getValue())*) {
>                  doWriteParam(sb, entry.getKey(), entry.getValue(), name, new
> Annotation[]{});
>              } else {
>                  doWriteBeanParam(sb, entry.getValue(), entry.getKey(),
> name);
>              }
>          }
>      }
>
> It seems to me that this method should treat the parameter type as a string
> primitive if it has such a method.
>
I agree, however the above code deals with a different branch, it seems 
even with the current code you should get a "<param>" tag, though 
probably you won't get an 'xs:string' attached right now

Cheers, Sergey

> As all of these methods are marked as private, I cannot override this
> behaviour to fix the problem.
>
> Has anyone else found another way around this?
>
> I may resort to copying the entire class and making this modification
> myself.
>
> Thanks in advance
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/WADL-Generation-Misses-parameters-of-Bean-types-that-have-a-static-valueOf-String-tp5553328p5553328.html
> Sent from the cxf-user mailing list archive at Nabble.com.


-- 
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/

Blog: http://sberyozkin.blogspot.com