List of usage examples for java.io PrintWriter append
public PrintWriter append(char c)
From source file:com.francelabs.datafari.servlets.admin.ZooKeeperConf.java
/** * @throws IOException/*from w w w . ja v a 2s . co m*/ * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse * response) */ @Override protected void doGet(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException { final JSONObject jsonResponse = new JSONObject(); request.setCharacterEncoding("utf8"); response.setContentType("application/json"); final String actionParam = request.getParameter("action"); IndexerServer server = null; try { server = IndexerServerManager.getIndexerServer(Core.FILESHARE); } catch (final IOException e1) { final PrintWriter out = response.getWriter(); out.append( "Error while getting the Solr core, please make sure the core dedicated to PromoLinks has booted up. Error code : 69000"); out.close(); LOGGER.error( "Error while getting the Solr core in doGet, admin servlet, make sure the core dedicated to Promolink has booted up and is still called promolink or that the code has been changed to match the changes. Error 69000 ", e1); return; } catch (final Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } try { if (actionParam.toLowerCase().equals("download")) { final File folderConf = new File(downloadFolder); FileUtils.cleanDirectory(folderConf); server.downloadConfig(Paths.get(downloadFolder), Core.FILESHARE.toString()); } else if (actionParam.toLowerCase().equals("upload")) { server.uploadConfig(Paths.get(env), Core.FILESHARE.toString()); } else if (actionParam.toLowerCase().equals("reload")) { server.reloadCollection(Core.FILESHARE.toString()); } else if (actionParam.toLowerCase().equals("upload_and_reload")) { server.uploadConfig(Paths.get(env), Core.FILESHARE.toString()); Thread.sleep(3000); server.reloadCollection(Core.FILESHARE.toString()); } jsonResponse.put(OutputConstants.CODE, CodesReturned.ALLOK.getValue()); } catch (final IOException | SolrServerException | InterruptedException e) { LOGGER.error("Exception during action " + actionParam, e); jsonResponse.put(OutputConstants.CODE, CodesReturned.GENERALERROR.getValue()); } final PrintWriter out = response.getWriter(); out.print(jsonResponse); }
From source file:org.eclipse.virgo.management.console.UploadServlet.java
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException { try {// w ww .j a v a 2 s . c o m File stagingDir = createStagingDirectory(); FileItemFactory factory = new DiskFileItemFactory(); ServletFileUpload upload = new ServletFileUpload(factory); response.setContentType("text/html"); @SuppressWarnings("unchecked") List<FileItem> items = (List<FileItem>) upload.parseRequest(request); List<File> uploadedFiles = new ArrayList<File>(); for (FileItem fileItem : items) { File uploadedFile = this.doUpload(fileItem, stagingDir); if (uploadedFile != null) { uploadedFiles.add(uploadedFile); } } doDeployment(uploadedFiles, response); } catch (IllegalArgumentException ea) { PrintWriter writer = response.getWriter(); writer.append("<ol id=\"uploadResults\"><li>File name contains '/' or '\\', this is not allowed.</ol>"); writer.close(); } catch (Exception e) { log.error(e.toString()); response.sendError(HTTP_RESPONSE_INTERNAL_SERVER_ERROR, e.toString()); } }
From source file:org.eclipse.orion.server.authentication.formopenid.ManageOpenidsServlet.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse response) throws ServletException, IOException { String pathInfo = req.getPathInfo() == null ? "" : req.getPathInfo(); //$NON-NLS-1$ try {// ww w. j av a 2 s.c o m if (pathInfo.startsWith("/openid")) { //$NON-NLS-1$ String openid = req.getParameter(OpenIdHelper.OPENID); if (openid != null) { consumer = OpenIdHelper.redirectToOpenIdProvider(req, response, consumer); return; } String op_return = req.getParameter(OpenIdHelper.OP_RETURN); if (op_return != null) { OpenIdHelper.handleOpenIdReturn(req, response, consumer); return; } } } catch (OpenIdException e) { writeOpenIdError(e.getMessage(), req, response); return; } JSONArray providersJson = new JSONArray(); for (OpendIdProviderDescription provider : getSupportedOpenids(req)) { JSONObject providerJson = new JSONObject(); try { providerJson.put(ProtocolConstants.KEY_NAME, provider.getName()); providerJson.put(OpenIdConstants.KEY_IMAGE, provider.getImage()); providerJson.put(OpenIdConstants.KEY_URL, provider.getAuthSite()); providersJson.put(providerJson); } catch (JSONException e) { LogHelper.log(new Status(IStatus.ERROR, Activator.PI_AUTHENTICATION_SERVLETS, "Exception writing OpenId provider " + provider.getName(), e)); //$NON-NLS-1$ } } response.setContentType("application/json"); //$NON-NLS-1$ PrintWriter writer = response.getWriter(); writer.append(providersJson.toString()); writer.flush(); }
From source file:org.efaps.util.EFapsException.java
/** * If a caused exception is a {@link SQLException}, also all next * exceptions of the {@link SQLException}'s are printed into the stack * trace.//ww w . ja va 2s. c o m * * @param _writer <code>PrintWriter</code> to use for output * @see #makeInfo() to get all information about this EFapsException */ @Override public void printStackTrace(final PrintWriter _writer) { _writer.append(makeInfo()); if (this.className != null) { _writer.append("Thrown within class ").append(this.className.getName()).append('\n'); } super.printStackTrace(_writer); if (getCause() != null && getCause() instanceof SQLException) { SQLException ex = (SQLException) getCause(); ex = ex.getNextException(); while (ex != null) { _writer.append("Next SQL Exception is: "); ex.printStackTrace(_writer); ex = ex.getNextException(); } } }
From source file:com.shopzilla.ducky.WadlXsltFilter.java
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { if (this.requestMatcher.match(request)) { LOG.debug("adding transform"); ByteBufferResponseWrapper wrapper = new ByteBufferResponseWrapper((HttpServletResponse) response); String styleSheetPath = makeProcessingInstruction(request); chain.doFilter(request, wrapper); wrapper.getWriter().flush();/* w w w. java2 s . c om*/ String responseStr = injectStyleSheet(wrapper.toString(), styleSheetPath); response.setContentLength(responseStr.length()); PrintWriter out = response.getWriter(); out.append(responseStr); out.flush(); } else { LOG.debug("NOT adding transform"); // just pass it along chain.doFilter(request, response); } }
From source file:org.emergent.plumber.UserServlet.java
protected void doGetNodeWeave(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String reqUrl = req.getRequestURL().toString(); String reqUri = req.getRequestURI(); String ctxPath = req.getContextPath(); // String pathInfo = req.getPathInfo(); // String servletPath = req.getServletPath(); // log("requrl: " + reqUrl); // log("requri: " + req.getRequestURI()); // log("ctxpath: " + ctxPath); // log("pathinfo: " + pathInfo); // log("servletpath: " + servletPath); StringBuilder retval = new StringBuilder(); retval.append(reqUrl.substring(0, reqUrl.indexOf(reqUri))); retval.append(ctxPath).append('/'); resp.setContentType("text/html"); resp.setCharacterEncoding("UTF-8"); PrintWriter writer = resp.getWriter(); writer.append(retval); }
From source file:org.emergent.plumber.UserServlet.java
protected void doGetDefault(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String userName = (String) req.getAttribute(ATTRIB_USERNAME_KEY); Connection dbCon = null;/*from w ww . j ava 2s.c o m*/ boolean exists = false; PreparedStatement st = null; ResultSet rs = null; try { dbCon = getDatabaseConnection(req); st = dbCon.prepareStatement("SELECT COUNT(*) FROM WeaveUser WHERE username = ?"); st.setString(1, userName); rs = st.executeQuery(); while (rs.next()) { int count = rs.getInt(1); log("COUNT: " + count); if (count > 0) exists = true; } } catch (SQLException e) { log(e.getMessage(), e); } finally { MiscUtil.close(rs); MiscUtil.close(st); MiscUtil.close(dbCon); } resp.setContentType("text/html"); resp.setCharacterEncoding("UTF-8"); PrintWriter writer = resp.getWriter(); writer.append(exists ? "1" : "0"); }
From source file:demo.project.ExportTable.java
/** * @param w// w ww. j ava 2 s .c om * @param children */ private void addAll(PrintWriter w, IRow row, List<ARankColumnModel> children) { for (ARankColumnModel col : children) { w.append('\t').print(toValue(row, col)); if (col instanceof ACompositeRankColumnModel) { addAll(w, row, ((ACompositeRankColumnModel) col).getChildren()); } } }
From source file:org.b3log.solo.processor.FileUploadProcessor.java
@Override public void doPost(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { if (QN_ENABLED) { return;//from w w w. j a va2s . c om } final MultipartRequestInputStream multipartRequestInputStream = new MultipartRequestInputStream( req.getInputStream()); multipartRequestInputStream.readBoundary(); multipartRequestInputStream.readDataHeader("UTF-8"); String fileName = multipartRequestInputStream.getLastHeader().getFileName(); String suffix = StringUtils.substringAfterLast(fileName, "."); if (StringUtils.isBlank(suffix)) { final String mimeType = multipartRequestInputStream.getLastHeader().getContentType(); String[] exts = MimeTypes.findExtensionsByMimeTypes(mimeType, false); if (null != exts && 0 < exts.length) { suffix = exts[0]; } else { suffix = StringUtils.substringAfter(mimeType, "/"); } } final String name = StringUtils.substringBeforeLast(fileName, "."); final String processName = name.replaceAll("\\W", ""); final String uuid = UUID.randomUUID().toString().replaceAll("-", ""); if (StringUtils.isBlank(processName)) { fileName = uuid + "." + suffix; } else { fileName = uuid + '_' + processName + "." + suffix; } final OutputStream output = new FileOutputStream(UPLOAD_DIR + fileName); IOUtils.copy(multipartRequestInputStream, output); IOUtils.closeQuietly(multipartRequestInputStream); IOUtils.closeQuietly(output); final JSONObject data = new JSONObject(); data.put("key", Latkes.getServePath() + "/upload/" + fileName); data.put("name", fileName); resp.setContentType("application/json"); final PrintWriter writer = resp.getWriter(); writer.append(data.toString()); writer.flush(); writer.close(); }
From source file:org.kalypso.model.wspm.tuhh.core.profile.export.AbstractCsvWriter.java
private void writeHeader(final PrintWriter writer) { for (int i = 0; i < m_columns.length; i++) { final IProfileExportColumn column = m_columns[i]; writer.append(column.getHeader()); if (i != m_columns.length - 1) { writer.append(m_tokenSeparator); //$NON-NLS-1$ }//from www .j a v a 2 s .c o m } writer.println(); }