|
From: Borut B. <bor...@gm...> - 2010-10-21 08:31:43
|
Hello,
I hope someone reads this, as the list seem a bit deserted, but anyways...
Yesterday I tried to use the client side of the RestEasy framework. The
interface has a method:
@PUT
@Path("document/autoincrement")
@Consumes("application/xml")
BaseClientResponse<String> insertPointOfInterest(PoiDocument
poiDocument);
and the call to some (Jersey) rest service looks like:
String restServerServiceUrl = "
http://my.jersey.server/rest/serviceFoo/v1/";
NSSClientService client =
ProxyFactory.create(NSSClientService.class, restServerServiceUrl);
PoiDocument poiDocument = new PoiDocument("Parkirišče", "90",
390262.85133115170, 42240.33558245482);
BaseClientResponse<String> response =
client.insertPointOfInterest(poiDocument);
assert response.getResponseStatus() == Response.Status.OK;
// Expected result
//<?xml version="1.0" encoding="UTF-8"
standalone="yes"?><insertedRecord><record>14</record></insertedRecord>
logger.info("Returned: " + response.getEntity());
And the logger prints:
<?xml version="1.0" encoding="UTF-8"
standalone="yes"?><insertedRecord><record>14</record></insertedRecord>
Kind of expected.
But I want an object not a string, so I can easely assert the values
returned. The interface:
@PUT
@Path("document/autoincrement")
@Consumes("application/xml")
BaseClientResponse<InsertedResponse> insertPointOfInterest(PoiDocument
poiDocument);
Instead of String there is now a InsertedResponse class which looks like:
@XmlRootElement(name="insertedRecord")
public class InsertedResponse extends ResponseResult{
String insertedRecord;
public InsertedResponse(int insertedRecord) {
this.insertedRecord = Integer.toString(insertedRecord);
}
public InsertedResponse(){
insertedRecord = "";
}
@XmlElement(name="record")
public String getInsertedRecords(){
return insertedRecord;
}
public void add(int recNo) {
insertedRecord = Integer.toString(recNo);
}
}
...and his superclass:
@XmlRootElement(name = "result")
public abstract class ResponseResult {
protected String getClearString(String string) {
if (string != null) {
return Constants.removeInvalidXMLCharacters(string);
}
return "";
}
}
Now, when I change the client call also to:
BaseClientResponse<InsertedResponse> response =
client.insertPointOfInterest(poiDocument);
logger.info("Returned: " +
response.getEntity().getInsertedRecords());
I get an empty string instead of some value.
So, the question is - where did the value of <record> go? It should print a
number, like 14 in the above example.
Kind regards,
Borut
|