users@jersey.java.net

Using annotated POJOs to build client request

From: Patrick Sansoucy <patrick.sansoucy_at_gmail.com>
Date: Mon, 23 Mar 2009 14:26:21 -0400

                Hello,

                I am quite new to Jersey and the JSR311 spec and was looking
into using this for a project I am currently working on ... I have to call a
RESTful service which has a more than 10 request parameters which will
return a XML response. I was wondering if it was possible to use an annoted
POJO to build the URI ?

For example, something that would look like this ...

http://www.myurl.net/getquote.asp?acct=XXX&type=1&pid=XXX&a=1

And the associated POJO ...

@Path("getquote.asp?acct={accountCode}&type={productType}&pid={productIdentifier}")

public class Quote {

/*
* account code Format: up to 12 alphanumeric characters. Mandatory
*/
protected String accountCode;

/*
* product type. Mandatory
*/
protected int productType;

/*
* unique product identifier Format: positive integer from result set
* Mandatory
*/
protected int productIdentifier;

public void setAccountCode(@PathParam("accountCode") String aAccountCode) {
 this.accountCode = aAccountCode;
}

public String getAccountCode() {
return this.accountCode;
}

public int getProductType() {
return this.productType;
}

public void setProductType(@PathParam("productType") int aProductType) {
 this.productType = aProductType;
}

public int getProductIdentifier() {
return this.productIdentifier;
}

public void setProductIdentifier(@PathParam("productIdentifier") int
aProductIdentifier) {
this.productIdentifier = aProductIdentifier;
}

}

Thank you
Patrick Sansoucy