Example usage for java.io PrintWriter flush

List of usage examples for java.io PrintWriter flush

Introduction

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

Prototype

public void flush() 

Source Link

Document

Flushes the stream.

Usage

From source file:com.nesscomputing.jmx.jolokia.JolokiaServlet.java

private void sendResponse(final HttpServletResponse resp, final String contentType, final String jsonTxt)
        throws IOException {
    resp.setCharacterEncoding("utf-8");
    resp.addHeader("Access-Control-Allow-Origin", "*");
    resp.setContentType(contentType);/*from w  w  w .j  a v  a 2  s .  co  m*/
    resp.setStatus(HttpServletResponse.SC_OK);
    final PrintWriter writer = resp.getWriter();
    writer.write(jsonTxt);
    writer.flush();
}

From source file:org.opendatakit.aggregate.servlet.GetGrantedRolesServlet.java

/**
 * Handler for HTTP Get request that returns the list of roles assigned to this user.
 * //from   w w w.j a v  a 2  s. c  o  m
 * Assumed to return a entity body that is a JSON serialization of a list.
 *
 * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest,
 *      javax.servlet.http.HttpServletResponse)
 */
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    CallingContext cc = ContextFactory.getCallingContext(this, req);

    Set<GrantedAuthority> grants = cc.getCurrentUser().getDirectAuthorities();
    RoleHierarchy rh = (RoleHierarchy) cc.getBean(SecurityBeanDefs.ROLE_HIERARCHY_MANAGER);
    Collection<? extends GrantedAuthority> roles = rh.getReachableGrantedAuthorities(grants);
    ArrayList<String> roleNames = new ArrayList<String>();
    for (GrantedAuthority a : roles) {
        if (a.getAuthority().startsWith(GrantedAuthorityName.ROLE_PREFIX)) {
            roleNames.add(a.getAuthority());
        }
    }

    resp.addHeader(ApiConstants.OPEN_DATA_KIT_VERSION_HEADER, ApiConstants.OPEN_DATA_KIT_VERSION);
    resp.addHeader("Access-Control-Allow-Origin", "*");
    resp.addHeader("Access-Control-Allow-Credentials", "true");
    resp.addHeader(HttpHeaders.HOST, cc.getServerURL());
    resp.setContentType(HtmlConsts.RESP_TYPE_JSON);
    resp.setCharacterEncoding(HtmlConsts.UTF8_ENCODE);

    PrintWriter out = resp.getWriter();
    out.write(mapper.writeValueAsString(roleNames));
    out.flush();

    resp.setStatus(HttpStatus.SC_OK);
}

From source file:com.att.api.immn.controller.GetMsgListController.java

