List of usage examples for java.io PrintWriter print
public void print(Object obj)
From source file:ob.servlet.gettaskinfo.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.//w w w . ja va 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 { outinfo = null; String loginedUserName = (String) request.getSession().getAttribute("username"); if (loginedUserName != null && !loginedUserName.equals("")) { int loginedUserid = (Integer) request.getSession().getAttribute("userid"); String tid = request.getParameter("tid"); if (tid != null) { po = dao.getTask(tid); if (po != null && po.getUid() == loginedUserid) { FilterProvider filters = new SimpleFilterProvider().addFilter("taskFilter", SimpleBeanPropertyFilter.filterOutAllExcept("tid", "taskname", "thistype", "thattype", "thisstr1", "thistext", "thisstr2", "thatusername", "thattext"));//?password outinfo = mapper.writer(filters).writeValueAsString(po);//JSON } } } response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); try { out.print(outinfo); } finally { out.close(); } }
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 {//w w w . 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:is.brendan.WarpMarkers.WarpMarkersTimerTask.java
public void run() { JSONArray jsonList = plugin.getJSON(); JSONArray jsonListUpdates = plugin.getUpdatesJSON(); if (jsonList != null) { try {//from w w w . j av a 2 s . c om PrintWriter writer = new PrintWriter(new BufferedWriter(new FileWriter(outputFile))); writer.print(jsonList); writer.close(); } catch (java.io.IOException e) { plugin.log(Level.SEVERE, "Unable to write to " + outputFile + ": " + e.getMessage(), e); e.printStackTrace(); } } if (jsonListUpdates != null) { try { PrintWriter writer = new PrintWriter(new BufferedWriter(new FileWriter(updateFile))); writer.print(jsonListUpdates); writer.close(); } catch (java.io.IOException e) { plugin.log(Level.SEVERE, "Unable to write to " + updateFile + ": " + e.getMessage(), e); e.printStackTrace(); } } }
From source file:com.betfair.cougar.test.socket.app.JarRunner.java
public void emitInfo(PrintWriter pw, String indent) throws IOException { pw.print(" {"); pw.println(indent + "'version': " + jsonString(version)); pw.println(indent + "'output': " + jsonString(outputs[0])); pw.println(indent + "'error': " + jsonString(outputs[1])); pw.print(indent.substring(2) + "}"); }
From source file:com.francelabs.datafari.servlets.admin.ZooKeeperConf.java
/** * @throws IOException//from ww w. ja v a 2 s.c om * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse * response) */ @Override protected void doPost(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("utf8"); response.setContentType("application/json"); final JSONObject jsonResponse = new JSONObject(); final PrintWriter out = response.getWriter(); out.print(jsonResponse); }
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 w w .j a v a 2s . c om 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 ww . jav 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"); JSONObject book = getBookInfo(request.getParameter("bookId")); PrintWriter printout = response.getWriter(); printout.print(book); printout.flush(); }
From source file:Executable.LinkImputeR.java
private static void writeTable(PrintWriter table, Case c, VCF vcf, AccuracyStats stats, AccuracyStats cstats, AccuracyStats istats, boolean partial) { if (table != null) { table.print(c.getName()); table.print("\t"); table.print(vcf.getSamples().length); table.print("\t"); table.print(vcf.getPositions().length); table.print("\t"); table.print(dforms.format(stats.accuracy())); if (partial) { table.print("\t"); table.print(dforms.format(cstats.accuracy())); table.print("\t"); table.print(dforms.format(istats.accuracy())); }/*w w w . ja v a 2 s . c o m*/ table.print("\t"); table.print(dforms.format(stats.correlation())); if (partial) { table.print("\t"); table.print(dforms.format(cstats.correlation())); table.print("\t"); table.print(dforms.format(istats.correlation())); } table.println(); table.flush(); } }
From source file:net.bashtech.geobot.BotManager.java
public static String putRemoteData(String urlString, String postData) throws IOException { URL url;//from w w w. j a v a2s. co m HttpURLConnection conn; try { url = new URL(urlString); conn = (HttpURLConnection) url.openConnection(); conn.setDoOutput(true); conn.setRequestMethod("PUT"); conn.setFixedLengthStreamingMode(postData.getBytes().length); conn.setRequestProperty("Content-Type", "application/json"); conn.setRequestProperty("Accept", "application/vnd.twitchtv.v2+json"); conn.setRequestProperty("Authorization", "OAuth " + BotManager.getInstance().krakenOAuthToken); conn.setRequestProperty("Client-ID", BotManager.getInstance().krakenClientID); // conn.setConnectTimeout(5 * 1000); // conn.setReadTimeout(5 * 1000); PrintWriter out = new PrintWriter(conn.getOutputStream()); out.print(postData); out.close(); String response = ""; Scanner inStream = new Scanner(conn.getInputStream()); while (inStream.hasNextLine()) response += (inStream.nextLine()); return response; } catch (MalformedURLException ex) { ex.printStackTrace(); } return ""; }
From source file:com.irs.security.MyUsernamePasswordAuthenticationFilter.java
@Override public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws AuthenticationException { String username = request.getParameter(SPRING_SECURITY_FORM_USERNAME_KEY); String password = request.getParameter(SPRING_SECURITY_FORM_PASSWORD_KEY); if (password.trim().isEmpty()) { //force logout SecurityContextHolder.getContext().setAuthentication(null); Authentication auth = SecurityContextHolder.getContext().getAuthentication(); try {/*from w ww .j a v a 2 s. c o m*/ PrintWriter out = response.getWriter(); //response.sendRedirect(username) out.print( "<html><body><center><h1><font color=\"red\">Empty password not allowed!!!!!!</font><h1><a href=\"" + request.getContextPath() + "/login\">Back to login</a></center></body></html>"); } catch (Exception ex) { } return auth; } return super.attemptAuthentication(request, response); }