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:eu.europa.ejusticeportal.dss.controller.action.SigningAction.java

private void writeResponse(final PortalFacade portal, final HttpServletRequest request,
        final HttpServletResponse response) {
    try {/*ww w .  ja v  a  2  s . co  m*/
        response.setContentType("application/json");
        final OutputStream os = response.getOutputStream();
        final Object reqObject = getRequestObject(request);
        final Object resObject = getResponseObject(portal, request, reqObject);
        final DataWrapper w = new DataWrapper(getResponseString(resObject));
        final Gson gson = new Gson();
        os.write(gson.toJson(w).getBytes("UTF-8"));
        os.close();
    } catch (IOException e) {
        LOGGER.error("Error writeResponse", e);
        throw new SigningException(e);
    }
}

From source file:com.sivalabs.jcart.admin.web.controllers.ProductController.java

@GetMapping(value = "/products/images/{productId}")
public void showProductImage(@PathVariable String productId, HttpServletRequest request,
        HttpServletResponse response) {
    try {//from  w w w  .  j  a  v  a  2 s.c  o m
        FileSystemResource file = new FileSystemResource(IMAGES_DIR + productId + ".jpg");
        response.setContentType("image/jpg");
        copy(file.getInputStream(), response.getOutputStream());
        response.flushBuffer();
    } catch (IOException e) {
        log.error(e.getMessage(), e);
    }
}

From source file:istata.web.HtmlController.java

@RequestMapping("/graph")
public void graph(HttpServletResponse response) throws IOException {
    response.setContentType("image/png");

    stataService.saveCmd("/graph");
    File f = stataService.graph();

    InputStream in = new FileInputStream(f);
    IOUtils.copy(in, response.getOutputStream());
}

From source file:org.red5.server.net.servlet.StatisticsServlet.java

/** {@inheritDoc} */
@Override//from   w w  w . j ava 2s  .com
public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    // Process request with XML-RPC server
    byte[] result = server.execute(request.getInputStream());
    response.setContentType("text/xml");
    response.setContentLength(result.length);
    OutputStream out = response.getOutputStream();
    out.write(result);
    out.close();
}

From source file:com.adito.extensions.actions.GetApplicationFileAction.java

private void sendFile(InputStream in, long length, HttpServletResponse response) throws IOException {
    Util.noCache(response);/* w  w  w  .ja v  a2  s  .co m*/

    response.setHeader("Content-type", "application/octet-stream");
    response.setContentLength((int) length);
    try {

        Util.copy(in, response.getOutputStream());

    } catch (IOException ex) {
    } finally {
        Util.closeStream(in);
        Util.closeStream(response.getOutputStream());
    }

}

From source file:com.controlj.green.istat.web.BookmarkServlet.java

@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    //System.out.println("Area Servlet called at:"+new Date());

    resp.setHeader("Expires", "Wed, 01 Jan 2003 12:00:00 GMT");
    resp.setHeader("Cache-Control", "no-cache");
    ServletOutputStream out = resp.getOutputStream();
    try {//ww w. jav  a 2 s .  c om
        writeLocations(out, req.getParameterValues("bookmarks"), req);
    } catch (Exception e) {
        Logging.LOGGER.println("Unexpected exception:");
        e.printStackTrace(Logging.LOGGER);

        throw new ServletException(e);
    }
    /*
    out.println("[");
    out.println("{ display:'Main Conf Room', id:'mainconf'},");
    out.println("{ display:'Board Room', id:'boardroom'},");
    out.println("{ display:'Room 235', id:'room235'}");
    out.println("]");
    */
}

From source file:fr.esiea.windmeal.controller.provider.ProviderCtrl.java

@Secured("ROLE_USER")
@RequestMapping(value = "user/{ownerId}", method = RequestMethod.GET, produces = "application/json")
@ResponseBody/*from w ww .  j a  va 2s . c o  m*/
public void getAll(@PathVariable String ownerId, HttpServletResponse servletResponse)
        throws ServiceException, DaoException, IOException {

    LOGGER.info("[Controller] Querying FoodProvider list from the user " + ownerId);
    this.objectMapper = new ObjectMapper();
    objectMapper.writerWithView(FoodProvider.Views.LightView.class)
            .writeValue(servletResponse.getOutputStream(), providerService.getAllProviderFromUser(ownerId));
}

From source file:ke.co.tawi.babblesms.server.servlet.export.excel.inbox.ExportExcel.java

/**    
 *
 * @param request/*  ww w . j  a va  2  s  . c  o m*/
 * @param response
 * @throws ServletException, IOException
 * @throws java.io.IOException
 */
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    out = response.getOutputStream();
    response.setContentType("application/vnd.ms-excel");
    response.setHeader("Cache-Control", "cache, must-revalidate");
    response.setHeader("Pragma", "public");

    HttpSession session = request.getSession(false);

    int CurrentPage;
    List<IncomingLog> clog = new ArrayList<>();

    String dd = request.getParameter("ExportPageExcel");
    String AllPages = request.getParameter("ExportAllExcel");

    if (dd == null) {
        CurrentPage = 1;
    } else {
        CurrentPage = Integer.parseInt(dd);
    }

    pageno = (CurrentPage - 1) * PAGE_SIZE;

    String sessionEmail = (String) session.getAttribute(SessionConstants.ACCOUNT_SIGN_IN_KEY);
    Element element = accountsCache.get(sessionEmail);
    account = (Account) element.getObjectValue();

    String fileName = new StringBuffer(account.getUsername()).append(" ").append(SPREADSHEET_NAME).toString();

    response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");

    clog = getListDetails(CurrentPage, AllPages);
    createExcelSheets(clog);
}

From source file:org.energyos.espi.datacustodian.web.api.ApplicationInformationRESTController.java

@RequestMapping(value = Routes.ROOT_APPLICATION_INFORMATION_COLLECTION, method = RequestMethod.GET, produces = "application/atom+xml")
@ResponseBody/*from  www.ja va 2 s  . c o  m*/
public void index(HttpServletResponse response, @RequestParam Map<String, String> params)
        throws IOException, FeedException {

    response.setContentType(MediaType.APPLICATION_ATOM_XML_VALUE);
    exportService.exportApplicationInformations(response.getOutputStream(), new ExportFilter(params));
}

From source file:com.curl.orb.servlet.DefaultInstanceManagementFilter.java

protected void setFailedResponse(HttpServletResponse response, Throwable exception) {
    response.setContentType("application/octet-stream;charset=UTF-8");
    OutputStream ostream = null;/*from www .j a va 2s  .co m*/
    try {
        ostream = response.getOutputStream();
        serializer.serialize(new InstanceManagementResponse(new ExceptionContent(exception)), null, ostream);
        response.setStatus(200);
        log.info(exception.getMessage(), exception);
    } catch (InstanceManagementException e) {
        response.setStatus(500);
        log.debug(e.getMessage(), e);
    } catch (SerializerException e) {
        response.setStatus(500);
        log.debug(e.getMessage(), e);
    } catch (IOException e) {
        response.setStatus(500);
        log.debug(e.getMessage(), e);
    } finally {
        if (ostream != null) {
            try {
                ostream.close();
            } catch (IOException e) {
                // ignored
            }
        }
    }
}