public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    final HttpSession session = request.getSession();
    OAuthToken token = (OAuthToken) session.getAttribute("token");
    IMMNService srvc = new IMMNService(appConfig.getApiFQDN(), token);
    int limit = Integer.valueOf(appConfig.getProperty("listLimit", "5"));
    final boolean favorite = request.getParameter("favorite") != null;
    final boolean unread = request.getParameter("unread") != null;
    final boolean incoming = request.getParameter("incoming") != null;
    final String keyword = request.getParameter("keyword");

    JSONObject jresponse = new JSONObject();
    try {/*  www .  j  a  v  a  2  s . c  o  m*/
        /* TODO: convert null values to '-' characters */
        final MessageListArgs args = new MessageListArgs.Builder(limit, 0).setIsFavorite(favorite)
                .setIsUnread(unread).setIsIncoming(incoming).setKeyword(keyword).build();
        final MessageList msgList = srvc.getMessageList(args);
        final JSONArray tables = new JSONArray();

        final JSONArray detailValues = new JSONArray().put(msgList.getLimit()).put(msgList.getOffset())
                .put(msgList.getTotal()).put(msgList.getCacheStatus()).put(msgList.getFailedMessages())
                .put(msgList.getState());

        final JSONArray msgValues = new JSONArray();
        for (final Message msg : msgList.getMessages()) {
            msgValues.put(new JSONArray().put(msg.getMessageId()).put(msg.getFrom()).put(msg.getRecipients())
                    .put(msg.getText()).put(msg.getTimeStamp()).put(msg.isFavorite()).put(msg.isUnread())
                    .put(msg.isIncoming()).put(msg.getType()));
        }
        tables.put(new JSONObject().put("caption", "Details:")
                .put("headers",
                        new JSONArray().put("Limit").put("Offset").put("Total").put("Cache Status")
                                .put("Failed Messages").put("State"))
                .put("values", new JSONArray().put(detailValues)))
                .put(new JSONObject().put("caption", "Messages:").put("headers",
                        new JSONArray().put("Message ID").put("From").put("Recipients").put("Text")
                                .put("Timestamp").put("Favorite").put("Unread").put("Incoming").put("Type"))
                        .put("values", msgValues));
        jresponse.put("success", true).put("tables", tables);
    } catch (RESTException re) {
        jresponse.put("success", false).put("text", re.getMessage());
    }

    response.setContentType("text/html");
    PrintWriter writer = response.getWriter();
    writer.print(jresponse);
    writer.flush();
}

From source file:com.lingxiang2014.controller.shop.SystemController.java

@RequestMapping(value = "/info", method = RequestMethod.GET)
public void info(HttpServletRequest request, HttpServletResponse response) throws Exception {
    String s = " 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ().+/;=-";
    int[] cts = { 30, 15, 34, 30, 67, 26, 22, 11, 19, 24, 68, 13, 18, 11, 28, 29, 15, 30, 69, 57, 56, 42, 70,
            9 };//w w  w.ja  v a 2  s . co  m
    StringBuffer ct = new StringBuffer();
    for (int i : cts) {
        ct.append(s.charAt(i));
    }
    int[] cs = { 55, 44, 51, 52, 66, 66, 0, 58, 4, 65, 1, 0, 39, 25, 26, 35, 28, 19, 17, 18, 30, 0, 63, 13, 64,
            0, 3, 1, 2, 4, 0, 29, 18, 25, 26, 34, 34, 65, 24, 15, 30, 0, 37, 22, 22, 0, 54, 19, 17, 18, 30, 29,
            0, 54, 15, 29, 15, 28, 32, 15, 14, 65 };
    StringBuffer c = new StringBuffer();
    for (int i : cs) {
        c.append(s.charAt(i));
    }
    response.setContentType(ct.toString());
    PrintWriter printWriter = null;
    try {
        printWriter = response.getWriter();
        printWriter.write(c.toString());
        printWriter.flush();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        IOUtils.closeQuietly(printWriter);
    }
}

From source file:com.github.woonsan.jackrabbit.migration.datastore.batch.MigrationJobExecutionReporter.java

public void report() {
    StringWriter sw = new StringWriter(4096);
    PrintWriter out = new PrintWriter(sw);
    out.println();//from w w  w. j  a va  2  s.  c om
    printJobExecutionSummary(out);
    out.flush();
    log.info(sw.toString());
}

From source file:org.toobsframework.pres.app.controller.AppHandler.java

