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.cami.web.controller.uploadController.java

@RequestMapping(value = "/get/{value}", method = RequestMethod.GET)
public void get(HttpServletResponse response, @PathVariable String value) {
    try {//ww  w.  java  2s  .  c o m

        response.setContentType(ufile.type);
        response.setContentLength(ufile.length);
        FileCopyUtils.copy(ufile.bytes, response.getOutputStream());

    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:com.mockey.ui.JsonSchemaLoadSamplesServlet.java

@Override
protected void doGet(final HttpServletRequest req, final HttpServletResponse resp)
        throws ServletException, IOException {
    final int index = RND.nextInt(SAMPLE_DATA_SIZE);
    final JsonNode ret = SAMPLE_DATA.get(index);

    final OutputStream out = resp.getOutputStream();

    try {/*from w  ww. j ava2  s .  c  o m*/
        out.write(ret.toString().getBytes(Charset.forName("UTF-8")));
        out.flush();
    } finally {
        Closeables.closeQuietly(out);
    }
}

From source file:com.silverpeas.tags.servlets.WebFileServer.java

private void displayWarningHtmlCode(HttpServletResponse res) throws IOException {
    OutputStream out2 = res.getOutputStream();
    ResourceLocator resourceLocator = new ResourceLocator(
            "org.silverpeas.util.peasUtil.multiLang.fileServerBundle", "");
    try {//w w w  . j  av a  2 s .c  o  m
        out2.write(resourceLocator.getString("warning").getBytes(Charsets.UTF_8));
    } catch (Exception e) {
        SilverTrace.warn("peasUtil", "OnlineFileServer.displayWarningHtmlCode", "root.EX_CANT_READ_FILE",
                "warning properties");
    } finally {
        IOUtils.closeQuietly(out2);
    }
}

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

public void start() throws Exception {
    server = new Server();
    ServerConnector connector = new ServerConnector(server);
    connector.setPort(9090);/*from   w  w w .  j  av  a  2  s.  c o m*/
    server.addConnector(connector);

    SslContextFactory sslContextFactory = new SslContextFactory();
    sslContextFactory.setCertAlias("cruise");
    sslContextFactory.setKeyStoreResource(Resource.newClassPathResource("testdata/fake-server-keystore"));
    sslContextFactory.setKeyStorePassword("serverKeystorepa55w0rd");

    ServerConnector secureConnnector = new ServerConnector(server,
            new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()),
            new HttpConnectionFactory(new HttpConfiguration()));
    secureConnnector.setPort(9091);
    server.addConnector(secureConnnector);

    WebAppContext wac = new WebAppContext(".", "/go");
    ServletHolder holder = new ServletHolder();
    holder.setServlet(new HttpServlet() {
        @Override
        protected void doGet(HttpServletRequest req, HttpServletResponse resp)
                throws ServletException, IOException {
            resp.getOutputStream().println("Hello");
        }
    });
    wac.addServlet(holder, "/hello");
    addFakeAgentBinaryServlet(wac, "/admin/agent", TEST_AGENT);
    addFakeAgentBinaryServlet(wac, "/admin/agent-launcher.jar", TEST_AGENT_LAUNCHER);
    addFakeAgentBinaryServlet(wac, "/admin/agent-plugins.zip", TEST_AGENT_PLUGINS);
    addFakeAgentBinaryServlet(wac, "/admin/tfs-impl.jar", TEST_TFS_IMPL);
    addlatestAgentStatusCall(wac);
    addDefaultServlet(wac);
    server.setHandler(wac);
    server.setStopAtShutdown(true);
    server.start();
}

From source file:com.webtide.jetty.load.generator.web.UploadServlet.java

@Override
protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    //Path tmp = Files.createTempFile( "loadgenerator", ".jetty" );
    //try (OutputStream outputStream = Files.newOutputStream( tmp ))
    //{/*from   www  .  j a  v  a2s  . c o m*/
    IOUtils.copy(req.getInputStream(), resp.getOutputStream());
    //}

}

From source file:eu.earthobservatory.org.StrabonEndpoint.BrowseBean.java

/**
 * Processes the request made by a client of the endpoint that uses it as a
 * service./*from  w ww .  ja v a2s.c o m*/
 * 
 * @param request
 * @param response
 * @throws IOException
 */
private void processRequest(HttpServletRequest request, HttpServletResponse response) throws IOException {
    ServletOutputStream out = response.getOutputStream();

    // get the stSPARQL Query Result format (we check only the Accept
    // header)
    stSPARQLQueryResultFormat format = stSPARQLQueryResultFormat.forMIMEType(request.getHeader("accept"));

    // get the query
    String query = request.getParameter("query");

    // check for required parameters
    if (format == null || query == null) {
        response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
        out.print(ResponseMessages.getXMLHeader());
        out.print(ResponseMessages.getXMLException(PARAM_ERROR));
        out.print(ResponseMessages.getXMLFooter());

    } else {
        // decode the query
        query = URLDecoder.decode(request.getParameter("query"), "UTF-8");

        response.setContentType(format.getDefaultMIMEType());
        try {
            strabonWrapper.query(query, format.getName(), out);
            response.setStatus(HttpServletResponse.SC_OK);

        } catch (Exception e) {
            response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
            out.print(ResponseMessages.getXMLHeader());
            out.print(ResponseMessages.getXMLException(e.getMessage()));
            out.print(ResponseMessages.getXMLFooter());
        }
    }

    out.flush();
}

From source file:org.vbossica.springbox.metrics.ThreadDumpController.java

@RequestMapping(value = "/metrics/threaddump", method = RequestMethod.GET)
protected void doGet(HttpServletResponse resp) throws ServletException, IOException {
    resp.setContentType("text/plain");
    resp.setHeader("Cache-Control", "must-revalidate,no-cache,no-store");
    resp.setStatus(HttpServletResponse.SC_OK);
    OutputStream output = resp.getOutputStream();
    try {/*from w  ww  .java  2 s  .  com*/
        threadDump.dump(output);
    } finally {
        output.close();
    }
}

From source file:codes.thischwa.c5c.requestcycle.response.mode.Prieview.java

@Override
@JsonIgnore//from   ww  w  . ja v  a 2s. com
public void write(HttpServletResponse resp) throws IOException {
    String contentType = contentTypes.getContentTypeFor(fullPath);
    resp.setHeader("Content-Type", contentType);
    resp.setHeader("Content-Length", String.valueOf(contentLength));
    IOUtils.copy(in, resp.getOutputStream());
}

From source file:com.impala.servlet.Balance.java

/**
 * //from ww  w  .j  a  va  2  s  .co m
 * @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(Remit.class.getName()).log(Level.SEVERE, null, ex);
    }
    out.flush();
    out.close();
}

From source file:edu.cornell.mannlib.vitro.webapp.controller.api.VitroApiServlet.java

private PrintWriter getWriter(HttpServletResponse resp) throws IOException {
    try {/*  ww  w. j  a v  a 2  s .  c o  m*/
        return resp.getWriter();
    } catch (IllegalStateException e) {
        return new PrintWriter(new OutputStreamWriter(resp.getOutputStream()));
    }
}