Return-Path: X-Original-To: apmail-cxf-dev-archive@www.apache.org Delivered-To: apmail-cxf-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id A9D0748F7 for ; Fri, 13 May 2011 09:35:38 +0000 (UTC) Received: (qmail 97500 invoked by uid 500); 13 May 2011 09:35:38 -0000 Delivered-To: apmail-cxf-dev-archive@cxf.apache.org Received: (qmail 97443 invoked by uid 500); 13 May 2011 09:35:38 -0000 Mailing-List: contact dev-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list dev@cxf.apache.org Received: (qmail 97433 invoked by uid 99); 13 May 2011 09:35:38 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 13 May 2011 09:35:38 +0000 X-ASF-Spam-Status: No, hits=-0.7 required=5.0 tests=FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,RFC_ABUSE_POST,SPF_PASS,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of sberyozkin@gmail.com designates 209.85.214.41 as permitted sender) Received: from [209.85.214.41] (HELO mail-bw0-f41.google.com) (209.85.214.41) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 13 May 2011 09:35:30 +0000 Received: by bwz17 with SMTP id 17so2524987bwz.0 for ; Fri, 13 May 2011 02:35:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:content-type:content-transfer-encoding; bh=l5GIeQ+DpdRXUTxQHiqlHoX8vYiimH3kPtoyUIa0PTI=; b=D903bSVrHxFnb7J2zsE8d5MWGkyJbM0qJovQqFoQufU11OIQjGSOqsoCQR3CWSa10p cTWqEsR+sakrC+Wx2jyFdZCzIDUIRWQEo2yieunDJIwia0AO0TR+sEktmNtQa8VjPk46 lEIhRtUzmRYipwWhE3zD8+pBC5r6ceg85qctQ= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=kWAi8g/+tgF5lqJKon8YlyXIirDz/qbqEjhLkyO7rbLk5d6J0X/8iXxVxkC43ypvkz 4aI46+iiNnl4P1P0uA16dYfoojeth6eTCmQgtARMYjuI20M8XZINXp6sxjfSAIUIztW+ d8aNmeEhP0ekKG3wehmNEYaK9jqgUj+qviYqA= MIME-Version: 1.0 Received: by 10.204.136.217 with SMTP id s25mr1167318bkt.13.1305279309180; Fri, 13 May 2011 02:35:09 -0700 (PDT) Received: by 10.204.179.211 with HTTP; Fri, 13 May 2011 02:35:09 -0700 (PDT) In-Reply-To: References: Date: Fri, 13 May 2011 10:35:09 +0100 Message-ID: Subject: Re: Questions regarding the implementation of a 2-endpoint Customer and CustomerService CXF JAX-RS web application From: Sergey Beryozkin To: dev@cxf.apache.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Checked: Checked by ClamAV on apache.org Hi Ryan On Fri, May 13, 2011 at 2:25 AM, Ryan Zoerner 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? > =A0Constructor (overloaded)? > =A0FactoryMethod? > =A0Constructor w/necessary calls to setName and setID? > > What methods should I expose?: > =A0Overloaded or non-overloaded constructor? > =A0Manipulate name and id, or do not manipulate name and id? (Get and Set= ) > =A0Should I keep a list of Customers, perhaps in class > =A0 =A0CustomerStorage? > =A0Do 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 > =A0from 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 > =A0that it retrieves. > > Is there anything such as a 'request-set' of Customers, > =A0s.t. (such that), you can display a list of Customers > =A0retrieved 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+ > =A0-CustomerFactoryImpl.java > =A0-CustomerImpl.java > =A0-CustomerStorageImpl.java > > +customerService.customer.interfaces+ > =A0-Customer.java =A0 =A0{ generateNewCustomerInstance() } > =A0-CustomerFactory.java =A0 { overloaded constructor,set[...],get[...] } > =A0-CustomerStorage.java =A0 { add, get, update, delete } > > +customerService.jaxrs.client > =A0-Client.java { sends commands to endpoints and receives responses } > > +customerService.jaxrs.client.xmlResources > =A0-add_customer.xml > =A0-customer_list.xml { list of Customers } > =A0-update_customer.xml > > +customerService.jaxrs.customerGenerationAndStorage > =A0-CustomerService.java { uses add, get, update, and delete to manage > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0CustomerStorage.java } > =A0-Server.java { consumes messages and produces responses } > > +customerService.jaxrs.customersListingService > =A0-CustomersService.java { makes calls to CustomerService, to instantiat= e > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 or retrieve Customer = instances, in the form of > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 xml. I was envisionin= g being able to instantiate > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 a CustomerFactory fro= m within this code, and in > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 such a way that it ca= n be treated as though it > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 were contained in cod= e that is in another package > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 in my workspace, in e= clipse, with this package. > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Somehow to create cod= e s.t., > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 CustomerFactory c =3D= new ... > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 /** > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0* I want this to r= eturn a new instantiated > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0* Customer that ha= s come in from the other > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0* service, by mean= s of an xml transmission. > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0* > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0* Presumably, you = could import the FactoryImpl > and > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0* extend it by add= ing some helper class to the > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0* constructor whic= h would transform an xml > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0* representation t= o an Object representation. > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0* Presumably, that= class would be a part of cxf. > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0* > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0* I would like, al= so, for the environment to be > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0* able to locate t= he URI of the resource as > though > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0* it were simply a= nother package in a packaged > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0* web archive. Thi= s, because you want the > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0* FactoryImpl to n= ot implement any web methods > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0* what-so-ever. I = guess, ideally, you would say > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0* > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0* @InjectWebMethod= ("/URI-of-method") > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0* private Customer= Factory c; > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0* > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0* and this would b= e instantiated in the > constructor, > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0* but declared fro= m within class-scope. And the > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0* annotation. Wait= , this is better: the > annotation > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0* would take care = of locating the method, > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0* web communicatio= n, receiving the xml and auto- > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0* converting it to= the Object, and this, by > linking > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0* the Factory to o= ther code which automatically > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0* processes the st= uff differently by means of > the > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0* compiler, or the= virtual machine. > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0* > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0* Did I just descr= ibe JAXB and JAX-WS? I may > have, > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0* but I don't real= ly know. However, what I have > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0* just described s= ounds, to me, like the most > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0* sensible thing b= ecause you can treat code on > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0* a distant machin= e, just as though it is on > your > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0* machine, in codi= ng with it. > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0* > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0* Is it currently = possible to obtain from > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0* customerService.= java the full representation > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0* of the class? Or= just the method stubs? > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0* > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0* Is it currently = possible to obtain the full > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0* representation f= rom wsimport? Or through some > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0* other means? Or = does the implementation > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0* traditionally re= main secure within the > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0* webservice, in j= ax-ws? > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0*/ > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 c.getNewCustomerInsta= nce( [name], [id] ); > =A0-Server.java =A0{ 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 > --=20 Sergey Beryozkin Application Integration Division of Talend http://sberyozkin.blogspot.com