Using Servlet, I can do the following to process binary stream:
public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
InputStream inputStream = req.getInputStream();
byte[] data = IOUtils.toByteArray(inputStream);
// ...
Result result = process(data);
// ...
ServletOutputStream op = resp.getOutputStream();
result.writeTo(resp.getOutputStream());
}
How I can do this in Wicket? (I have no clue after creating a page extends WebPage class)
You could do it like this:
public class OutputStreamPage extends WebPage { public OutputStreamPage( PageParameters p ) { }
}
This isn't really very natural to do in Wicket, but you can get access to the request and response objects as described in this wiki page and likely do this more or less as in your servlet code.
Or you can simply have your servlet configured in web.xml independently of wicket.
If you don't mind changing from a raw POST with binary data to a multipart form with an upload, the most natural wicket way of dealing with such is shown in the wicket examples upload.
I am now using AbstractResourceStreamWriter to implement the solution:
For such needs you should use a specialization of Wicket's org.apache.wicket.request.resource.IResource instead of a WebPage. Or plain Servlet if you don't need access to Wicket's Application/Session.