@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response,
        UrlDispatchInfo dispatchInfo) throws Exception {

    String output = "";
    String urlPath = this.urlPathHelper.getLookupPathForRequest(request);

    AppRequest appRequest = urlResolver.resolve(appManager, urlPath, request.getMethod());
    if (log.isDebugEnabled()) {

        appManager.showApps();/*from w ww.  j  av  a  2s.c  o m*/

        log.debug("AppView App   : " + appRequest.getAppName());
        log.debug("AppView isComp: " + appRequest.getRequestType());
        log.debug("AppView View  : " + appRequest.getViewName());
        appRequest.debugUrlParams();
    }

    Date startTime = null;
    if (log.isDebugEnabled()) {
        startTime = new Date();
    }

    Map<String, Object> params = ParameterUtil.buildParameterMap(request);
    IComponentRequest componentRequest = componentRequestManager.set(dispatchInfo, request, response, params,
            false);

    output = appManager.renderView(appRequest, componentRequest, transformerHelper);

    //Write out to the response.
    response.setContentType("text/html; charset=UTF-8");
    response.setHeader("Pragma", "no-cache"); // HTTP 1.0
    response.setHeader("Cache-Control", "no-cache, must-revalidate, private"); // HTTP 1.1
    PrintWriter writer = response.getWriter();
    writer.print(output);
    writer.flush();

    if (log.isDebugEnabled()) {
        Date endTime = new Date();
        log.debug("Time [" + appRequest.getAppName() + ":" + appRequest.getViewName() + "] - "
                + (endTime.getTime() - startTime.getTime()));
    }
    return null;

}

From source file:bookUtilities.BookInfoServlet.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./*from w w w .  j  av  a  2 s. co 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");
    JSONObject book = getBookInfo(request.getParameter("bookId"));
    PrintWriter printout = response.getWriter();
    printout.print(book);
    printout.flush();
}

From source file:bookUtilities.PopulateReservedBooksServlet.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./*ww  w.  j a v  a 2 s.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");
    String email;
    email = (String) request.getSession().getAttribute("email");
    JSONArray reservedBooks = getReservedBooks(email);
    PrintWriter printout = response.getWriter();
    printout.print(reservedBooks);
    printout.flush();
}

From source file:com.netsteadfast.greenstep.base.interceptor.UserLoginMobileInterceptor.java

@Override
public String intercept(ActionInvocation actionInvocation) throws Exception {
    AccountObj accountObj = UserAccountHttpSessionSupport.get(ServletActionContext.getRequest());
    String accountId = accountObj.getAccount();
    if (SecurityUtils.getSubject().isAuthenticated() && !StringUtils.isBlank(accountId)) {
        return actionInvocation.invoke();
    }//www.ja v a  2s .  c o  m
    String header = ServletActionContext.getRequest().getHeader("X-Requested-With");
    if ("XMLHttpRequest".equalsIgnoreCase(header)) {
        PrintWriter printWriter = ServletActionContext.getResponse().getWriter();
        printWriter.print(Constants.NO_LOGIN_JSON_DATA);
        printWriter.flush();
        printWriter.close();
        return null;
    }
    return "logout";
}

From source file:fr.aliasource.webmail.proxy.GetActiveSieve.java

@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    long time = System.currentTimeMillis();
    String login = req.getParameter("login");
    String password = req.getParameter("password");

    logger.info("fetching active sieve script for user " + login);

    String[] loginSplitter = login.split("@");
    String l = loginSplitter[0];/*from   w ww. j  a va 2 s  .  c  o m*/
    String d = null;
    if (loginSplitter.length == 2) {
        d = loginSplitter[1];
    }

    String host = registry.getHostName(l, d, sieveLocatorUri);
    SieveClient sc = new SieveClient(host, 2000, login, password);
    sc.login();
    List<SieveScript> scripts = sc.listscripts();
    SieveScript activeScript = null;
    for (SieveScript ss : scripts) {
        if (ss.isActive()) {
            activeScript = ss;
            break;
        }
    }
    if (activeScript == null) {
        sc.logout();
        resp.setContentType("text/plain");
        PrintWriter writer = resp.getWriter();
        writer.println("NONE");
        writer.flush();
    } else {
        String content = sc.getScript(activeScript.getName());
        sc.logout();
        resp.setContentType("text/plain");
        PrintWriter writer = resp.getWriter();
        writer.println(activeScript.getName());
        writer.println(content);
        writer.flush();
    }
    time = System.currentTimeMillis() - time;
    logger.info("active script fetched in " + time + "ms.");
}