Java Reference
In-Depth Information
package com.soacookbook.rest.post;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement
public class User {
private int id;
private String username;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
@Override
public String toString() {
return "[ID=" + id + ". Username=" + username + "]";
}
}
So User is your entity in this example and is just a standard bean annotated with @Xm-
lRootElement so that you don't have to write a custom reader and writer.
The last class in the application is the client ( Example 8-18 ) . This class uses the Apache Com-
mons HTTP library to execute the POST and GET operations programmatically. There are a
couple of other dependencies you'll need for this example, including Commons Logging and
Commons Codec. You don't use them directly, but the HTTP library requires them.
Example8-18.Post user client
package com.soacookbook.rest.post;
import java.io.IOException;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.methods.GetMethod;
Search WWH ::




Custom Search