You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by yoMrJ <mr...@abv.bg> on 2010/05/21 12:14:23 UTC

Re: CXF RESTful user generated model instead of Annotations in the code?


Hi Sergey,

thanks for your hint. I've looked into this and I was able to build a model
for my service.
However I have some strange problem.

My exposed interface is: test.ws.Service

I try to invoke it's login method that has 2 parameters (arg0 and arg1)

[code]
<model xmlns="http://cxf.apache.org/jaxrs">
 <resource name="test.ws.Service" path="service"
 consumes="application/xml" produces="application/xml">
    <operation name="login" path="log-in/{arg0}/{arg1}">
       
       
    </operation>
 </resource>
  <resource name="test.ws.UserState">
    <operation name="getLoginState" />
    <operation name="getSessionId" verb="GET" />
    <operation name="getUserId" verb="GET"/>
    <operation name="getUsername" verb="GET"/>
  </resource>
  <resource name="test.ws.LoginState">
  </resource>
</model>

/code]

UserState is an interface
LoginState is an enum

Problem: When I call 

 http://localhost:9090/rest/ws/usersession/service/log-in/admin/admin

it returns no XML but only the number 4 - which is the result of the
getUserId method of the UserState type. But I want it to return a full XML
with the UserState object with all of its fields like for example as similar
to what I get when invoking the greeter or greeter2 method greeting.

What am I doing wrong? It seems that there is a little, tiny mistake I am
making when creating the model.



Cheers,
George

-- 
View this message in context: http://old.nabble.com/CXF-RESTful-user-generated-model-instead-of-Annotations-in-the-code--tp28620778p28631958.html
Sent from the cxf-user mailing list archive at Nabble.com.


Re: CXF RESTful user generated model instead of Annotations in the code?

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi

On Sat, May 22, 2010 at 7:47 PM, yoMrJ <mr...@abv.bg> wrote:

>
> Hi Sergey,
>
> Thanks for the reply!
>
> >Can LoginState act as a subresource ? If no then you'll need to remove its
> >description from the model...
>
> I was hoping you can tell me that. How can I know if it can act as a
> subresource? It is an enum class having the values LOGIN_SUCCESS and
> LOGIN_ERR. Can enum act as a subresource? What features must a class have
> to
> be able to act as a subresource and most important - can an enum act as a
> subresource?
>
>
Subresource is a JAXRS term - a root resource can have a number of resource
methods, some of them servicing request URI and returning some data and some
of them acting as locators which return objects or subresources capable of
handling request URI/HTTP method

To that end, a custom enum can be a subresource - if you use JAXRS
annotations. With a user model you can turn any class which can not be
touched/extended/wrapped into a JAXRS resource/subresource

>
>
> > What does login/{arg0}/{arg1} return, a subresource such as UserState ?
>
> Yes this returns a UserState instance. An UserState has the fields
> -LoginState - this is an enum as I said. There is also a getter for this
> field
> -sessionId - this is a sting - also has a getter.
> -userId - string as well - has getter
> -username - string as well - this one has getter too
>
>
>
> >Well, looks like "getLoginState" is not recognized as a subresource (given
> >it has no 'verb' and perhaps because LoginState is not a valid resource),
> >three other operations are equal candidates, they have the same implicit
> >path value and the same verb :
>
> In the cxf jaxrs/RESTFul related documentation about the user specified
> model it was stated that in order for a subresource to be recognized the
> definition of it in the model has to have no verb. That's why I've removed
> it.
>

sure - should work provided LoginState is a valid subresource


> I see now that the three oder operations that describe the fields of type
> String are possibly wrongly described by me.
>
> Would it be OK that I write my class here and you write me how the model
> for
> it should look like? This way I can figure out what the principle is an I
> can then build the model for the rest of my classes.
>


> >Perhaps you might want to review the JAXRS docs ?
>
> I will take a look at those docs as well :) The problem is that the model
> that cxf uses is somehow slightly different from the way the annotations
> are
> added in JAXRS.
>
> How about starting with the JAXRS compliant option first (using
annotations) ? Once you learn how to use them
it will be straightforward to switch to a user model - using it is really
nearly identical to adding annotations to the code

cheers, Sergey


