Image ransfer using hessian protocol from client's folder to tomcat server

你离开我真会死。 提交于 2019-12-10 12:23:21

问题


My goal is to upload a image(.jpg or .png) from client's folder to tomcat6 server through hessian protocol. And do image processing using opencv on server, then return the image back to client.

Question1. Is the following transfering steps correct?

  • put a test.jpg image on client's folder
    --> convert the test.jpg in client.java (main.java) class to BufferedImage
    --> convert the BufferedImage to mat or Iplimage in server for using openCV.

I have set a hello world sample from Simple Messaging Example using Hessian , and searched from Hessian with large binary data and other websites, but still dont know how to use it!

Question2. Is there a related Java sample code?

(I am using ubuntu12+netbeans7.2)


回答1:


It sounds like you probably want to treat the image as a byte stream on the client, instead of using BufferedImage. After processing, you can do whatever you want, but it'll be easier to use hessian if you just send the file contents.

Hessian understand InputStream as a type. So your minimal method call API can look like

InputStream convert(InputStream upload);

The client would open an input stream to the original file and send that input stream directly:

InputStream is = new FileInputStream("test.jpg");
InputStream resultIs = hessianProxy.convert(is);
.... // save the result

A bit of caution that the hessian response connection will still be live until you finish reading the input stream, so you need to read it immediately. (It's not buffered, which is one reason it can be efficient.)

On the server, you need to read from the input stream (again, immediately). And as a result, return an InputStream that reads from your converted image:

InputStream convert(InputStream is) {
  ... // read from 'is' to your internal data
  InputStream result = ... // process
  return result;
}

You'll want to make sure the result input stream closes anything automatically on the end of file. You might want to create a wrapper to call close().



来源:https://stackoverflow.com/questions/12575872/image-ransfer-using-hessian-protocol-from-clients-folder-to-tomcat-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!