users@jersey.java.net

Re: [Jersey] POST multiple entities

From: mkuchtiak <Milan.Kuchtiak_at_Sun.COM>
Date: Wed, 25 Aug 2010 16:09:04 +0200

Netbeans Jersey client generates a bunch of methods based on selected
resource and its http methods e.g. :

The methods may contain type parameters, e.g. :

     public <T> T find_XML(Class<T> responseType, String id) throws
UniformInterfaceException {
         return webResource.path(java.text.MessageFormat.format("{0}",
new
Object[]{id})).accept(javax.ws.rs.core.MediaType.APPLICATION_XML).get(responseType);
     }

The usage is simple:

     CustomarClient client = new CustomerClient();

     // response in string (XML) format
     String stringResponse = find_XML(String.class, "1"); // where "1"
is some table primary key, e.g. customer ID

or

     // the method will return the Customer object (which represents
database table row)
     // note that Customer.class must be annotated with @XmlRootResource
annotation)
     Customer cust = find_XML(Customer.class, "1");

In case of , for example, post/put method, you may call the (client)
method twice to insert 2 records.

Milan

On 08/25/2010 11:58 AM, Paul Sandoz wrote:
> CC'ing Milan on the NBs team.
>
> Note that your latter example is not a valid XML document (it required
> an additional root element).
>
> Jersey supports lists of JAXB beans, you can change the type T to
> List<T>, but beyond that i am not familiar with the code that NBs
> generates.
>
> Paul.
>
> On Aug 25, 2010, at 7:50 AM, Dmitri Krupnov wrote:
>
>> Hello,
>>
>> Going off this article, I am trying to develop a method to insert
>> multiple entries into a MySQL DB using POST request. The Netbeans
>> generated java files have a method to insert a single entity, but not
>> multiple ones. For example, it accepts:
>>
>> Code:
>> <creature>
>> <sort>Mouse</sort>
>> <name>Pinky</name>
>> </creature>
>>
>>
>> But not (what I would like):
>>
>> Code:
>> <creature>
>> <sort>Mouse</sort>
>> <name>Pinky</name>
>> </creature>
>> <creature>
>> <sort>Elephant</sort>
>> <name>Dumbo</name>
>> </creature>
>>
>>
>> I'm guessing that you have to loop through the entities, but not sure
>> how to implement it, being a novice.
>>
>> Thank you in advanced,
>> Dmitri
>
>