public Message invoke(Message msg) {
// Put an entry
Object[] args = (Object[])msg.getBody();
String id = (String)args[0];
Entry entry = (Entry)args[1];
// Send an HTTP PUT
PutMethod putMethod = new PutMethod(uri + "/" + id);
putMethod.setRequestHeader("Authorization", authorizationHeader);
try {
// Write the Atom entry
StringWriter writer = new StringWriter();
AtomEntryUtil.writeEntry(entry, "atom_1.0", writer);
putMethod.setRequestHeader("Content-type", "application/atom+xml; charset=utf-8");
putMethod.setRequestEntity(new StringRequestEntity(writer.toString()));
httpClient.executeMethod(putMethod);
int status = putMethod.getStatusCode();
// Read the Atom entry
if (status == 200 || status == 201) {
try {
Entry updatedEntry =
AtomEntryUtil.readEntry("atom_1.0", new InputStreamReader(putMethod
.getResponseBodyAsStream()));
msg.setBody(updatedEntry);
} catch (Exception e) {
// Returning the updated entry is optional