List of usage examples for java.io PrintWriter print
public void print(Object obj)
From source file:net.cellcloud.http.AbstractJSONHandler.java
/** * ??? JSON ?/* w ww. j a va 2 s . co m*/ * @param response * @param status * @param json * @throws IOException */ protected void respond(HttpResponse response, int status, JSONObject json) throws IOException { response.setContentType("application/json"); response.setCharacterEncoding("UTF-8"); response.setStatus(status); PrintWriter out = null; try { out = response.getWriter(); out.print(json.toString()); } catch (IOException e) { throw e; } finally { try { out.close(); } catch (Exception e) { // Nothing } } }
From source file:net.cellcloud.http.AbstractJSONHandler.java
/** * 200 ???//from w w w. j a v a 2 s. c o m * @param response */ protected void respondWithOk(HttpResponse response) { response.setContentType("application/json"); response.setCharacterEncoding("UTF-8"); response.setStatus(HttpResponse.SC_OK); PrintWriter out = null; try { out = response.getWriter(); out.print("{}"); } catch (IOException e) { Logger.log(AbstractJSONHandler.class, e, LogLevel.ERROR); } finally { try { out.close(); } catch (Exception e) { // Nothing } } }
From source file:net.cellcloud.http.AbstractJSONHandler.java
/** * 200 ??? JSON ?/* w ww .ja v a 2 s.co m*/ * @param response * @param json * @throws IOException */ protected void respondWithOk(HttpResponse response, JSONObject json) throws IOException { response.setContentType("application/json"); response.setCharacterEncoding("UTF-8"); response.setStatus(HttpResponse.SC_OK); PrintWriter out = null; try { out = response.getWriter(); out.print(json.toString()); } catch (IOException e) { throw e; } finally { try { out.close(); } catch (Exception e) { // Nothing } } }
From source file:it.cilea.osd.jdyna.utils.ClassificationExportUtils.java
/** * Metodo di supporto per esportare una classificazione nella sua "bean * definition". //FIXME valutare la possibilita' di utilizzare il * polimorfismo implementando un'interfaccia IExportableBeanDefinition * /*from w ww. ja v a 2 s.c o m*/ * @param writer * @param classificazione */ private void classificazioneToXML(PrintWriter writer, Classificazione classificazione) { writer.print(" <bean id=\"" + Classificazione.class.getSimpleName() + classificazione.getId() + "\" class=\"" + Classificazione.class.getCanonicalName() + "\">\n"); writer.print(" <property name=\"alberoClassificatorio\" ref=\"" + AlberoClassificatorio.class.getSimpleName() + classificazione.getAlberoClassificatorio().getId() + "\" />\n"); if (classificazione.getPadre() != null) { writer.print(" <property name=\"padre\" ref=\"" + Classificazione.class.getSimpleName() + classificazione.getPadre().getId() + "\" />\n"); } writer.print(" <property name=\"codice\" value=\"" + classificazione.getCodice() + "\" />\n"); writer.print(" <property name=\"nome\" value=\"" + classificazione.getNome() + "\" />\n"); writer.print(" <property name=\"selezionabile\" value=\"" + classificazione.isSelezionabile() + "\" />\n"); writer.print(" <property name=\"attivo\" value=\"" + classificazione.isAttivo() + "\" />\n"); // bisogna settare solo i legami "a salire" quelli a scendere vengono // dedotti automaticamente // writer // .print(" <property name=\"sottoCategorie\">\n" // + " <list>\n"); // for (Classificazione subClass : classificazione.getSottoCategorie()) // { // // toXML(writer, subClass); // // } // writer.print(" </list>\n"); // writer.print(" </property>\n"); writer.print(" </bean>\n\n"); writer.print(" <!-- SottoClassificazioni di:" + classificazione.getNome() + " -->\n\n"); for (Classificazione subClass : classificazione.getSottoCategorie()) { classificazioneToXML(writer, subClass); } writer.print(" <!-- FINE SottoClassificazioni di:" + classificazione.getNome() + " -->\n\n"); }
From source file:com.concursive.connect.web.webdav.resources.WebdavResource.java
protected void sendContentMenu(final PrintWriter printer) { printer.print("<ul>"); for (WebdavResource r : parent.children) { printer.print("<li><a href='" + r.getHref() + "'>" + r.getName() + "</a>"); }/*from w w w . ja v a 2 s . c o m*/ printer.print("</ul>"); }
From source file:com.jaspersoft.jasperserver.rest.RESTLoginAuthenticationFilter.java
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest httpRequest = (HttpServletRequest) request; HttpServletResponse httpResponse = (HttpServletResponse) response; String username = EncryptionRequestUtils.getValue(request, AuthenticationProcessingFilter.SPRING_SECURITY_FORM_USERNAME_KEY); String password = EncryptionRequestUtils.getValue(request, AuthenticationProcessingFilter.SPRING_SECURITY_FORM_PASSWORD_KEY); if (!StringUtils.isEmpty(username)) { // decoding since | is not http safe username = URLDecoder.decode(username, CharEncoding.UTF_8); UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken(username, password);//from w w w . j a va2 s . c o m authRequest.setDetails(new WebAuthenticationDetails(httpRequest)); Authentication authResult; try { authResult = authenticationManager.authenticate(authRequest); } catch (AuthenticationException e) { if (log.isDebugEnabled()) { log.debug("User " + username + " failed to authenticate: " + e.toString()); } if (log.isWarnEnabled()) { log.warn("User " + username + " failed to authenticate: " + e.toString() + " " + e, e.getRootCause()); } SecurityContextHolder.getContext().setAuthentication(null); // Send an error message in the form of OperationResult... httpResponse.setStatus(HttpServletResponse.SC_UNAUTHORIZED); //OperationResult or = servicesUtils.createOperationResult(1, "Invalid username " + username); PrintWriter pw = httpResponse.getWriter(); pw.print("Unauthorized"); return; } if (log.isDebugEnabled()) { log.debug("User " + username + " authenticated: " + authResult); } SecurityContextHolder.getContext().setAuthentication(authResult); chain.doFilter(request, response); } else { if (log.isDebugEnabled()) { log.debug("Failed to authenticate: Bad request. Username and password must be specified."); } if (log.isWarnEnabled()) { log.warn("Failed to authenticate: Bad request. Username and password must be specified."); } httpResponse.setStatus(HttpServletResponse.SC_BAD_REQUEST); PrintWriter pw = httpResponse.getWriter(); pw.print("Bad request." + (StringUtils.isEmpty(username) ? " Parameter " + AuthenticationProcessingFilter.SPRING_SECURITY_FORM_USERNAME_KEY + " not found." : "") + (StringUtils.isEmpty(password) ? " Parameter " + AuthenticationProcessingFilter.SPRING_SECURITY_FORM_PASSWORD_KEY + " not found." : "")); } }
From source file:gov.nih.nci.ncicb.tcga.dcc.qclive.common.MD5ChecksumCreatorFastTest.java
public void setUp() throws FileNotFoundException { PrintWriter writer = null; try {//from w w w . j a va 2s . c om testFile = new File(TEST_FILE_NAME); //noinspection IOResourceOpenedButNotSafelyClosed writer = new PrintWriter(testFile); writer.print(TEST_CHECKSUM_TEXT); } finally { IOUtils.closeQuietly(writer); } }
From source file:com.google.gct.idea.appengine.synchronization.SampleSyncTaskTest.java
private RevCommit addFileToMockGitHubRepo(String fileName, String commitMessage) throws GitAPIException, IOException { // Create a new file File file = new File(db.getWorkTree(), fileName); file.createNewFile();/* w w w . j a v a 2s . com*/ PrintWriter writer = new PrintWriter(file); writer.print("Some content"); writer.close(); // Add file to mocked Github repo mockGitHubRepo.add().addFilepattern(fileName).call(); RevCommit commit = mockGitHubRepo.commit().setMessage(commitMessage).call(); Assert.assertNotNull(commit); mockGitHubRepo.push().call(); return commit; }
From source file:edu.lternet.pasta.portal.ReportViewerServlet.java
/** * The doPost method of the servlet. <br> * * This method is called when a form has its tag value method equals to post. * /*www .j a v a 2 s . c o m*/ * @param request the request send by the client to the server * @param response the response send by the server to the client * @throws ServletException if an error occurred * @throws IOException if an error occurred */ public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HttpSession httpSession = request.getSession(); String uid = (String) httpSession.getAttribute("uid"); if (uid == null || uid.isEmpty()) uid = "public"; String packageId = request.getParameter("packageid"); String encodedPath = request.getParameter("localPath"); String scope = null; Integer identifier = null; String revision = null; String xml = null; String html = null; try { String[] tokens = packageId.split("\\."); if (tokens.length == 3) { scope = tokens[0]; identifier = Integer.valueOf(tokens[1]); revision = tokens[2]; /* * The quality report XML could be read either from a local file * or from PASTA via the DataPackageManagerClient. */ if (encodedPath != null && encodedPath.length() > 0) { URLCodec urlCodec = new URLCodec(); String localPath = urlCodec.decode(encodedPath); File xmlFile = new File(localPath); if (xmlFile != null && xmlFile.exists()) { xml = FileUtils.readFileToString(xmlFile); } } else { DataPackageManagerClient dpmClient = new DataPackageManagerClient(uid); xml = dpmClient.readDataPackageReport(scope, identifier, revision); } ReportUtility qrUtility = new ReportUtility(xml); html = HTMLHEAD + "<div class=\"qualityreport\">" + qrUtility.xmlToHtmlTable(cwd + xslpath) + "</div>" + HTMLTAIL; } else { String msg = String.format( "packageId '%s' is not in the correct form of 'scope.identifier.revision' (e.g., 'knb-lter-lno.1.1')", packageId); throw new UserErrorException(msg); } } catch (Exception e) { handleDataPortalError(logger, e); } response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.print(html); out.flush(); out.close(); }
From source file:bookUtilities.BookSearchServlet.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./* ww 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"); JSONArray books = getSearchResults(request.getParameter("searchPhrase")); PrintWriter printout = response.getWriter(); printout.print(books); printout.flush(); }