> Cheers,
> George
>
> --
> View this message in context:
> http://old.nabble.com/CXF-RESTful-user-generated-model-instead-of-Annotations-in-the-code--tp28620778p28645364.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>
>

Re: CXF RESTful user generated model instead of Annotations in the code?

Posted by yoMrJ <mr...@abv.bg>.
Hi Sergey,

Thanks for the reply!

>Can LoginState act as a subresource ? If no then you'll need to remove its
>description from the model...

I was hoping you can tell me that. How can I know if it can act as a
subresource? It is an enum class having the values LOGIN_SUCCESS and
LOGIN_ERR. Can enum act as a subresource? What features must a class have to
be able to act as a subresource and most important - can an enum act as a
subresource?



> What does login/{arg0}/{arg1} return, a subresource such as UserState ?

Yes this returns a UserState instance. An UserState has the fields
-LoginState - this is an enum as I said. There is also a getter for this
field
-sessionId - this is a sting - also has a getter.
-userId - string as well - has getter
-username - string as well - this one has getter too



>Well, looks like "getLoginState" is not recognized as a subresource (given
>it has no 'verb' and perhaps because LoginState is not a valid resource),
>three other operations are equal candidates, they have the same implicit
>path value and the same verb :

In the cxf jaxrs/RESTFul related documentation about the user specified
model it was stated that in order for a subresource to be recognized the
definition of it in the model has to have no verb. That's why I've removed
it.
I see now that the three oder operations that describe the fields of type
String are possibly wrongly described by me.

Would it be OK that I write my class here and you write me how the model for
it should look like? This way I can figure out what the principle is an I
can then build the model for the rest of my classes.


>Perhaps you might want to review the JAXRS docs ?

I will take a look at those docs as well :) The problem is that the model
that cxf uses is somehow slightly different from the way the annotations are
added in JAXRS.


Cheers,
George

-- 
View this message in context: http://old.nabble.com/CXF-RESTful-user-generated-model-instead-of-Annotations-in-the-code--tp28620778p28645364.html
Sent from the cxf-user mailing list archive at Nabble.com.


Re: CXF RESTful user generated model instead of Annotations in the code?

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi

<model xmlns="http://cxf.apache.org/jaxrs">

>  <resource name="test.ws.Service" path="service"
>  consumes="application/xml" produces="application/xml">
>    <operation name="login" path="log-in/{arg0}/{arg1}">
>
>
>    </operation>
>  </resource>
>  <resource name="test.ws.UserState">
>    <operation name="getLoginState" />
>    <operation name="getSessionId" verb="GET" />
>    <operation name="getUserId" verb="GET"/>
>    <operation name="getUsername" verb="GET"/>
>  </resource>
>  <resource name="test.ws.LoginState">
>  </resource>
> </model>
>
> /code]
>
> UserState is an interface
> LoginState is an enum
>
>
Can LoginState act as a subresource ? If no then you'll need to remove its
description from the model...


> Problem: When I call
>
>  http://localhost:9090/rest/ws/usersession/service/log-in/admin/admin
>
> it returns no XML but only the number 4 - which is the result of the
> getUserId method of the UserState type. But I want it to return a full XML
> with the UserState object with all of its fields like for example as
> similar
> to what I get when invoking the greeter or greeter2 method greeting.
>
> What am I doing wrong? It seems that there is a little, tiny mistake I am
> making when creating the model.
>
>

What does login/{arg0}/{arg1} return, a subresource such as UserState ?

Well, looks like "getLoginState" is not recognized as a subresource (given
it has no 'verb' and perhaps because LoginState is not a valid resource),
three other operations are equal candidates, they have the same implicit
path value and the same verb :

<resource name="test.ws.UserState">
   <operation name="getLoginState" />
   <operation name="getSessionId" verb="GET" />
   <operation name="getUserId" verb="GET"/>
   <operation name="getUsername" verb="GET"/>
 </resource>

Perhaps you might want to review the JAXRS docs ?

cheers, Sergey



>
>
> Cheers,
> George
>
> --
> View this message in context:
> http://old.nabble.com/CXF-RESTful-user-generated-model-instead-of-Annotations-in-the-code--tp28620778p28631958.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>
>