You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cxf.apache.org by Ryan Zoerner <ry...@gmail.com> on 2011/05/13 03:25:40 UTC

Questions regarding the implementation of a 2-endpoint Customer and CustomerService CXF JAX-RS web application

Sergey,

I have the following question regarding the project.

---------------------------------------------------------------------
---------------------------------------------------------------------
Customer:
---------------------------------------------------------------------
Per-request resource: Does Customer store Customers?
By what mechanism does Customer return Customers?
  Constructor (overloaded)?
  FactoryMethod?
  Constructor w/necessary calls to setName and setID?

What methods should I expose?:
  Overloaded or non-overloaded constructor?
  Manipulate name and id, or do not manipulate name and id? (Get and Set)
  Should I keep a list of Customers, perhaps in class
    CustomerStorage?
  Do you want a CustomerFactory and a Customer object?
---------------------------------------------------------------------
---------------------------------------------------------------------
CustomerService:

Does it store the customers or does Customer store the
customers, (or both)? Does anything store the customers?

Does customerService call Customer to retrieve Customers
  from storage?

Does it call Customer to generate Customers fresh each time?

Does it store Customers that it retrieves?

For how long does it store the complete list of Customers
  that it retrieves.

Is there anything such as a 'request-set' of Customers,
  s.t. (such that), you can display a list of Customers
  retrieved in one request session?

By what means does CustomerService instantiate xml?

Does it instantiate the xml?

With JAX-WS, there is WSDL and WS-import. If I create a
Customer Interface; if I store it on the Customer Endpoint
by what mechanism can I obtain a method-stub representation
of the class, on this Endpoint, s.t. I can instantiate the
class and use getters and setters?

---------------------------------------------------------------------
---------------------------------------------------------------------

Because I thought that Customer must store Customers,
what I created was:

+customerService.customer.classes+
  -CustomerFactoryImpl.java
  -CustomerImpl.java
  -CustomerStorageImpl.java

+customerService.customer.interfaces+
  -Customer.java    { generateNewCustomerInstance() }
  -CustomerFactory.java   { overloaded constructor,set[...],get[...] }
  -CustomerStorage.java   { add, get, update, delete }

+customerService.jaxrs.client
  -Client.java { sends commands to endpoints and receives responses }

+customerService.jaxrs.client.xmlResources
  -add_customer.xml
  -customer_list.xml { list of Customers }
  -update_customer.xml

+customerService.jaxrs.customerGenerationAndStorage
  -CustomerService.java { uses add, get, update, and delete to manage
                          CustomerStorage.java }
  -Server.java { consumes messages and produces responses }

