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:de.knurt.fam.service.pdf.handler.FamServicePDFHandler.java

@RequestMapping(value = "/generated.pdf", method = RequestMethod.POST)
public final ModelAndView generatePDF(HttpServletResponse response, HttpServletRequest request) {
    ServletOutputStream output = null;//w ww  .  j a  v a2 s .com
    FileInputStream input = null;
    try {
        File file2write = new HttpServletRequest2File().process(request);
        input = new FileInputStream(file2write);
        output = response.getOutputStream();

        response.setContentType("application/pdf;charset=UTF-8");
        response.setHeader("Content-Disposition", "attachment; filename=" + file2write.getName());

        int nob = IOUtils.copy(input, output);
        if (nob < 1) {
            Logger.getRootLogger().fatal("201204231353");
        }
    } catch (IOException ex) {
        Logger.getRootLogger().fatal("201105301032");
    } finally {
        IOUtils.closeQuietly(input);
        IOUtils.closeQuietly(output);
    }
    return null;
}

From source file:com.asual.summer.sample.web.TechnologyController.java

@RequestMapping("/image/{value}")
public void image(@PathVariable("value") String value, HttpServletResponse response) throws IOException {
    Image image = Technology.findImage(value);
    if (image != null) {
        response.setContentLength(image.getBytes().length);
        response.setContentType(image.getContentType());
        response.getOutputStream().write(image.getBytes());
    } else {//  ww  w  .j a va  2s .  c  o  m
        response.setStatus(HttpServletResponse.SC_NOT_FOUND);
    }
    response.getOutputStream().flush();
    response.getOutputStream().close();
}

From source file:org.ednovo.gooru.controller.ScreenshotController.java

/**
 * Get and check parameters// www .  j a  v  a2  s  . c o  m
 * 
 * @param sourceUrl
 *            (URL should be encoded)
 * @param width
 * @param height
 * @param request
 * @param response
 * @throws Exception
 */

@RequestMapping(method = RequestMethod.GET, value = "/snapshot/generate/{width}/{height}")
public void getScreenshot(@PathVariable(value = "width") int width, @PathVariable(value = "height") int height,
        @RequestParam(value = "SourceUrl", required = true) String sourceUrl, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    sourceUrl = URLDecoder.decode(sourceUrl, ENCODE_FORMAT);
    if (checkUrl(sourceUrl)) {
        response.setStatus(400);
        response.getWriter().append(INVALID_URL);
        return;
    } else {
        response.getOutputStream().write(getWebDriverUtil().generateScreenshot(sourceUrl, width, height));
    }

}

From source file:com.ewcms.publication.filter.render.TemplateSourceRender.java

/**
 * ?//from  w  ww . ja v a 2s  .  c om
 * 
 * @param response
 * @param uri   ?
 * @return
 * @throws IOException
 */
protected boolean output(HttpServletResponse response, Long siteId, String uri) throws IOException {
    TemplateSource source = templateSourcePublishDao.findByUri(siteId, uri);
    if (source == null) {
        logger.debug("TemplateSource is not exist,uri is {}", uri);
        return false;
    }
    IOUtils.write(source.getContent(), response.getOutputStream());
    response.flushBuffer();
    return true;
}

From source file:com.expressflow.servlets.ExecProcessServlet.java

public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
    UserService userService = UserServiceFactory.getUserService();
    User user = userService.getCurrentUser();
    if (user != null) {
        performRequest(request, response);
        try {/*from   w  ww . j a  v a 2  s. c om*/
            response.getOutputStream().println(new JSONObject().put("result", "success").toString());
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace(System.err);
        }
    } else {
        response.sendRedirect(response.encodeRedirectURL(userService.createLoginURL(request.getRequestURI())));
    }
}

From source file:com.hzc.framework.ssh.controller.WebUtil.java

/**
 * ?response??????com???//from  w w w . j  a  v  a  2s  . c  om
 *
 * @param contentType
 * @param attachFile
 * @throws IOException
 */
