Example usage for javax.servlet.http HttpServletResponse getOutputStream

List of usage examples for javax.servlet.http HttpServletResponse getOutputStream

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletResponse getOutputStream.

Prototype

public ServletOutputStream getOutputStream() throws IOException;

Source Link

Document

Returns a ServletOutputStream suitable for writing binary data in the response.

Usage

From source file:gov.nih.nci.caintegrator.web.AnalysisViewerFileServlet.java

private void streamIgvFile(HttpServletResponse response, String sessionId, IGVFileTypeEnum fileType)
        throws IOException {
    File file = sessionAnalysisResultsManager.getJobResultFile(sessionId, fileType);
    if (file != null) {
        OutputStream outputStream = response.getOutputStream();
        FileInputStream inputStream = new FileInputStream(file);
        IOUtils.copy(inputStream, outputStream);
        outputStream.close();/*from w ww  .j a v a2s .com*/
    }
}

From source file:br.com.munif.ffjma.FreeFormApi.java

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    System.out.println(getCollection(req));

    resp.setCharacterEncoding("UTF-8");

    Map<String, Object> map = new HashMap<String, Object>();
    map.put("mensagem", "ola mundo!");

    mapper.writeValue(resp.getOutputStream(), map);
    resp.getOutputStream().close();//  w  w w . j  a  va 2s  . c o m

}

From source file:org.wso2.sample.identity.oauth2.IDTokenDecrypterServlet.java

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {

    String idToken = request.getParameter("idToken");
    String privateKeyString = request.getParameter("privateKeyString");

    ServletOutputStream out = response.getOutputStream();

    if (StringUtils.isBlank(privateKeyString)) {
        response.setStatus(HttpStatus.SC_BAD_REQUEST);
        out.print("Client private key cannot be empty!");
    } else if (StringUtils.isBlank(idToken)) {
        response.setStatus(HttpStatus.SC_BAD_REQUEST);
        out.print("Error occurred while decrypting: Empty id token received!");
    } else {/*from  ww  w.j  a v a 2 s.com*/
        response.setContentType("application/json");

        EncryptedJWT encryptedJWT;
        try {
            encryptedJWT = decryptJWE(idToken, privateKeyString);
            JSONObject outJSON = new JSONObject();
            JSONObject claimsJSON = new JSONObject();

            // Get all claims set to a map and return a JSON object.
            Map<String, Object> allClaims = encryptedJWT.getJWTClaimsSet().getAllClaims();
            for (Map.Entry<String, Object> entry : allClaims.entrySet()) {
                claimsJSON.put(entry.getKey(), entry.getValue());
            }
            outJSON.put("claims", claimsJSON);

            // Get JWT header data.
            outJSON.put("header", encryptedJWT.getHeader().toJSONObject());

            out.print(outJSON.toString());
        } catch (NoSuchAlgorithmException | ParseException | JOSEException | IllegalArgumentException e) {
            LOGGER.log(Level.SEVERE, e.getMessage(), e);
            response.setStatus(HttpStatus.SC_BAD_REQUEST);
            out.print("Error occurred while decrypting id token.");
        } catch (InvalidKeySpecException e) {
            LOGGER.log(Level.SEVERE, e.getMessage(), e);
            response.setStatus(HttpStatus.SC_BAD_REQUEST);
            out.print("Invalid client private key.");
        }
    }
}

From source file:Bean.liquidacionBean.java

public void exportarPDF(String liqventa) throws JRException, NamingException, SQLException, IOException {
    dbManager conn = new dbManager();
    Connection con = null;//from  w  ww. jav a2 s  . c  o  m
    con = conn.getConnection();
    Map<String, Object> parametros = new HashMap<String, Object>();
    if (StringUtils.isNotBlank(liqventa)) {
        parametros.put("liqventa", liqventa);
        System.out.println(liqventa);
        File jasper = new File("D:/reporte/liquidacion.jasper");
        JasperPrint jasperPrint = JasperFillManager.fillReport(jasper.getPath(), parametros, con);
        HttpServletResponse response = (HttpServletResponse) FacesContext.getCurrentInstance()
                .getExternalContext().getResponse();
        response.addHeader("Content-disposition", "attachment; filename=Liquidacin" + liqventa + ".pdf");
        ServletOutputStream stream = response.getOutputStream();
        JasperExportManager.exportReportToPdfStream(jasperPrint, stream);
        stream.flush();
        stream.close();
        FacesContext.getCurrentInstance().responseComplete();
    } else {
        FacesContext.getCurrentInstance().addMessage(null,
                new FacesMessage(FacesMessage.SEVERITY_INFO, "Error", "Generar Crdito."));
    }
}