+customerService.jaxrs.customersListingService
  -CustomersService.java { makes calls to CustomerService, to instantiate
                           or retrieve Customer instances, in the form of
                           xml. I was envisioning being able to instantiate
                           a CustomerFactory from within this code, and in
                           such a way that it can be treated as though it
                           were contained in code that is in another package

                           in my workspace, in eclipse, with this package.

                           Somehow to create code s.t.,
                           CustomerFactory c = new ...
                           /**
                            * I want this to return a new instantiated
                            * Customer that has come in from the other
                            * service, by means of an xml transmission.
                            *
                            * Presumably, you could import the FactoryImpl
and
                            * extend it by adding some helper class to the
                            * constructor which would transform an xml
                            * representation to an Object representation.
                            * Presumably, that class would be a part of cxf.

                            *
                            * I would like, also, for the environment to be
                            * able to locate the URI of the resource as
though
                            * it were simply another package in a packaged
                            * web archive. This, because you want the
                            * FactoryImpl to not implement any web methods
                            * what-so-ever. I guess, ideally, you would say
                            *
                            * @InjectWebMethod("/URI-of-method")
                            * private CustomerFactory c;
                            *
                            * and this would be instantiated in the
constructor,
                            * but declared from within class-scope. And the
                            * annotation. Wait, this is better: the
annotation
                            * would take care of locating the method,
                            * web communication, receiving the xml and auto-
                            * converting it to the Object, and this, by
linking
                            * the Factory to other code which automatically
                            * processes the stuff differently by means of
the
                            * compiler, or the virtual machine.
                            *
                            * Did I just describe JAXB and JAX-WS? I may
have,
                            * but I don't really know. However, what I have
                            * just described sounds, to me, like the most
                            * sensible thing because you can treat code on
                            * a distant machine, just as though it is on
your
                            * machine, in coding with it.
                            *
                            * Is it currently possible to obtain from
                            * customerService.java the full representation
                            * of the class? Or just the method stubs?
                            *
                            * Is it currently possible to obtain the full
                            * representation from wsimport? Or through some
                            * other means? Or does the implementation
                            * traditionally remain secure within the
                            * webservice, in jax-ws?
                            */
                           c.getNewCustomerInstance( [name], [id] );
  -Server.java  { consumes messages and produces responses }

Thanks,
Ryan

Re: Questions regarding the implementation of a 2-endpoint Customer and CustomerService CXF JAX-RS web application

Posted by Ryan Zoerner <ry...@gmail.com>.
Thank you for your answer. I'm sorry, I didn't see it before I posted the
link.

Ryan

Re: Questions regarding the implementation of a 2-endpoint Customer and CustomerService CXF JAX-RS web application

Posted by Sergey Beryozkin <sb...@gmail.com>.
Very good, there's one simplification is that those methods with @GET
should just return 'this'.
Just make sure Customer id and name are set to some default values.

Your implementation is also correct though; if we rename Customer to
say Person then your code can handle  the family hierarchy case, etc;

Do you what I'm saying, why for the sake of the test you don;t have to
create new Customer() ? Effectively Customer becomes CustomerService
but I just wanted you to see that the root resource can return its own
state and act as a subresource too

Also, there's one problem with that code is that you have multiple
methods with @GET which is fine - but every GET method should be
unique enough (has unique @Path or Consumes or Produces)

Sergey
On Fri, May 13, 2011 at 12:47 PM, Ryan Zoerner <ry...@gmail.com> wrote:
> The full Customer.java class may be viewed here:
>
> http://pages.cs.wisc.edu/~zoerner/downloads/dev/samples/customerservice/Customer.java
>



-- 
Sergey Beryozkin

Application Integration Division of Talend
http://sberyozkin.blogspot.com

Re: Questions regarding the implementation of a 2-endpoint Customer and CustomerService CXF JAX-RS web application

Posted by Ryan Zoerner <ry...@gmail.com>.
The full Customer.java class may be viewed here:

http://pages.cs.wisc.edu/~zoerner/downloads/dev/samples/customerservice/Customer.java

Re: Questions regarding the implementation of a 2-endpoint Customer and CustomerService CXF JAX-RS web application

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

On Fri, May 13, 2011 at 10:54 AM, Ryan Zoerner <ry...@gmail.com> wrote:
> Hi Sergey,
>
> You mentioned that Customer should display a single customer. Does
> CustomerService instantiate that Customer?

I'm presuming we are talking about the 2nd endpoint ?
No, as I said in the previous email, it is the custom resource
provider which will do it.

>By what mechanism? I created this
> class to try and get around that problem. In the old demo, Customers were
> instantiated in CustomerService, however, if you have CustomerService being
> called by Customer to get its Customer to display, does that make sense to
> you?

I agree it does not. Customer root resource will be instantiated by
your custom resource provider
and will return its own hardcoded state...

> The server would call getCustomer and the createCustomer method would
> act like init() on an individual call basis.
>
> I may have questions about your response that I just read, but I am too
> tired right now to develop them.

Please take a break :-). Check the CXF JAX-RS docs about subresources
too, it's very simple, you'll do it in few mins after you get a break.
I guess I could've just typed the code right here but it's about you
managing this GSOC project and you've progressed a lot so I'll just
let you do it :-). If you prefer you could start focusing on EJB
integration right now, but I think that without feeling how JAX-RS
works you'll just find it difficult to get the integration working
>  ----------------------------------------------------------------
> public Customer()
>  {
>    @Path("/name/none/id/none/")
>    public Customer getCustomer()
>
>    @Path("/name/{name: [a-zA-Z]+}/id/none}")
>    public Customer getCustomer(@PathParam("name") String name)
>
>    @Path("/name/none/id/{id: [0-9]+)")
>    public Customer getCustomer(@PathParam("id") long id)
>
>    @Path("/name/{name: [a-zA-Z]+}/id/{id: [0-9]+)")
>    public Customer getCustomer(@PathParam("name") String name,
>        @PathParam("id") long id)
>
>    @GET
>    private Customer createCustomer()
>
>    @GET
>    private Customer createCustomer(String name)
>
>    @GET
>    private Customer createCustomer(long id)
>
>    @GET
>    private Customer createCustomer(String name, long id)
> }
>  -----------------------------------------------------------------------------------------------------------
>
A hint:

