Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Problem using RPCRequest to hit servlet that returns application/pdf

    Hello,

    Using: (v8.2p_2012-07-30/PowerEdition Deployment 2012-07-30)

    I have a POST servlet that generates some special PDF file.
    Rather than storing it on the server, and returning a download link, I would like to let the browser download it immediately (ie. return a http response of content-type application/pdf).

    I use the Content-type: application/pdf return header, and verified using firebug that the PDF is in the response.

    Yet it doesn't trigger the download.
    I trigger the servlet from the client as follows:


    Code:
    private void generatePdfOnServer(List<String> pages){
    	RPCRequest request = new RPCRequest();
    	request.setActionURL(GWT.getModuleBaseURL() + "sc/GeneratePdf");
    	request.setHttpMethod("POST");
    	request.setShowPrompt(false);
    	request.setWillHandleError(true);
    			
    	Map<String, Object> params = new HashMap<String, Object>();
    	params.put("template","kitchenlist_template.html");
    	params.put("pages", pages);
    	params.put("placeholder", "__CONTENT__");
    	request.setData(params);
    	RPCManager.sendRequest(request);
    }
    In the servlet, I use the normal httpresponse to return it (ie. not using rpc.send(rpcReq, rpcResp), should i?)

    Server code that outputs the data to the client
    Code:
    ....
    //response is of type HttpServletResponse passed in in doPost(...)	      
     response.setContentType("application/pdf");			
    
    OutputStream os = response.getOutputStream();
    
    ITextRenderer renderer = new ITextRenderer();
    renderer.setDocumentFromString(html);
    renderer.layout();
    renderer.createPDF(os); //writes to the output stream
    renderer.finishPDF();
    If i specify an RPCCallback, I can also see in the rawData variable that a PDF is returned.

    Should I trigger this thing differently from the client for my purpose?

    Any advice is welcome!
    Last edited by Sytematic; 30 Aug 2012, 05:51.

    #2
    Aha, just after posting this, I realized what might be wrong.

    My client code is now like this:

    Code:
    RPCRequest request = new RPCRequest();
    			request.setActionURL(GWT.getModuleBaseURL() + "sc/GeneratePdf");
    request.setHttpMethod("POST");
    request.setShowPrompt(false);
    request.setWillHandleError(true);
    request.setDownloadResult(true);
    request.setContentType("application/pdf");
    			
    Map<String, Object> params = new HashMap<String, Object>();
    			params.put("template","kitchenlist_template.html");
    params.put("pages", pages);
    params.put("placeholder", "__CONTENT__");
    request.setData(params);
    RPCManager.sendRequest(request);
    and this works for me!

    Comment

    Working...
    X