Example usage for javax.servlet.http HttpServletResponse getWriter

List of usage examples for javax.servlet.http HttpServletResponse getWriter

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletResponse getWriter.

Prototype

public PrintWriter getWriter() throws IOException;

Source Link

Document

Returns a PrintWriter object that can send character text to the client.

Usage

From source file:com.boazlev.fnf.web.IndexerServlet.java

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/xml;charset=UTF-8");
    PrintWriter out = response.getWriter();
    out.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
    out.println("<?xml-stylesheet type=\"text/xsl\" href=\"out.xslt\"?>");
    out.println("<catalog>");

    DiskFileItemFactory factory = new DiskFileItemFactory();
    ServletFileUpload fileUpload = new ServletFileUpload(factory);
    try {/*from   ww  w.  j a v  a2 s  . c  o m*/
        FileItemIterator iterator = fileUpload.getItemIterator(request);
        while (iterator.hasNext()) {
            FileItemStream item = iterator.next();
            InputStream mathMLContent = item.openStream();
            if (!item.isFormField()) {
                Map<String, Integer> index = indexer.index(mathMLContent, "./lines.txt");
                for (Map.Entry<String, Integer> mapEntry : index.entrySet()) {
                    out.println("<cd>");
                    out.print("<index>");
                    out.print(mapEntry.getKey());
                    out.println("</index>");
                    out.print("<count>");
                    out.print(mapEntry.getValue());
                    out.println("</count>");
                    out.println("</cd>");
                }
            }
        }
    } catch (FileUploadException e) {
        throw new ServletException("Cannot parse multipart request.", e);
    }
    out.print("</catalog>");
}

From source file:com.cognifide.aet.rest.ConfigsServlet.java

private PrintWriter retrieveResponseWriter(HttpServletRequest req, HttpServletResponse resp) {
    PrintWriter printWriter = null;
    try {/*from w  w w.  j a v a  2s  . c  o m*/
        printWriter = resp.getWriter();
    } catch (IOException e) {
        LOGGER.error("error while getting response writer for request: '{}' and response: '{}'", req, resp, e);
    }
    return printWriter;
}

From source file:com.github.rabid_fish.proxy.servlet.SoapServlet.java

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

    PrintWriter writer = response.getWriter();

    if (request.getQueryString() != null && request.getQueryString().equals("wsdl")) {
        response.setStatus(HttpServletResponse.SC_OK);
        response.setContentType("text/xml");
        writeWsdl(writer);//from w  w w  . j  a  v a2  s . c  o  m
    } else {
        response.setStatus(HttpServletResponse.SC_NOT_FOUND);
        response.setContentType("text/html");
        writer.append("404: page not found");
    }

    writer.flush();
    writer.close();
}

From source file:com.myjeeva.spring.security.secureuri.SecureServerURI.java

/**
 * writes the Bad Request String in the Servlet response if condition falis
 * //from  ww  w.j  ava2  s  . com
 * @param res a {@link javax.servlet.http.HttpServletResponse} object
 * @throws IOException
 */
private void badRequest(HttpServletResponse res) throws IOException {
    res.setContentType("text/html");
    PrintWriter pw = res.getWriter();
    pw.write(BAD_REQUEST);
    pw.close();
}

From source file:com.adobe.acs.commons.oak.impl.EnsureOakIndexServlet.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) {

    try {//from  w w  w .  ja  v a 2  s  .c o  m

        response.setStatus(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
        response.getWriter().println("<pre>");
        response.getWriter().println();
        response.getWriter().println();
        response.getWriter().println("HTTP method GET is not supported by this URL");
        response.getWriter().println("Use HTTP POST to access this end-point");
        response.getWriter().println("--------------------------------------------");
        response.getWriter().println("HTTP POST /system/console/ensure-oak-index");
        response.getWriter().println(" Parameters");
        response.getWriter().println("   * force = true | false (optional; when blank defaults to false)");
        response.getWriter()
                .println("   * path = /abs/path/to/ensure/definition (optional; when blank indicates all)");
        response.getWriter().println();
        response.getWriter().println();
        response.getWriter().println(
                "Example: curl --user admin:admin --data \"force=true\" https://localhost:4502/system/console/ensure-oak-index");
        response.getWriter().println("</pre>");

    } catch (IOException e) {
        log.warn("Caught IOException while handling doGet() in the Ensure Oak Index Servlet.", e);
        response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    }
}

From source file:com.softwareaggov.messaging.simplesoapjms.client.web.SendSoapCall.java

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    resp.setContentType("text/html");
    PrintWriter out = resp.getWriter();

    out.write("<h1>" + req.getContextPath() + " - Sending SOAP Call</h1>");
    try {//from  w ww .  j av  a 2 s.co  m
        String callType = req.getParameter("calltype");
        SoapClientLocal soapJmsService = null;
        if (null != callType) {
            if ("oneway".equals(callType.toLowerCase()))
                soapJmsService = soapHttpClientOneWayService;
            else if ("twoway".equals(callType.toLowerCase()))
                soapJmsService = soapHttpClientTwoWayService;
            else
                throw new IllegalArgumentException("call type [" + callType + "] not supported.");
        } else {
            throw new IllegalArgumentException("call type [null] not supported.");
        }

        if (null == soapJmsService)
            throw new IllegalArgumentException(
                    "soapJmsService is null...should not be...check code or configs");

        String response = soapJmsService.callWS();

        String responseToDisplay = "";
        if (null != response) {
            if (response.toLowerCase().startsWith("<?xml")) {
                responseToDisplay = StringEscapeUtils.escapeXml10(response);
            } else {
                responseToDisplay = response;
            }
        } else {
            responseToDisplay = "null";
        }

        out.write("<p><b>messages sent successfully</b></p>");
        out.write(String.format("<div><p>Response:</p><p>%s</p></div>", responseToDisplay));

        out.close();
    } catch (Throwable exc) {
        log.error("Error Occurred", exc);
        throw new ServletException(exc);
    }
}

