List of usage examples for java.io PrintWriter write
public void write(String s)
From source file:com.globalsight.connector.eloqua.EloquaCreateJobHandler.java
@ActionHandler(action = "uploadAttachment", formClass = "") public void uploadAttachment(HttpServletRequest request, HttpServletResponse response, Object form) throws Exception { logger.debug("Upload attachment..."); FileUploader uploader = new FileUploader(); File file = uploader.upload(request); HttpSession session = request.getSession(); SessionManager sessionMgr = (SessionManager) session.getAttribute(SESSION_MANAGER); sessionMgr.setAttribute("uploadAttachment", file); PrintWriter writer = response.getWriter(); writer.write("<script type='text/javascript'>window.parent.addAttachment(' ')</script>;"); pageReturn();//from w w w . ja v a 2 s. co m logger.debug("Upload attachment finished."); }
From source file:MainServer.UploadServlet.java
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); DiskFileItemFactory factory = new DiskFileItemFactory(); String upload = this.getServletContext().getRealPath("/upload/"); String temp = System.getProperty("java.io.tmpdir"); factory.setSizeThreshold(1024 * 1024 * 5); factory.setRepository(new File(temp)); ServletFileUpload servleFileUplaod = new ServletFileUpload(factory); try {// w w w .j ava2s . c om List<FileItem> list = servleFileUplaod.parseRequest(request); for (FileItem item : list) { String name = item.getFieldName(); InputStream is = item.getInputStream(); if (name.contains("content")) { System.out.println(inputStream2String(is)); } else { if (name.contains("file")) { try { inputStream2File(is, upload + "\\" + item.getName()); } catch (Exception e) { } } } } out.write("success"); } catch (FileUploadException | IOException e) { out.write("failure"); } out.flush(); out.close(); }
From source file:com.imagelake.earnings.Servlet_EarningsValues.java
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { PrintWriter out = response.getWriter(); try {// w ww. j a va 2 s . c om String uid = request.getParameter("uid"); if (uid != null && !uid.equals("")) { uidd = Integer.parseInt(uid); PaymentPreferences pp = ppimp.getPendingEarning(uidd, 1); double pd = 00.00; double ad = 00.00; if (pp != null) { pd = pp.getAmount(); DecimalFormat df1 = new DecimalFormat("#.##"); pd = Double.valueOf(df1.format(pd)); } SellerIncome sin = sidi.getSellerIncome(uidd); ad = sin.getTotal(); DecimalFormat df = new DecimalFormat("#.##"); ad = Double.valueOf(df.format(ad)); double netamo = ad - pd; DecimalFormat df2 = new DecimalFormat("#.##"); netamo = Double.valueOf(df2.format(netamo)); JSONObject jo = new JSONObject(); jo.put("pe", pd); jo.put("ab", ad); jo.put("ne", netamo); out.write("json=" + jo.toJSONString()); } } catch (Exception e) { e.printStackTrace(); } }
From source file:com.globalsight.connector.eloqua.EloquaCreateJobHandler.java
/** * Called by ajax, search target locales for files, and init the target * locales checkbox on the jsp//www .j a v a2 s . co m * * @param request * @param response * @param user * @throws IOException */ private void queryTargetLocales(HttpServletRequest request, HttpServletResponse response, User user) throws IOException { String l10Nid = request.getParameter("l10Nid"); if (StringUtils.isNotEmpty(l10Nid)) { String targetLocalesString = l10NToTargetLocalesMap.get(l10Nid); if (targetLocalesString == null) { String hsql = "select wti.targetLocale from " + "L10nProfileWFTemplateInfo as ltp, WorkflowTemplateInfo wti " + "where wti.id = ltp.key.wfTemplateId and ltp.key.l10nProfileId = " + l10Nid + " and ltp.isActive = 'Y' and wti.isActive = 'Y' " + "order by wti.targetLocale.language"; List<?> localeList = HibernateUtil.search(hsql); if (localeList != null) { targetLocalesString = this.initTargetLocaleSelect(localeList, user); l10NToTargetLocalesMap.put(l10Nid, targetLocalesString); } else { targetLocalesString = ""; } } response.setContentType("text/html;charset=UTF-8"); PrintWriter writer = response.getWriter(); writer.write(targetLocalesString); writer.close(); } }
From source file:com.imaginea.mongodb.controllers.TroubleShootController.java
/** * Handles a GET Request at path mViewer/admin for changing the logger level * * @param request Request made by user/* w w w.j a v a 2 s . com*/ * @param response * @throws ServletException ,IOException,IllegalArgumentException */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, IllegalArgumentException { response.setContentType("application/x-json"); PrintWriter out = response.getWriter(); JSONObject respObj = new JSONObject(); String loggerLevel = request.getParameter("level"); try { if (!logLevels.containsKey(loggerLevel)) { JSONObject error = new JSONObject(); error.put("code", ErrorCodes.LOGGING_LEVEL_UNDEFINED); error.put("message", "Undefined Logging level"); JSONObject temp = new JSONObject(); temp.put("error", error); respObj.put("response", temp); } else { Level newLevel = logLevels.get(loggerLevel); Logger rootLogger = LogManager.getRootLogger(); // To get the // Root Logger String oldLevel = rootLogger.getEffectiveLevel().toString(); rootLogger.setLevel(newLevel); JSONObject temp = new JSONObject(); temp.put("result", "Logger Level Changed from " + oldLevel + " to " + rootLogger.getLevel()); respObj.put("response", temp); } out.write(respObj.toString()); out.close(); } catch (JSONException e) { throw new ServletException("Error forming JSON Object in Servlet", e.getCause()); } }
From source file:com.honnix.yaacs.adapter.http.TestACHttpServer.java
public void testPutAC() { Map<String, String> paramMap = null; String sessionId = null;//from w ww .j a v a 2s .c om try { paramMap = login(); sessionId = paramMap.get(ACHttpConstant.SESSION_ID_KEY); assertNotNull(RESPONSE_ERROR, sessionId); } catch (HttpException e) { fail(FORCED_FAILURE); } catch (IOException e) { fail(FORCED_FAILURE); } StringBuilder sb = new StringBuilder(HOST).append(ACHttpPropertiesConstant.HTTP_LISTENING_PORT) .append(ACHttpPropertiesConstant.HTTP_AC_REQUEST_URL); postMethod = new PostMethod(sb.toString()); postMethod.setRequestHeader(CONTENT_TYPE_KEY, CONTENT_TYPE); File file = new File("etc/http.properties"); byte[] byteArray = null; try { byteArray = StreamUtil.inputStream2ByteArray(new FileInputStream(file)); } catch (FileNotFoundException e1) { fail(FORCED_FAILURE); } assertNotNull("Should not be null.", byteArray); try { StringRequestEntity requestEntity = new StringRequestEntity( ACHttpBodyUtil.buildPutACRequestBody(sessionId, "aac6400f48249cc9763771cc626a3571", "Honnix", "2008", "Shadow of Light", ACConstant.AC_FILE_CONTENT_ENCODE, StringUtil.encodeBase64(byteArray)), null, ACHttpPropertiesConstant.HTTP_CHARSET); postMethod.setRequestEntity(requestEntity); int statusCode = client.executeMethod(postMethod); assertEquals(SHOULD_BE_OK, HttpStatus.SC_OK, statusCode); String response = postMethod.getResponseBodyAsString(); assertTrue(RESPONSE_ERROR, response.startsWith(ERROR_CONVERTING_FILE) || response.startsWith(SUCCESS_RESP)); } catch (HttpException e) { fail(FORCED_FAILURE); } catch (IOException e) { fail(FORCED_FAILURE); } file = new File(ACPropertiesConstant.REPO_PATH); File[] fileArray = file.listFiles(); for (int i = 0; i < fileArray.length; i++) { fileArray[i].delete(); } try { PrintWriter pw = new PrintWriter(ACPropertiesConstant.INFO_FILE_PATH); pw.print("aac6400f48249cc9763771cc626a3571" + ACConstant.AC_SEPARATOR + "Honnix" + ACConstant.AC_SEPARATOR + "2008" + ACConstant.AC_SEPARATOR + "Shadow of Light" + ACConstant.AC_SEPARATOR + ACPropertiesConstant.REPO_PATH + ACConstant.FILE_SEPARATOR + "f04b85d32f91df435c439f5723e0efbb.jpg"); pw.print(ACConstant.AC_LINE_SEPARATOR); pw.flush(); } catch (FileNotFoundException e) { fail("Could not open " + ACPropertiesConstant.INFO_FILE_PATH); } PrintWriter pw = null; try { pw = new PrintWriter(ACPropertiesConstant.REPO_PATH + ACConstant.FILE_SEPARATOR + "f04b85d32f91df435c439f5723e0efbb.jpg"); pw.write("abc"); } catch (FileNotFoundException e) { fail("Could not open test1.jpg to write."); } pw.flush(); }
From source file:convcao.com.caoAgent.convcaoNeptusInteraction.java
private void connectButtonActionPerformed(java.awt.event.ActionEvent evt) throws SocketException, IOException { String[] vehicles = controlledVehicles.split(","); jTextArea1.setText(""); jTextArea1.repaint();//from www.j av a2s . c o m showText("Initializing Control Structures"); try { startLocalStructures(vehicles); } catch (Exception e) { GuiUtils.errorMessage(getConsole(), e); return; } AUVS = positions.keySet().size(); showText("Initializing server connection"); FTPClient client = new FTPClient(); boolean PathNameCreated = false; try { client.connect("www.convcao.com", 21); client.login(jTextField1.getText(), new String(jPasswordField1.getPassword())); PathNameCreated = client.makeDirectory("/NEPTUS/" + SessionID); client.logout(); } catch (IOException e) { jLabel6.setText("Connection Error"); throw e; } showText("Sending session data"); InputData initialState = new InputData(); initialState.DateTime = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss").format(new Date()); initialState.SessionID = SessionID; initialState.DemoMode = "1"; initialState.AUVs = "" + positions.keySet().size(); String fileName = SessionID + ".txt"; Gson gson = new Gson(); String json = gson.toJson(initialState); PrintWriter writer = new PrintWriter(fileName, "UTF-8"); writer.write(json); writer.close(); if (PathNameCreated) { jLabel6.setText("Connection Established"); jLabel1.setVisible(true); System.out.println("Uploading first file"); Upload("www.convcao.com", "NEPTUS", "", jTextField1.getText(), new String(jPasswordField1.getPassword()), fileName); //send first file System.out.println("Uploading second file"); Upload("www.convcao.com", "NEPTUS/" + SessionID, "plugins-dev/caoAgent/convcao/com/caoAgent/", jTextField1.getText(), new String(jPasswordField1.getPassword()), "mapPortoSparse.txt"); //send sparse map System.out.println("Both files uploaded"); jButton1.setEnabled(true); jButton2.setEnabled(true); jTextPane1.setEditable(false); jTextField1.setEditable(false); jPasswordField1.setEditable(false); connectButton.setEnabled(false); renewButton.setEnabled(false); } else { jLabel6.setText(client.getReplyString()); jLabel1.setVisible(false); } myDeleteFile(fileName); showText("ConvCAO control has started"); }
From source file:com.hp.avmon.kpigetconfig.web.KpigetconfigAgentController.java
/** * agent AMP list/*from ww w . j av a 2s . c om*/ * @param request * @param writer */ @RequestMapping(value = "/findAgentAmp") public void findAgentAmp(HttpServletRequest request, PrintWriter writer) { Map map = null; try { map = agentManageService.findAgentAmp(request); String jsonData = JackJson.fromObjectToJson(map); //logger.debug("agent amp list==="+jsonData); writer.write(jsonData); writer.flush(); writer.close(); } catch (Exception e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } }
From source file:com.hp.avmon.config.web.AgentController.java
@RequestMapping(value = "/removeAmp") public void removeAmp(HttpServletRequest request, PrintWriter writer) { Map map = agentManageService.removeAmp(request); String jsonData = JackJson.fromObjectToJson(map); logger.debug("removeAmp: " + jsonData); writer.write(jsonData); writer.flush();//from w w w.j a v a 2 s . c om writer.close(); }