Example usage for java.io PrintWriter write

List of usage examples for java.io PrintWriter write

Introduction

In this page you can find the example usage for java.io PrintWriter write.

Prototype

public void write(String s) 

Source Link

Document

Writes a string.

Usage

From source file:cn.vlabs.umt.ui.servlet.UMTPublicKeyServiceServlet.java

public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    UMTCredential cred = (UMTCredential) factory.getBean("UMTCredUtil");
    PublicKeyEnvelope opublickey = new PublicKeyEnvelope();
    opublickey.setAppId(cred.getUMTId());
    Date month = DateUtils.addMonths(new Date(cred.getCreateTime()), 1);
    opublickey.setValidTime(DateFormatUtils.format(month, "yyyy-MM-dd hh:mm:ss"));
    opublickey.setPublicKey(HexUtil.toHexString(cred.getUMTKey().getRSAPublic().getEncoded()));
    response.setContentType("text/xml");
    response.setCharacterEncoding("UTF-8");
    PrintWriter out = response.getWriter();
    out.write(opublickey.toXML());
    out.flush();/*from www. jav  a  2s .  c  o m*/
    out.close();

}

From source file:net.sf.jasperreports.web.servlets.RequirejsConfigServlet.java

@Override
public void service(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {
    response.setContentType("text/javascript; charset=UTF-8");
    setNoExpire(response);/*from   w w  w .  j  av a  2 s.c om*/

    JasperReportsContext jrContext = getJasperReportsContext();
    DefaultWebRequestContext webRequestContext = new DefaultWebRequestContext();
    webRequestContext.setJasperReportsContext(jrContext);
    webRequestContext.setRequest(request);

    RequirejsConfigCreator configCreator = RequirejsConfigCreator.getInstance(webRequestContext);
    String requirejsConfig = configCreator.getRequirejsConfig();

    PrintWriter out = response.getWriter();
    out.write(requirejsConfig);
}

From source file:com.emc.ecs.sync.cli.CliHelper.java

public static String longHelp() {
    StringWriter helpWriter = new StringWriter();
    PrintWriter pw = new PrintWriter(helpWriter);
    HelpFormatter fmt = new HelpFormatter();
    fmt.setWidth(79);/*ww w  . j av a2  s  .  co  m*/

    // main CLI options
    Options options = ConfigUtil.wrapperFor(CliConfig.class).getOptions();

    // sync options
    for (Option o : ConfigUtil.wrapperFor(SyncOptions.class).getOptions().getOptions()) {
        options.addOption(o);
    }

    // Make sure we do CommonOptions first
    String usage = "java -jar ecs-sync.jar -source <source-uri> [-filters <filter1>[,<filter2>,...]] -target <target-uri> [options]";
    fmt.printHelp(pw, fmt.getWidth(), usage, "Common options:", options, fmt.getLeftPadding(),
            fmt.getDescPadding(), null);

    pw.print("\nAvailable plugins are listed below along with any custom options they may have\n");

    // Do the rest
    for (ConfigWrapper<?> storageWrapper : ConfigUtil.allStorageConfigWrappers()) {
        pw.write('\n');
        pw.write(String.format("%s (%s)\n", storageWrapper.getLabel(), storageWrapper.getUriPrefix()));
        fmt.printWrapped(pw, fmt.getWidth(), 4, "    " + storageWrapper.getDocumentation());
        fmt.printWrapped(pw, fmt.getWidth(), 4,
                "    NOTE: Storage options must be prefixed by source- or target-, depending on which role they assume");
        fmt.printOptions(pw, fmt.getWidth(), storageWrapper.getOptions(), fmt.getLeftPadding(),
                fmt.getDescPadding());
    }
    for (ConfigWrapper<?> filterWrapper : ConfigUtil.allFilterConfigWrappers()) {
        pw.write('\n');
        pw.write(String.format("%s (%s)\n", filterWrapper.getLabel(), filterWrapper.getCliName()));
        fmt.printWrapped(pw, fmt.getWidth(), 4, "    " + filterWrapper.getDocumentation());
        fmt.printOptions(pw, fmt.getWidth(), filterWrapper.getOptions(), fmt.getLeftPadding(),
                fmt.getDescPadding());
    }

    return helpWriter.toString();
}

From source file:com.parleys.server.frontend.web.ipad.filters.LoginFilter.java

private void writeUserId(final PrintWriter writer, final Long userId) {
    writer.write("{\"error\": false, \"message\": null, \"userId\": " + userId + "}");
}

From source file:de.undercouch.gradle.tasks.download.ContentEncodingTest.java

@Override
protected Handler[] makeHandlers() throws IOException {
    ContextHandler contentEncodingHandler = new ContextHandler("/" + CONTENT_ENCODING) {
        @Override//from   ww w .  jav a 2s  .co m
        public void handle(String target, HttpServletRequest request, HttpServletResponse response,
                int dispatch) throws IOException, ServletException {
            response.setStatus(200);
            if (contentEncoding != null) {
                response.setHeader("Content-Encoding", contentEncoding);
            }
            PrintWriter rw = response.getWriter();
            rw.write("ce: " + String.valueOf(contentEncoding));
            rw.close();
        }
    };
    return new Handler[] { contentEncodingHandler };
}

From source file:net.sourceforge.jwebunit.tests.util.HeadersServlet.java

protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    out.write(HtmlHelper.getStart("Received headers"));
    out.write("<h1>Received headers</h1>\n<p>Headers are:<br/>");
    /*//from w w  w. j a v  a2  s .  c o m
     * Prints headers as name=[value] separated
     * by <BR/>
     */
    java.util.Enumeration headers = request.getHeaderNames();
    for (; headers.hasMoreElements();) {
        String h = headers.nextElement().toString();
        String v = request.getHeader(h);
        out.write(h + "=[" + v);
        if (headers.hasMoreElements()) {
            out.write("]<br/>\n");
        }
    }
    out.write("]</p>\n");
    String ref = request.getHeader("Referer");
    if (ref == null) {
        if (request.getParameterValues("myReferer") != null) {
            ref = request.getParameterValues("myReferer")[0];
        }
    }
    out.write(HtmlHelper.getLinkParagraph("return", ref));
    out.write(HtmlHelper.getEnd());
}