Just have two methods: one is subresource locator, another one is the
final resource method which will return the state. Subresurce locator
effectively delegates to the final resource method. You'll be
surprised how easy it is but I do appreciate it can be tricky without
having a prior experience

Same for CustomeService: have some basic map/list of Customers, few
resource methods, etc. It's not about writing a quality
CustomerService - it's about you moving to the next stage with the
full confidence

Thanks, Sergey

> Thank you,
> Ryan
>



-- 
Sergey Beryozkin

Application Integration Division of Talend
http://sberyozkin.blogspot.com

Re: Questions regarding the implementation of a 2-endpoint Customer and CustomerService CXF JAX-RS web application

Posted by Ryan Zoerner <ry...@gmail.com>.
Hi Sergey,

You mentioned that Customer should display a single customer. Does
CustomerService instantiate that Customer? By what mechanism? I created this
class to try and get around that problem. In the old demo, Customers were
instantiated in CustomerService, however, if you have CustomerService being
called by Customer to get its Customer to display, does that make sense to
you? The server would call getCustomer and the createCustomer method would
act like init() on an individual call basis.

I may have questions about your response that I just read, but I am too
tired right now to develop them.
 ----------------------------------------------------------------
public Customer()
 {
    @Path("/name/none/id/none/")
    public Customer getCustomer()

    @Path("/name/{name: [a-zA-Z]+}/id/none}")
    public Customer getCustomer(@PathParam("name") String name)

    @Path("/name/none/id/{id: [0-9]+)")
    public Customer getCustomer(@PathParam("id") long id)

    @Path("/name/{name: [a-zA-Z]+}/id/{id: [0-9]+)")
    public Customer getCustomer(@PathParam("name") String name,
        @PathParam("id") long id)

    @GET
    private Customer createCustomer()

    @GET
    private Customer createCustomer(String name)

    @GET
    private Customer createCustomer(long id)

    @GET
    private Customer createCustomer(String name, long id)
}
 -----------------------------------------------------------------------------------------------------------

Thank you,
Ryan

Re: Questions regarding the implementation of a 2-endpoint Customer and CustomerService CXF JAX-RS web application

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

On Fri, May 13, 2011 at 2:25 AM, Ryan Zoerner <ry...@gmail.com> wrote:
> Sergey,
>
> I have the following question regarding the project.
>
> ---------------------------------------------------------------------
> ---------------------------------------------------------------------
> Customer:
> ---------------------------------------------------------------------
> Per-request resource: Does Customer store Customers?
> By what mechanism does Customer return Customers?
>  Constructor (overloaded)?
>  FactoryMethod?
>  Constructor w/necessary calls to setName and setID?
>
> What methods should I expose?:
>  Overloaded or non-overloaded constructor?
>  Manipulate name and id, or do not manipulate name and id? (Get and Set)
>  Should I keep a list of Customers, perhaps in class
>    CustomerStorage?
>  Do you want a CustomerFactory and a Customer object?
> ---------------------------------------------------------------------

Let CustomerService manage individual Customer instances, for the 2nd
endpoint lets have a Customer root resource with the hardcoded state
(name, whatever) which is created on every request. This Customer root
resource needs to return its own state. Suppose a client uses this URI
to get this state:
http://localhost:8080/customers/customer/state,

Customer root resource needs to handle this request in two steps:
- use subresource locator to return the subresource instance which
will handle the request and
- have a resource method with @GET annotation which will basically
return "this" and this has to work because Customer happens to have
@XmlRootElement annotation.


> ---------------------------------------------------------------------
> CustomerService:
>
> Does it store the customers or does Customer store the
> customers, (or both)? Does anything store the customers?
>
> Does customerService call Customer to retrieve Customers
>  from storage?
>
> Does it call Customer to generate Customers fresh each time?
>
> Does it store Customers that it retrieves?
>
> For how long does it store the complete list of Customers
>  that it retrieves.
>
> Is there anything such as a 'request-set' of Customers,
>  s.t. (such that), you can display a list of Customers
>  retrieved in one request session?
>
There are all good questions one needs to address when building a
CustomerService but this is not what you are after after all, what you
are trying to do is get up to speed with JAX-RS mechanics asap. Have
some primitive CustomerService implementation but make sure you see
how various methods are invoked and how request parameters and
response objects are handled, etc, and whatever else we agreed re the
1st endpoint