From source file:com.softwareaggov.messaging.simplesoapjms.client.web.SendSoapJmsCall.java

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    resp.setContentType("text/html");
    PrintWriter out = resp.getWriter();

    out.write("<h1>" + req.getContextPath() + " - Sending SOAP Call</h1>");
    try {/*from  ww w. j  ava 2s.c o m*/
        String callType = req.getParameter("calltype");
        SoapClientLocal soapJmsService = null;
        if (null != callType) {
            if ("oneway".equals(callType.toLowerCase()))
                soapJmsService = soapJmsClientOneWayService;
            else if ("twoway".equals(callType.toLowerCase()))
                soapJmsService = soapJmsClientTwoWayService;
            else
                throw new IllegalArgumentException("call type [" + callType + "] not supported.");
        } else {
            throw new IllegalArgumentException("call type [null] not supported.");
        }

        if (null == soapJmsService)
            throw new IllegalArgumentException(
                    "soapJmsService is null...should not be...check code or configs");

        String response = soapJmsService.callWS();

        String responseToDisplay = "";
        if (null != response) {
            if (response.toLowerCase().startsWith("<?xml")) {
                responseToDisplay = StringEscapeUtils.escapeXml10(response);
            } else {
                responseToDisplay = response;
            }
        } else {
            responseToDisplay = "null";
        }

        out.write("<p><b>messages sent successfully</b></p>");
        out.write(String.format("<div><p>Response:</p><p>%s</p></div>", responseToDisplay));

        out.close();
    } catch (Throwable exc) {
        log.error("Error Occurred", exc);
        throw new ServletException(exc);
    }
}

From source file:eionet.rpcserver.servlets.XmlRpcRouter.java

/**
 * Warning, if someone's trying to use GET.
 *//*from   w  w  w  .j ava  2 s.c  o  m*/
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
    res.setContentType("text/html");
    res.getWriter().write("<html><head><title>XML/RPC RPC Router</title></head>");
    res.getWriter().write("<body><h1>XML/RPC Router</h1>");
    res.getWriter().write(
            "<p>Sorry, I don't speak via HTTP GET- you have to use HTTP POST to talk to me</p></body></html>");
}

From source file:com.praktikum.praktikum4.ProdukServiceSpringJdbcTest.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./*  ww w .j  a v a2s . c o m*/
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    PrintWriter out = response.getWriter();
    try {
        /* TODO output your page here. You may use following sample code. */
        out.println("<!DOCTYPE html>");
        out.println("<html>");
        out.println("<head>");
        out.println("<title>Servlet ProdukServiceSpringJdbcTest</title>");
        out.println("</head>");
        out.println("<body>");
        out.println("<h1>Servlet ProdukServiceSpringJdbcTest at " + request.getContextPath() + "</h1>");
        out.println("</body>");
        out.println("</html>");
    } finally {
        out.close();
    }
}

From source file:io.github.chibat.selva.response.JsonResponse.java

public void execute(HttpServletRequest request, HttpServletResponse response, ServletContext servletContext)
        throws Exception {

    response.setStatus(this.status());
    response.setContentType(this.type());
    new ObjectMapper().writeValue(response.getWriter(), model);
    response.flushBuffer();/*from   ww w . j  av  a 2  s  . com*/
}