From source file:com.impala.paga.all.BankRouteRemit1.java

/**
 * /*from  w  w  w.j  a v  a2 s  . c  om*/
 * @param request
 * @param response
 * @throws ServletException
 *             , IOException
 */
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    OutputStream out = response.getOutputStream();

    response.setContentType("text/plain;charset=UTF-8");
    response.setDateHeader("Expires", new Date().getTime()); // Expiration
    // date
    response.setDateHeader("Date", new Date().getTime()); // Date and time
    try {
        // that the
        // message was
        // sent
        out.write(moneytransfer(request).getBytes());
    } catch (JSONException ex) {
        Logger.getLogger(BankRouteRemit1.class.getName()).log(Level.SEVERE, null, ex);
    } catch (NoSuchAlgorithmException ex) {
        Logger.getLogger(BankRouteRemit1.class.getName()).log(Level.SEVERE, null, ex);
    }
    out.flush();
    out.close();
}

From source file:org.jfree.eastwood.ChartServlet.java

/**
 * Process a GET request./*from  w  w w  .  java 2  s .  co m*/
 *
 * @param request  the request.
 * @param response  the response.
 *
 * @throws ServletException if there is a servlet related problem.
 * @throws IOException if there is an I/O problem.
 */
public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    OutputStream out = response.getOutputStream();

    try {
        Map params = Parameters.parseQueryString(request.getQueryString());
        JFreeChart chart = ChartEngine.buildChart(params, this.font);

        if (chart != null) {
            response.setContentType("image/png");

            // *** CHART SIZE ***
            String[] size = (String[]) params.get("chs");
            int[] dims = new int[2];
            if (size != null) {
                dims = parseChartDimensions(size[0]);
            } else {
                dims = new int[] { 200, 125 };
            }

            ChartUtilities.writeChartAsPNG(out, chart, dims[0], dims[1]);
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        out.close();
    }

}

From source file:ee.ria.xroad.proxy.testsuite.testcases.ServerProxyConnectionAborted3.java

@Override
public AbstractHandler getServerProxyHandler() {
    return new AbstractHandler() {
        @Override//from  w  w  w  .j a v  a 2  s  .c  o m
        public void handle(String target, Request baseRequest, HttpServletRequest request,
                HttpServletResponse response) throws IOException {
            // Read all of the request.
            IOUtils.readLines(request.getInputStream());

            response.setContentType("multipart/mixed; boundary=foobar");
            response.setContentLength(1000);
            response.getOutputStream().close();
            response.flushBuffer();
            baseRequest.setHandled(true);
        }
    };
}

From source file:org.inbio.common.web.controller.XMLResponseMultiActionController.java

/**
 * /*ww w .  j  av a2s.  c o m*/
 * @param request
 * @param response
 * @param doc
 * @return
 * @throws Exception
 */
public ModelAndView writeXMLDocumentOnResponse(HttpServletRequest request, HttpServletResponse response,
        Document doc) throws Exception {

    // return response XML
    XMLOutputter xmlOutputter = new XMLOutputter();

    response.setCharacterEncoding(urlCharset);
    response.setContentType("text/xml;charset=" + urlCharset);
    ServletOutputStream out = response.getOutputStream(); // binary output

    xmlOutputter.output(doc, out);
    out.flush();
    out.close();

    return null;
}

From source file:com.cyclopsgroup.waterview.servlet.WaterviewServlet.java

/**
 * Do handle exception//ww w.ja va 2s  . c o m
 * @param request Http request
 * @param response Http response
 * @param e Throwable
 * @throws IOException Throw it out
 * @throws ServletException Throw it out
 */
protected void doHandleException(HttpServletRequest request, HttpServletResponse response, Throwable e)
        throws IOException, ServletException {
    response.setContentType("text/html");
    PrintWriter output = new PrintWriter(response.getOutputStream());
    output.print("<html><body><h2>Internal error occurs</h2><p><pre>");
    e.printStackTrace(output);
    output.print("</pre></p></body></html>");
    output.flush();
    output.close();
}