From source file:org.tec.webapp.web.view.JSONView.java

/**
 * {@inheritDoc}/*w w  w  .  java  2  s  . c  o m*/
 */
@Override()
protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    try {
        JSONSerializable json = (JSONSerializable) model.get(JSONModelAndView.ERROR_KEY);

        if (json != null) {
            response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "failed to process response");
        } else {
            json = (JSONSerializable) model.get(JSONModelAndView.JSON_KEY);

            if (json != null) {
                if (mLogger.isDebugEnabled()) {
                    mLogger.debug("JSON Response\n" + json.toJSON());
                }
                response.setContentType(MimeTypeUtils.APPLICATION_JSON_VALUE);
                PrintWriter pw = response.getWriter();
                pw.write(json.toJSON());
                pw.flush();
            } else // null json for controllers that usurp the response or didn't intend to
            {
                mLogger.warn("null json object");
            }
        }
    } catch (Exception e) {
        mLogger.error("error", e);
        response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "failed to process response");
    }
}

From source file:pl.fraanek.caspresentation.client.springsecurity.ProxyTicketSampleServlet.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    // NOTE: The CasAuthenticationToken can also be obtained using SecurityContextHolder.getContext().getAuthentication()
    final CasAuthenticationToken token = (CasAuthenticationToken) request.getUserPrincipal();
    // proxyTicket could be reused to make calls to to the CAS service even if the target url differs
    final String proxyTicket = token.getAssertion().getPrincipal().getProxyTicketFor(targetUrl);

    // Make a remote call to ourself. This is a bit silly, but it works well to demonstrate how to use proxy tickets.
    final String serviceUrl = targetUrl + "?ticket=" + URLEncoder.encode(proxyTicket, "UTF-8");
    String proxyResponse = CommonUtils.getResponseFromServer(serviceUrl, "UTF-8");

    // modify the response and write it out to inform the user that it was obtained using a proxy ticket.
    proxyResponse = proxyResponse.replaceFirst("Secure Page", "Secure Page using a Proxy Ticket");
    proxyResponse = proxyResponse.replaceFirst("<p>",
            "<p>This page is rendered by " + getClass().getSimpleName()
                    + " by making a remote call to the Secure Page using a proxy ticket (" + proxyTicket
                    + ") and inserts this message. ");
    final PrintWriter writer = response.getWriter();
    writer.write(proxyResponse);
}

From source file:com.wx.spring.controller.UserController1.java

@RequestMapping("/delUser")
public void delUser(String id, HttpServletResponse response) {

    String result = "{\"result\":\"error\"}";
    Customer removeCustomer = userManager.findCustomerById(id);
    if (userManager.removeCustomer(removeCustomer)) {
        result = "{\"result\":\"success\"}";
    }/*from  ww w. ja v a2 s  .c  o  m*/

    response.setContentType("application/json");

    try {
        PrintWriter out = response.getWriter();
        out.write(result);
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.xinlei.core.app.cas.web.ProxyTicketSampleServlet.java

@Override
public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    // NOTE: The CasAuthenticationToken can also be obtained using
    // SecurityContextHolder.getContext().getAuthentication()
    final CasAuthenticationToken token = (CasAuthenticationToken) request.getUserPrincipal();
    // proxyTicket could be reused to make calls to to the CAS service even if the
    // target url differs
    final String proxyTicket = token.getAssertion().getPrincipal().getProxyTicketFor(targetUrl);

    // Make a remote call to ourselves. This is a bit silly, but it works well to
    // demonstrate how to use proxy tickets.
    final String serviceUrl = targetUrl + "?ticket=" + URLEncoder.encode(proxyTicket, "UTF-8");
    String proxyResponse = CommonUtils.getResponseFromServer(new URL(serviceUrl),
            new HttpsURLConnectionFactory(), "UTF-8");

    // modify the response and write it out to inform the user that it was obtained
    // using a proxy ticket.
    proxyResponse = proxyResponse.replaceFirst("Secure Page", "Secure Page using a Proxy Ticket");
    proxyResponse = proxyResponse.replaceFirst("<p>",
            "<p>This page is rendered by " + getClass().getSimpleName()
                    + " by making a remote call to the Secure Page using a proxy ticket (" + proxyTicket
                    + ") and inserts this message. ");
    response.setContentType("text/html;charset=UTF-8");
    final PrintWriter writer = response.getWriter();
    writer.write(proxyResponse);
}