I decided to work without any REST framework, so nothing like Jersey or restlet. Instead I decided to exploit the good old Servlet API which seems to use an faithful model on how the HTTP works.
And also I decided to starts from study how to design Web applications in a way that uses correctly the HTTP protocol.
During my study I didn't find a HTTP client which fit my requirements so I'm writing some client functionalities from scratch. This is the way I implemented the posting of a form with only one parameter:
private static InputStream postForm(final String url,
final String paramName,
final String paramValue) throws IOException
{
return new Object() {
public InputStream postForm() throws IOException {
prepareConnectionToServer();
packageFormValuesInAMessage();
submitTheMessage();
return theServerReply();
}
private void prepareConnectionToServer() throws IOException {
connection = new URL(url).openConnection();
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
}
private URLConnection connection;
private void packageFormValuesInAMessage() throws UnsupportedEncodingException {
message = String.format("%s=%s", paramName, URLEncoder.encode(paramValue, "UTF-8"));
}
private String message;
private void submitTheMessage() throws IOException {
OutputStream output = connection.getOutputStream();
output.write(message.getBytes("UTF-8"));
output.close();
}
private InputStream theServerReply() throws IOException {
return connection.getInputStream();
}
}.postForm();
}