-1

I've been trying to figure out why the Servlet won't return the bytes to the client with this code (although the bytes is read based on the logs):

Redirector redirector = new SelfInjectingRedirector(getContext(), targetPattern,
        Redirector.MODE_SERVER_OUTBOUND){

    @Inject
    FileStore fileStore;

    String fileName = "something_for_sample";
    boolean isBufferFirst = true;

    @Override
    public void handle(Request request, Response response) {
        try {
            HttpServletRequest servletRequest = ServletUtils.getRequest(request);
            HttpServletResponse servletResponse = ServletUtils.getResponse(response);
            //
            // Either statement here wont return the bytes to the client
            // 
            if(isBufferFirst) {
                byte[] bytes = fileStore.get(fileName);
                System.out.println("Bytes read: " + bytes.length); // Bytes read: 5731
                servletResponse.getOutputStream().write(bytes, 0, bytes.length)
            } else {
                fileStore.get(fileName, servletResponse.getOutputStream());
            }
        } catch (Exception e) {
            response.setStatus(Status.SERVER_ERROR_INTERNAL);
            e.printStackTrace();
        }
        System.out.println("Handle Done");
    }

};
quarks
  • 33,478
  • 73
  • 290
  • 513
  • Here's the class heirarchy "SelfInjectingRedirector extends Redirector" and "Redirector extends Restlet" as in org.restlet.Restlet – quarks Jul 22 '17 at 06:38
  • Since this is not using anything standard it's really impossible to tell. What is "Response"? What is "ServletUtils"? What is FileStore? – stdunbar Jul 23 '17 at 01:23
  • It's Restlet (see tag) – quarks Jul 23 '17 at 15:46

1 Answers1

0

The solution is to add the "Content-Length" header.

quarks
  • 33,478
  • 73
  • 290
  • 513