Hello Everyone,
I am trying to write a simple REST service which writes a new team of players into a text file every time the client is executed.The client is sending the POST request as follows:
private void sendPostRequest() {
byte [] team_to_add;
Player hibbert = new Player("Hibbert", "Roy Hibbert");
Player paul = new Player("Paul", "Paul George");
Player west = new Player("West", "David West");
List<Player> mb = new ArrayList<Player>();
mb.add(hibbert);
mb.add(paul);
mb.add(west);
Team Pacers = new Team("Indiana_Pacers",mb);
// TODO Auto-generated method stub
XMLEncoder enc;
try {
enc = new XMLEncoder(new BufferedOutputStream(new FileOutputStream("team_to_add.txt")));
enc.writeObject(Pacers);
enc.close();
}
catch(Exception e)
{
}
HttpURLConnection PostConn = get_connection(endpoint,"POST"); //method defined in the class to get a HTTP connection.
System.out.println(PostConn.getRequestMethod());
try {
PostConn.setDoOutput(true);
DataOutputStream wr = new DataOutputStream(PostConn.getOutputStream());
String cwd = System.getProperty ("user.dir");
String sep = System.getProperty ("file.separator");
int len = (int) new File(cwd+sep+"team_to_add.txt").length();
team_to_add=new byte[len];
new FileInputStream(cwd+sep+"team_to_add.txt").read(team_to_add);
wr.write(team_to_add);
wr.flush();
wr.close();
System.out.println(PostConn.getResponseCode());
In the REST service I am obtaining the Message Context object.
Can someone help me to figure out how i can get access to the body of the POST message being sent from the client.
Thanks in advance