public static void write(String contentType, byte[] attachFile) throws RuntimeException {
    try {
        HttpServletResponse resp = ActionContext.getResp();
        resp.setContentType(contentType);
        ServletOutputStream outputStream = resp.getOutputStream();
        outputStream.write(attachFile);
        outputStream.flush();
        //            outputStream.close();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:com.pm.myshop.controller.FilesController.java

@RequestMapping("/pictures/{thumb}/{fileName}")
@ResponseBody//from   w w  w  .  ja  v  a2s . c  o  m
public void viewFiles(@PathVariable("fileName") String fileName, @PathVariable("thumb") String thumb,
        HttpServletRequest request, HttpServletResponse response) throws IOException {
    try {

        String path = request.getRealPath("/");

        response.setContentType("image/jpeg");

        InputStream inputStream = new FileInputStream(path + "../../files/" + thumb + "/" + fileName + ".jpg");
        IOUtils.copy(inputStream, response.getOutputStream());
        response.flushBuffer();

    } catch (IOException ex) {
        System.out.println(ex.getMessage());
        response.getWriter().print("File Not Found");
    }

}

From source file:net.sf.appstatus.web.pages.StatusPage.java

public void doGetHTML(StatusWebHandler webHandler, HttpServletRequest req, HttpServletResponse resp)
        throws UnsupportedEncodingException, IOException {

    setup(resp, "text/html");
    ServletOutputStream os = resp.getOutputStream();

    Map<String, String> valuesMap = new HashMap<String, String>();
    List<ICheckResult> results = webHandler.getAppStatus().checkAll(req.getLocale());
    Collections.sort(results);//w w w.j a v  a  2 s  . c  o m
    boolean statusOk = true;
    int statusCode = 200;
    for (ICheckResult r : results) {
        if (r.getCode() != ICheckResult.OK && r.isFatal()) {
            resp.setStatus(500);
            statusCode = 500;
            statusOk = false;
            break;
        }
    }

    valuesMap.put("statusOk", String.valueOf(statusOk));
    valuesMap.put("statusCode", String.valueOf(statusCode));

    // STATUS TABLE
    StrBuilder sbStatusTable = new StrBuilder();
    if (HtmlUtils.generateBeginTable(sbStatusTable, results.size())) {

        HtmlUtils.generateHeaders(sbStatusTable, "", "Group", "Name", "Description", "Code", "Resolution");

        for (ICheckResult r : results) {
            HtmlUtils.generateRow(sbStatusTable, getStatus(r), r.getGroup(), r.getProbeName(),
                    r.getDescription(), String.valueOf(r.getCode()), r.getResolutionSteps());
        }
        HtmlUtils.generateEndTable(sbStatusTable, results.size());
    }
    valuesMap.put("statusTable", sbStatusTable.toString());

    // PROPERTIES TABLE
    StrBuilder sbPropertiesTable = new StrBuilder();
    Map<String, Map<String, String>> properties = webHandler.getAppStatus().getProperties();
    if (HtmlUtils.generateBeginTable(sbPropertiesTable, properties.size())) {

        HtmlUtils.generateHeaders(sbPropertiesTable, "", "Group", "Name", "Value");

        for (Entry<String, Map<String, String>> cat : properties.entrySet()) {
            String category = cat.getKey();

            for (Entry<String, String> r : cat.getValue().entrySet()) {
                HtmlUtils.generateRow(sbPropertiesTable, Resources.STATUS_PROP, category, r.getKey(),
                        r.getValue());
            }

        }
        HtmlUtils.generateEndTable(sbPropertiesTable, properties.size());
    }
    valuesMap.put("propertiesTable", sbPropertiesTable.toString());
    String content = HtmlUtils.applyLayout(valuesMap, PAGECONTENTLAYOUT);

    valuesMap.clear();
    valuesMap.put("content", content);
    os.write(getPage(webHandler, valuesMap).getBytes(ENCODING));
}

From source file:BaselinePlotGenerator.java

public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    OutputStream out = response.getOutputStream();
    NssBaseline nssBaseline = new NssBaseline();
    String filename = "";
    try {// w ww .j  av  a  2  s .c om

        filename = request.getParameter("filename");
        nssBaseline.openFile(filename);
        nssBaseline.readAllData();

        JFreeChart chart = null;
        chart = createChart(filename, nssBaseline);
        if (chart != null) {
            response.setContentType("image/png");
            ChartUtilities.writeChartAsPNG(out, chart, 660, 400);
        }
    } catch (Exception e) {
        System.err.println("BaselinePlotGenerator: " + e + " for file: " + filename);
    } finally {
        out.close();
        nssBaseline.closeFile();
    }
}

From source file:org.fenixedu.spaces.ui.SpaceSearchController.java

@RequestMapping(value = "/photo/{spacePhoto}", method = RequestMethod.GET)
public void spacePhotoRender(@PathVariable SpacePhoto spacePhoto, HttpServletResponse response)
        throws IOException, UnavailableException {

    response.setContentType("image/jpeg");
    try (OutputStream outputStream = response.getOutputStream()) {
        outputStream.write(spacePhoto.getContent());
    }//from   w  w w.j  av a  2  s.c o m
}