views:

27

answers:

0

Hello all, I'm trying to send byte[] to a servlet and get the result back using O'Reilly HttpMessage. But I get a null pointer exception on retrieving.

This is the code on the client app:

  URL url = null;
  try {
   url = new URL("http://localhost:8080/ImageFilter/imagefilter");
  } catch (MalformedURLException e) {
   e.printStackTrace();
  }
  HttpMessage msg = new HttpMessage(url);
  InputStream in;
  byte[] filteredImg = null;
  Properties prop = new Properties();
  prop.put("imgstream", new String(tile.arrayWithHeader));
  try {
   //sending parameter value in prop object 
   //and retrieve the value as inputstream
   //this line below gives me the error
   in = msg.sendPostMessage(prop);
   filteredImg = new byte[in.available()];
   in.read(filteredImg);
  } catch (IOException e) {
   e.printStackTrace();
  }

On the servlet itself, I don't do anything to the byte[]. Simply get from request and send it back directly to the client, like this:

  ServletInputStream in = req.getInputStream();
  byte[] imgOld = new byte[in.available()];
  in.read(imgOld);
  in.close();

  ServletOutputStream out = resp.getOutputStream();
  out.write(imgOld);        
  out.flush();
  out.close();

I would really appreciate if anyone could give me a hint on this. Thank you.