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:net.mindengine.oculus.frontend.view.JsonView.java

@Override
protected void renderMergedOutputModel(Map model, HttpServletRequest request, HttpServletResponse response)
        throws Exception {
    ObjectMapper mapper = new ObjectMapper();
    mapper.writeValue(response.getOutputStream(), model.get("response"));
    response.setStatus(200);/*from   w ww  .  j  ava2  s  .  c o m*/
}

From source file:werecloud.api.view.JSONView.java

@Override
public void render(Map<String, ?> model, HttpServletRequest request, HttpServletResponse response)
        throws Exception {
    ServletOutputStream out = response.getOutputStream();
    if (model.containsKey("model")) {
        ObjectMapper mapper = new ObjectMapper();
        //use ISO-8601 dates instead of timestamp
        mapper.configure(SerializationConfig.Feature.WRITE_DATES_AS_TIMESTAMPS, false);
        mapper.configure(SerializationConfig.Feature.WRITE_NULL_PROPERTIES, outputNulls);
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        mapper.writeValue(bos, model.get("model"));
        response.setContentLength(bos.size());
        response.setContentType("application/json");
        out.write(bos.toByteArray());//from  w ww.jav  a 2  s.c o m
        return;
    }
    throw new Exception("Could not find model.");
}

From source file:net.hillsdon.reviki.web.handlers.StreamView.java

public void render(final HttpServletRequest request, final HttpServletResponse response) throws Exception {
    response.setContentType(_mimeType);//from   w  ww .  j  a v a2  s  .  c  om
    IOUtils.copy(_contents, response.getOutputStream());
}

From source file:com.ewcms.component.checkcode.web.ImageCaptchaServlet.java

private void responseImage(HttpServletResponse response, byte[] imageBytes) throws IOException {
    OutputStream stream = response.getOutputStream();
    stream.write(imageBytes);/*w  ww  .j ava2  s .  c  o m*/
    stream.flush();
    stream.close();
}

From source file:com.griddynamics.banshun.web.View.java

@Override
protected void renderMergedOutputModel(final Map<String, Object> model, final HttpServletRequest request,
        final HttpServletResponse response) throws Exception {
    response.setContentType("text/plain");
    response.setCharacterEncoding("UTF-8");
    response.getOutputStream().write(model.toString().getBytes());
    response.getOutputStream().close();//w w w  .  ja va 2s  . co m
}

From source file:com.thoughtworks.go.agent.testhelper.AgentBinariesServlet.java

protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    doHead(request, response);/* ww w  .j  a va2 s. co m*/
    resource.copyTo(response.getOutputStream());
}

From source file:action.ChartResult.java

@Override
public void execute(ActionInvocation invocation) throws Exception {

    ImageAction action = (ImageAction) invocation.getAction();
    HttpServletResponse response = ServletActionContext.getResponse();

    response.setContentType("image/png");

    OutputStream outputStream = response.getOutputStream();

    JFreeChart chart = action.getChart();
    int width = 500;
    int height = 350;
    ChartUtilities.writeChartAsPNG(outputStream, chart, width, height);
}

From source file:net.jadler.stubbing.server.jetty.JadlerHandler.java

private void insertResponseBody(final byte[] body, final HttpServletResponse response) throws IOException {
    if (body.length > 0) {
        final OutputStream os = response.getOutputStream();
        os.write(body);//from  w  w  w  . j ava 2s. c  o m
    }
}

From source file:com.googlecode.jsonrpc4j.spring.CompositeJsonServiceExporter.java

/**
 * {@inheritDoc}// w w  w.  j  a v a2 s .co  m
 */
public void handleRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    jsonRpcServer.handle(request, response);
    response.getOutputStream().flush();
}

From source file:org.cloudfoundry.practical.demo.web.controller.TimeoutController.java

@RequestMapping("/timeout/ajaxdrip")
public void ajax(HttpServletResponse response) throws IOException {
    ServletOutputStream outputStream = response.getOutputStream();
    this.logger.info("Long running task...");
    try {//  w  ww .j  av a 2 s. com
        for (int i = 1; i <= TOTAL_SECONDS_DELAY; i++) {
            Thread.sleep(ONE_SECOND);
            this.logger.info(" Thinking..." + i);
            outputStream.write('.');
            response.flushBuffer();
        }
    } catch (InterruptedException e) {
    }
    outputStream.write("Hello from the server".getBytes());
}