List of usage examples for java.io PrintWriter print
public void print(Object obj)
From source file:grails.plugins.sitemapper.impl.XmlSitemapWriter.java
private void writeIndexExtry(PrintWriter writer, String serverUrl, String mapperName, String lastMod) { writer.print(SITEMAP_OPEN); writer.print(String.format("<loc>%s/%s.%s.%s</loc>", serverUrl, path, mapperName, extension)); writer.print(String.format("<lastmod>%s</lastmod>", lastMod)); writer.print(SITEMAP_CLOSE);/*from w w w. ja va2 s . c om*/ }
From source file:net.bashtech.geobot.BotManager.java
public static String postDataLinkShortener(String postData) { URL url;//from w w w . j a v a 2 s .c o m HttpURLConnection conn; postData = "{\"longUrl\": \"" + postData + "\"}"; try { url = new URL("https://www.googleapis.com/urlshortener/v1/url"); conn = (HttpURLConnection) url.openConnection(); conn.setDoOutput(true); conn.setRequestMethod("POST"); conn.setRequestProperty("User-Agent", "CoeBot"); conn.setRequestProperty("Content-Type", "application/json"); conn.setRequestProperty("Content-Length", "" + Integer.toString(postData.getBytes().length)); PrintWriter out = new PrintWriter(conn.getOutputStream()); System.out.println(postData); out.print(postData); out.close(); String response = ""; Scanner inStream = new Scanner(conn.getInputStream()); while (inStream.hasNextLine()) response += (inStream.nextLine()); inStream.close(); return response; } catch (MalformedURLException ex) { ex.printStackTrace(); } catch (IOException ex) { ex.printStackTrace(); } return ""; }
From source file:es.itecban.deployment.executionmanager.web.view.ReportActivityView.java
public void render(Map model, HttpServletRequest req, HttpServletResponse resp) throws Exception { PrintWriter out = resp.getWriter(); resp.setContentType("application/octet-stream"); ActivityExecReportType report = (ActivityExecReportType) model.get("report"); out.print(report.getTechnicalActivityExecReport()); out.flush();// ww w . jav a 2s . com out.close(); }
From source file:org.loklak.api.server.GraphServlet.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { RemoteAccess.Post post = RemoteAccess.evaluate(request); // manage DoS if (post.isDoS_blackout()) { response.sendError(503, "your request frequency is too high"); return;//from w w w .j a va 2 s . c o m } // parameters String callback = post.get("callback", ""); boolean jsonp = callback != null && callback.length() > 0; boolean minified = post.get("minified", false); String[] screen_names = post.get("screen_name", "").split(","); String followers = screen_names.length == 1 ? post.get("followers", "0") : "0"; String following = screen_names.length == 1 ? post.get("following", "0") : "0"; int maxFollowers = Integer.parseInt(followers); int maxFollowing = Integer.parseInt(following); List<Map<String, Object>> twitterUserEntries = new ArrayList<>(); for (String screen_name : screen_names) { try { Map<String, Object> twitterUserEntry = TwitterAPI.getUser(screen_name, false); if (twitterUserEntry != null) twitterUserEntries.add(twitterUserEntry); } catch (TwitterException e) { } } Map<String, Object> topology = null; try { topology = TwitterAPI.getNetwork(screen_names[0], maxFollowers, maxFollowing); } catch (TwitterException e) { } post.setResponse(response, "application/javascript"); // generate json Map<String, Object> m = new LinkedHashMap<>(); m.put("edges", post.getClientHost()); if (twitterUserEntries.size() == 1) m.put("user", twitterUserEntries.iterator().next()); if (twitterUserEntries.size() > 1) m.put("users", twitterUserEntries); if (topology != null) m.put("topology", topology); // write json FileHandler.setCaching(response, 10); response.setCharacterEncoding("UTF-8"); PrintWriter sos = response.getWriter(); if (jsonp) sos.print(callback + "("); sos.print((minified ? new ObjectMapper().writer() : new ObjectMapper().writerWithDefaultPrettyPrinter()) .writeValueAsString(m)); if (jsonp) sos.println(");"); sos.println(); post.finalize(); }
From source file:feedme.controller.SearchRestServlet.java
/** * Handles the HTTP <code>GET</code> method. * * @param request servlet request//from w ww .ja v a2 s . co m * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); request.setCharacterEncoding("UTF-8"); String city = request.getParameter("where");//get the city int category = Integer.parseInt(request.getParameter("what"));//get the category int page = 1; int recordsPerPage = 6; if (request.getParameter("page") != null) { page = Integer.parseInt(request.getParameter("page")); } List<Restaurant> restaurants = new DbRestaurantsManagement().getNextRecentRestaurantsByCatAndCity(0, recordsPerPage, category, city);//getting a list of restaurants by category and cities int noOfRecords = restaurants.size(); int noOfPages = (int) Math.ceil(noOfRecords * 1.0 / recordsPerPage); if (isAjaxRequest(request)) { try { restaurants = new DbRestaurantsManagement().getNextRecentRestaurantsByCatAndCity( (page - 1) * recordsPerPage, recordsPerPage, category, city);//getting a list of restaurants by category and cities JSONObject restObj = new JSONObject(); JSONArray restArray = new JSONArray(); for (Restaurant rest : restaurants) { restArray.put(new JSONObject().put("resturent", rest.toJson())); } restObj.put("resturent", restArray); restObj.put("noOfPages", noOfPages); restObj.put("currentPage", page); response.setContentType("application/json"); PrintWriter writer = response.getWriter(); writer.print(restObj); response.getWriter().flush(); return; } catch (JSONException e) { e.printStackTrace(); } } request.setAttribute("noOfPages", noOfPages); request.setAttribute("currentPage", page); request.setAttribute("restaurants", restaurants);//return the restaurants to the client RequestDispatcher dispatcher = request.getRequestDispatcher("website/search_rest.jsp"); dispatcher.forward(request, response); }
From source file:it.unibz.instasearch.ui.ReportErrorDialog.java
private void addStatusContent(PrintWriter b, IStatus status) { b.print("Status: "); b.println(status.getMessage());//w ww . ja v a 2s . c o m status.getException().printStackTrace(b); b.println(); }
From source file:com.vmware.identity.openidconnect.protocol.HttpResponse.java
public void applyTo(HttpServletResponse httpServletResponse) throws IOException { Validate.notNull(httpServletResponse, "httpServletResponse"); for (Cookie cookie : this.cookies) { httpServletResponse.addCookie(cookie); }// w w w. j av a2 s.c om for (Header header : this.headers) { httpServletResponse.addHeader(header.getName(), header.getValue()); } if (this.errorObject != null) { httpServletResponse.sendError(this.errorObject.getStatusCode().getValue(), this.errorObject.getErrorCode().getValue() + ": " + this.errorObject.getDescription()); } else if (this.redirectTarget != null) { httpServletResponse.sendRedirect(this.redirectTarget.toString()); } else if (this.htmlContent != null) { httpServletResponse.setStatus(this.statusCode.getValue()); httpServletResponse.setHeader("Cache-Control", "no-cache, no-store"); httpServletResponse.setHeader("Pragma", "no-cache"); httpServletResponse.setContentType("text/html;charset=UTF-8"); PrintWriter writer = httpServletResponse.getWriter(); writer.print(this.htmlContent); writer.close(); } else if (this.jsonContent != null) { httpServletResponse.setStatus(this.statusCode.getValue()); httpServletResponse.setHeader("Cache-Control", "no-store"); httpServletResponse.setHeader("Pragma", "no-cache"); httpServletResponse.setContentType("application/json;charset=UTF-8"); PrintWriter writer = httpServletResponse.getWriter(); writer.print(this.jsonContent.toString()); writer.close(); } else { throw new IllegalStateException("unexpected"); } }
From source file:com.buaa.cfs.conf.ReconfigurationServlet.java
private void printHeader(PrintWriter out, String nodeName) { out.print("<html><head>"); out.printf("<title>%s Reconfiguration Utility</title>%n", StringEscapeUtils.escapeHtml(nodeName)); out.print("</head><body>\n"); out.printf("<h1>%s Reconfiguration Utility</h1>%n", StringEscapeUtils.escapeHtml(nodeName)); }
From source file:it.tidalwave.northernwind.frontend.util.InitializationDiagnosticsDispatcherServletDecorator.java
/******************************************************************************************************************* * * ******************************************************************************************************************/ private void sendProcessingError(final @Nonnull Throwable t, final @Nonnull HttpServletResponse response) throws IOException { response.setStatus(500);/*from w w w . j a v a 2 s .c o m*/ response.setContentType("text/html"); final PrintWriter pw = new PrintWriter(new PrintStream(response.getOutputStream(), true, "UTF-8")); pw.print("<html>\n<head>\n<title>Configuration Error</title>\n</head>\n<body>\n"); pw.print("<h1>Configuration Error</h1>\n<pre>\n"); pw.print(t.toString()); // t.printStackTrace(pw); pw.print("</pre>\n"); pw.print("<h2>Boot log</h2>\n<pre>\n"); pw.print(BootLogger.getLogContent()); pw.print("</pre></body>\n</html>"); pw.close(); response.getOutputStream().close(); }
From source file:com.wechat.client.business.controller.CarController.java
@RequestMapping("/searchVin.json") public void search(HttpServletRequest request, HttpServletResponse response) { try {/*from w w w . j a v a 2s .c o m*/ LoginUser user = getLoginUser(request, response); String vin = request.getParameter("vin17"); String accessUrl = getByVINPath; String param = HttpEntityUtils.toParameterString(user).substring(1); JsonHttpRequestUtil jr = new JsonHttpRequestUtil(); String json = jr.doGet(accessUrl + "?" + param + "&vin17=" + vin); PrintWriter out = response.getWriter(); out.print(json); } catch (IOException e) { e.printStackTrace(); } }