> By what means does CustomerService instantiate xml?
>
> Does it instantiate the xml?
>
CustomerService does not deal with it directly, it could, but not in
this case. CXF JAX-RS MessageBodyReader and MessageBodyWriter
supporting the JAXB databindiing will do it.

> With JAX-WS, there is WSDL and WS-import. If I create a
> Customer Interface; if I store it on the Customer Endpoint
> by what mechanism can I obtain a method-stub representation
> of the class, on this Endpoint, s.t. I can instantiate the
> class and use getters and setters?
>
> ---------------------------------------------------------------------

Your custom per-request provider only needs to create a new instance
when requested.

> ---------------------------------------------------------------------
>
> Because I thought that Customer must store Customers,
> what I created was:
>
> +customerService.customer.classes+
>  -CustomerFactoryImpl.java
>  -CustomerImpl.java
>  -CustomerStorageImpl.java
>
> +customerService.customer.interfaces+
>  -Customer.java    { generateNewCustomerInstance() }
>  -CustomerFactory.java   { overloaded constructor,set[...],get[...] }
>  -CustomerStorage.java   { add, get, update, delete }
>
> +customerService.jaxrs.client
>  -Client.java { sends commands to endpoints and receives responses }
>
> +customerService.jaxrs.client.xmlResources
>  -add_customer.xml
>  -customer_list.xml { list of Customers }
>  -update_customer.xml
>
> +customerService.jaxrs.customerGenerationAndStorage
>  -CustomerService.java { uses add, get, update, and delete to manage
>                          CustomerStorage.java }
>  -Server.java { consumes messages and produces responses }
>
> +customerService.jaxrs.customersListingService
>  -CustomersService.java { makes calls to CustomerService, to instantiate
>                           or retrieve Customer instances, in the form of
>                           xml. I was envisioning being able to instantiate
>                           a CustomerFactory from within this code, and in
>                           such a way that it can be treated as though it
>                           were contained in code that is in another package
>
>                           in my workspace, in eclipse, with this package.
>
>                           Somehow to create code s.t.,
>                           CustomerFactory c = new ...
>                           /**
>                            * I want this to return a new instantiated
>                            * Customer that has come in from the other
>                            * service, by means of an xml transmission.
>                            *
>                            * Presumably, you could import the FactoryImpl
> and
>                            * extend it by adding some helper class to the
>                            * constructor which would transform an xml
>                            * representation to an Object representation.
>                            * Presumably, that class would be a part of cxf.
>
>                            *
>                            * I would like, also, for the environment to be
>                            * able to locate the URI of the resource as
> though
>                            * it were simply another package in a packaged
>                            * web archive. This, because you want the
>                            * FactoryImpl to not implement any web methods
>                            * what-so-ever. I guess, ideally, you would say
>                            *
>                            * @InjectWebMethod("/URI-of-method")
>                            * private CustomerFactory c;
>                            *
>                            * and this would be instantiated in the
> constructor,
>                            * but declared from within class-scope. And the
>                            * annotation. Wait, this is better: the
> annotation
>                            * would take care of locating the method,
>                            * web communication, receiving the xml and auto-
>                            * converting it to the Object, and this, by
> linking
>                            * the Factory to other code which automatically
>                            * processes the stuff differently by means of
> the
>                            * compiler, or the virtual machine.
>                            *
>                            * Did I just describe JAXB and JAX-WS? I may
> have,
>                            * but I don't really know. However, what I have
>                            * just described sounds, to me, like the most
>                            * sensible thing because you can treat code on
>                            * a distant machine, just as though it is on
> your
>                            * machine, in coding with it.
>                            *
>                            * Is it currently possible to obtain from
>                            * customerService.java the full representation
>                            * of the class? Or just the method stubs?
>                            *
>                            * Is it currently possible to obtain the full
>                            * representation from wsimport? Or through some
>                            * other means? Or does the implementation
>                            * traditionally remain secure within the
>                            * webservice, in jax-ws?
>                            */
>                           c.getNewCustomerInstance( [name], [id] );
>  -Server.java  { consumes messages and produces responses }

Please make things simpler, follow the basic/jax-rs demo and focus on
the JAX-RS mechanics.
Use JAXRSServerFactorybean to create both endpoints, or jaxrs:server
Spring declarations if you prefer

Thanks, Sergey

>
> Thanks,
> Ryan
>



-- 
Sergey Beryozkin

Application Integration Division of Talend
http://sberyozkin.blogspot.com