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:com.nominanuda.hyperapi.HttpClientHyperApiFactoryTest.java

@Test
public void testE() throws Exception {
    startServer(12000, new AbstractHandler() {
        public void handle(String uri, Request arg1, HttpServletRequest req, HttpServletResponse resp)
                throws IOException, ServletException {
            IOHelper io = new IOHelper();
            io.pipe(req.getInputStream(), resp.getOutputStream(), false, false);
        }// www .j a  va 2 s.  c o m
    });
    HttpCoreHelper httpCoreHelper = new HttpCoreHelper();
    HttpClient client = httpCoreHelper.createClient(10, 100000000, 100000000);
    HttpClientHyperApiFactory f = new HttpClientHyperApiFactory();
    f.setHttpClient(client);
    f.setUriPrefix("http://localhost:12000");
    TestHyperApi api = f.getInstance("", TestHyperApi.class);
    DataObject foo = new DataObjectImpl();
    foo.put("foo", "FOO");
    DataObject result = api.putFoo("BAR", "BAZ", foo);
    Assert.assertEquals("FOO", result.get("foo"));
}

From source file:edu.emory.library.tast.database.graphs.GraphsServlet.java

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

    HttpSession session = request.getSession();
    OutputStream stream = response.getOutputStream();

    int width = Integer.parseInt(request.getParameter("width"));
    int height = Integer.parseInt(request.getParameter("height"));

    JFreeChart chart = (JFreeChart) session.getAttribute(GraphsBean.SESSION_KEY_GRAPH);

    if (chart == null) {
        response.encodeRedirectURL("../../images/blank.png");
        return;/*from  ww w. j  a v  a2s.c  o m*/
    }

    response.setHeader("Cache-Control", "no-cache");
    response.setHeader("Cache-Control", "max-age=0");
    response.setHeader("Pragma", "no-cache");
    response.setDateHeader("Expires", 0);

    response.setContentType("image/png");
    ChartUtilities.writeChartAsPNG(stream, chart, width, height);

}

From source file:com.thinkgem.jeesite.modules.sso.web.IndexController.java

/**
 * ?? ???/*from  w w w .j  a v a2s.  c  om*/
 */
@Login(action = Action.Skip)
@ResponseBody
@RequestMapping("/verify")
public void verify(HttpServletResponse response) {
    try {
        String verifyCode = CaptchaUtil.outputImage(response.getOutputStream());
        System.out.println("??:" + verifyCode);
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.lixiaocong.rest.FileController.java

@RequestMapping(value = "/imagecode")
public void imagecode(HttpSession session, HttpServletResponse response) throws IOException {
    response.setContentType("image/png");
    OutputStream os = response.getOutputStream();
    ImageIO.write(codeService.getImage(session), "png", os);
}

From source file:net.sourceforge.fenixedu.presentationTier.Action.externalServices.ISTConnectDA.java

private void writeJSONObject(HttpServletResponse response, final JSONArray jsonObject) throws IOException {
    final ServletOutputStream outputStream = response.getOutputStream();
    outputStream.write(jsonObject.toJSONString().getBytes());
    outputStream.close();/*  w  ww.j  a  v a2  s.  c o m*/
}

From source file:info.magnolia.cms.servlets.ResourceDispatcher.java

/**
 * Send data as is.//ww w  .j ava  2  s  .  c  om
 *
 * @param is  Input stream for the resource
 * @param res HttpServletResponse as received by the service method
 * @throws IOException standard servlet exception
 */
private void sendUnCompressed(InputStream is, HttpServletResponse res) throws IOException {
    ServletOutputStream os = res.getOutputStream();
    byte[] buffer = new byte[8192];
    int read = 0;
    while ((read = is.read(buffer)) > 0) {
        os.write(buffer, 0, read);
    }
    os.flush();
    IOUtils.closeQuietly(os);
}

From source file:com.netflix.hystrix.dashboard.stream.EurekaInfoServlet.java

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

    String uri = request.getParameter("url");
    if (uri == null || "".equals(uri))
        response.getOutputStream().write("Error. You need supply a valid eureka URL ".getBytes());

    try {/*w  ww  .j av  a2s  .  c o  m*/
        response.setContentType("application/xml");
        response.setHeader("Content-Encoding", "gzip");
        IOUtils.copy(UrlUtils.readXmlInputStream(uri), response.getOutputStream());
    } catch (Exception e) {
        response.getOutputStream()
                .write(("Error. You need supply a valid eureka URL. Ex: " + e + "").getBytes());
    }

}

From source file:com.katropine.oauth.LogoutImpl.java

@Override
public void onLogoutSuccess(HttpServletRequest paramHttpServletRequest,
        HttpServletResponse paramHttpServletResponse, Authentication paramAuthentication)
        throws IOException, ServletException {
    removeaccess(paramHttpServletRequest);
    paramHttpServletResponse.getOutputStream().write("\n\tYou Have Logged Out successfully.".getBytes());

}

From source file:de.perdoctus.synology.jdadapter.controller.JdAdapter.java

@RequestMapping(value = "/crossdomain.xml", method = RequestMethod.GET)
public void allowCrossdomain(final HttpServletResponse resp) throws IOException {
    final OutputStream response = resp.getOutputStream();
    final InputStream input = getClass().getResourceAsStream("/crossdomain.xml");
    StreamUtils.copyThenClose(input, response);
}

From source file:com.haulmont.cuba.web.controllers.FileDownloadController.java

protected void downloadFromMiddlewareAndWriteResponse(FileDescriptor fd, HttpServletResponse response)
        throws IOException {
    ServletOutputStream os = response.getOutputStream();
    try (InputStream is = fileLoader.openStream(fd)) {
        IOUtils.copy(is, os);/*from   w  w w .  j  ava  2s. c  o  m*/
        os.flush();
    } catch (FileStorageException e) {
        log.error("Unable to load file from middleware", e);
        error(response);
    }
}