List of usage examples for java.io PrintWriter write
public void write(String s)
From source file:gemlite.shell.admin.dao.AdminDao.java
/** * ??,??server/*from w ww .j a v a 2 s .c o m*/ * * @param conf */ public void lookConf() { try { FileWriter fw = new FileWriter("conf.info"); BufferedWriter bw = new BufferedWriter(fw); PrintWriter pw = new PrintWriter(bw); Map param = new HashMap(); param.put("beanName", "ConfService"); Map args = new HashMap(); param.put("userArgs", args); Execution execution = FunctionService.onServers(clientPool).withArgs(param); ResultCollector rc = execution.execute("REMOTE_ADMIN_FUNCTION"); Object result = rc.getResult(); System.out.println(result); pw.write(result.toString()); pw.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.github.vatbub.vatbubgitreports.Main.java
public void doPost(HttpServletRequest request, HttpServletResponse response) { response.setContentType("application/json"); PrintWriter writer; Gson gson = new GsonBuilder().setPrettyPrinting().create(); StringBuilder requestBody = new StringBuilder(); String line;//w ww. j a v a 2 s .co m try { writer = response.getWriter(); } catch (IOException e) { Internet.sendErrorMail("getWriter", "Unable not read request", e, gMailUsername, gMailPassword); e.printStackTrace(); response.setStatus(500); return; } try { BufferedReader reader = request.getReader(); while ((line = reader.readLine()) != null) { requestBody.append(line); } } catch (IOException e) { Error error = new Error(e.getClass().getName() + " occurred while reading the request", ExceptionUtils.getFullStackTrace(e)); writer.write(gson.toJson(error)); response.setStatus(500); Internet.sendErrorMail("ReadRequestBody", requestBody.toString(), e, gMailUsername, gMailPassword); return; } // parse the request if (!request.getContentType().equals("application/json")) { // bad content type Error error = new Error("content type must be application/json"); writer.write(gson.toJson(error)); } GitHubIssue gitHubIssue; try { System.out.println("Received request:"); System.out.println(requestBody.toString()); System.out.println("Request encoding is: " + request.getCharacterEncoding()); gitHubIssue = gson.fromJson(requestBody.toString(), GitHubIssue.class); } catch (Exception e) { Internet.sendErrorMail("ParseJSON", requestBody.toString(), e, gMailUsername, gMailPassword); Error error = new Error(e.getClass().getName() + " occurred while parsing the request", ExceptionUtils.getFullStackTrace(e)); writer.write(gson.toJson(error)); response.setStatus(500); return; } // Authenticate on GitHub GitHubClient client = new GitHubClient(); client.setOAuth2Token(System.getenv("GITHUB_ACCESS_TOKEN")); // Convert the issue object Issue issue = new Issue(); issue.setTitle(gitHubIssue.getTitle()); String body = ""; boolean metadataGiven = false; if (!gitHubIssue.getReporterName().equals("")) { body = "Reporter name: " + gitHubIssue.getReporterName() + "\n"; metadataGiven = true; } if (!gitHubIssue.getReporterEmail().equals("")) { body = body + "Reporter email: " + gitHubIssue.getReporterEmail() + "\n"; metadataGiven = true; } if (gitHubIssue.getLogLocation() != null) { body = body + "Log location: " + gitHubIssue.getLogLocation() + "\n"; metadataGiven = true; } if (gitHubIssue.getScreenshotLocation() != null) { body = body + "Screenshot location: " + gitHubIssue.getScreenshotLocation() + "\n"; metadataGiven = true; } if (gitHubIssue.getThrowable() != null) { body = body + "Exception stacktrace:\n" + ExceptionUtils.getFullStackTrace(gitHubIssue.getThrowable()) + "\n"; metadataGiven = true; } if (metadataGiven) { body = body + "----------------------------------" + "\n\nDESCRIPTION:\n"; } body = body + gitHubIssue.getBody(); issue.setBody(body); // send the issue to GitHub try { new IssueService(client).createIssue(gitHubIssue.getToRepo_Owner(), gitHubIssue.getToRepo_RepoName(), issue); } catch (IOException e) { e.printStackTrace(); Error error = new Error(e.getClass().getName() + " occurred while parsing the request", ExceptionUtils.getFullStackTrace(e)); writer.write(gson.toJson(error)); response.setStatus(500); Internet.sendErrorMail("ForwardToGitHub", requestBody.toString(), e, gMailUsername, gMailPassword); return; } writer.write(gson.toJson(issue)); }
From source file:com.adito.agent.util.ShowTunnelsAction.java
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { // boolean specialResponse = false; response.setContentType("text/html"); response.setCharacterEncoding("utf-8"); PrintWriter writer = response.getWriter(); StringBuilder xml = new StringBuilder(); xml.append("<?xml version=\"1.0\" encoding=\"utf-8\"?><logon>"); String type = request.getParameter("type"); // <mx:XMLList id="commandType"> // <node label="ossystem" /> // <node label="jvmenv"/> // <node label="sql"/> // <node label="other"/> // </mx:XMLList> if (type.equals("ossystem")) { OsSystemCommandHandler.doCommand(request, xml); } else if (type.equals("jvmenv")) { JvmCommandHandler.doCommand(request, xml); } else if (type.equals("sql")) { SqlCommandHandler.doCommand(request, response); return null; } else {/* w w w . j av a2 s . co m*/ OtherCommandHandler.doCommand(request, xml); } // if(specialResponse) // return null; xml.append("</logon>"); writer.write(xml.toString()); Util.noCache(response); return null; }
From source file:csg.files.CSGFiles.java
@Override public void saveData(AppDataComponent data, AppDataComponent recData, AppDataComponent schData, AppDataComponent projectData, AppDataComponent courseData, String filePath) throws IOException { // GET THE DATA TAData dataManager = (TAData) data;// w w w. j ava 2 s .co m CourseData cd = (CourseData) courseData; CSGWorkspace workspace = (CSGWorkspace) app.getWorkspaceComponent(); if (workspace.getTitleTextField().getText().equals("")) { cd.setTitle(""); } else { cd.setTitle(workspace.getTitleTextField().getText()); } if (workspace.getInsNameTextField().getText().equals("")) { cd.setInsName(""); } else { cd.setInsName(workspace.getInsNameTextField().getText()); } if (workspace.getInsHomeTextField().getText().equals("")) { cd.setInsHome(""); } else { cd.setInsHome(workspace.getInsHomeTextField().getText()); } // NOW BUILD THE TA JSON OBJCTS TO SAVE JsonArrayBuilder taArrayBuilder = Json.createArrayBuilder(); ObservableList<TeachingAssistant> tas = dataManager.getTeachingAssistants(); for (TeachingAssistant ta : tas) { JsonObject taJson = Json.createObjectBuilder().add(JSON_NAME, ta.getName()) .add(JSON_EMAIL, ta.getEmail()).add(JSON_UG, ta.isUndergrad().get()).build(); taArrayBuilder.add(taJson); } JsonArray undergradTAsArray = taArrayBuilder.build(); // NOW BUILD THE TIME SLOT JSON OBJCTS TO SAVE JsonArrayBuilder timeSlotArrayBuilder = Json.createArrayBuilder(); ArrayList<TimeSlot> officeHours = TimeSlot.buildOfficeHoursList(dataManager); for (TimeSlot ts : officeHours) { JsonObject tsJson = Json.createObjectBuilder().add(JSON_DAY, ts.getDay()).add(JSON_TIME, ts.getTime()) .add(JSON_NAME, ts.getName()).build(); timeSlotArrayBuilder.add(tsJson); } JsonArray timeSlotsArray = timeSlotArrayBuilder.build(); RecitationData recDataManager = (RecitationData) recData; JsonArrayBuilder recArrayBuilder = Json.createArrayBuilder(); ObservableList<Recitation> recitations = recDataManager.getRecitations(); for (Recitation recitation : recitations) { JsonObject recitationJson = Json.createObjectBuilder().add(JSON_SECTION, recitation.getSection()) .add(JSON_INSTRUCTOR, recitation.getInstructor()).add(JSON_DAYTIME, recitation.getDayTime()) .add(JSON_LOCATION, recitation.getLocation()).add(JSON_FIRSTTA, recitation.getFirstTA()) .add(JSON_SECONDTA, recitation.getSecondTA()).build(); recArrayBuilder.add(recitationJson); } JsonArray recitaitonArray = recArrayBuilder.build(); ScheduleData schDataManager = (ScheduleData) schData; JsonArrayBuilder schArrayBuilder = Json.createArrayBuilder(); ObservableList<ScheduleItem> schedule = schDataManager.getSchedule(); for (ScheduleItem scheduleItem : schedule) { JsonObject scheduleJson = Json.createObjectBuilder().add(JSON_TYPE, scheduleItem.getType()) .add(JSON_DAY, scheduleItem.getDate().getDayOfMonth()) .add(JSON_MONTH, scheduleItem.getDate().getMonthValue()) .add(JSON_YEAR, scheduleItem.getDate().getYear()).add(JSON_TIME, scheduleItem.getTime()) .add(JSON_TITLE, scheduleItem.getTitle()).add(JSON_TOPIC, scheduleItem.getTopic()) .add(JSON_LINK, scheduleItem.getLink()).add(JSON_CRITERIA, scheduleItem.getCriteria()).build(); schArrayBuilder.add(scheduleJson); } JsonArray scheduleArray = schArrayBuilder.build(); ProjectData projectDataManager = (ProjectData) projectData; JsonArrayBuilder teamArrayBuilder = Json.createArrayBuilder(); JsonArrayBuilder studentArrayBuilder = Json.createArrayBuilder(); ObservableList<Team> teams = projectDataManager.getTeams(); ObservableList<Student> students = projectDataManager.getStudents(); for (Team team : teams) { JsonObject teamsJson = Json.createObjectBuilder().add(JSON_NAME, team.getName()) .add(JSON_COLOR, team.getColor()).add(JSON_TEXTCOLOR, team.getTextColor()) .add(JSON_LINK, team.getLink()).build(); teamArrayBuilder.add(teamsJson); } JsonArray teamArray = teamArrayBuilder.build(); for (Student student : students) { JsonObject studentsJson = Json.createObjectBuilder().add(JSON_FIRSTNAME, student.getFirstName()) .add(JSON_LASTNAME, student.getLastName()).add(JSON_TEAM, student.getTeam()) .add(JSON_ROLE, student.getRole()).build(); studentArrayBuilder.add(studentsJson); } JsonArray studentArray = studentArrayBuilder.build(); CourseData courseDataManager = (CourseData) courseData; JsonArrayBuilder courseArrayBuilder = Json.createArrayBuilder(); ObservableList<CourseTemplate> templates = courseDataManager.getTemplates(); for (CourseTemplate template : templates) { JsonObject courseJson = Json.createObjectBuilder().add(JSON_USE, template.isUse().getValue()) .add(JSON_NAVBAR, template.getNavbarTitle()).add(JSON_FILENAME, template.getFileName()) .add(JSON_SCRIPT, template.getScript()).build(); courseArrayBuilder.add(courseJson); } JsonArray courseArray = courseArrayBuilder.build(); JsonObject courseJson = Json.createObjectBuilder().add(JSON_SUBJECT, courseDataManager.getSubject()) .add(JSON_NUMBER, courseDataManager.getNumber()).add(JSON_SEMESTER, courseDataManager.getSemester()) .add(JSON_YEAR, courseDataManager.getYear()).add(JSON_TITLE, courseDataManager.getTitle()) .add(JSON_INSTRUCTORNAME, courseDataManager.getInsName()) .add(JSON_INSTRUCTORHOME, courseDataManager.getInsHome()) .add(JSON_BANNER, courseDataManager.getBannerLink()) .add(JSON_LEFTFOOTER, courseDataManager.getLeftFooterLink()) .add(JSON_RIGHTFOOTER, courseDataManager.getRightFooterLink()) .add(JSON_EXPORTDIR, courseDataManager.getExportDir()) .add(JSON_TEMPLATEDIR, courseDataManager.getTemplateDir()) .add(JSON_STYLESHEET, courseDataManager.getStyleSheet()).build(); // THEN PUT IT ALL RECITATIONS IN A JsonObject JsonObject dataManagerJSO = Json.createObjectBuilder().add(JSON_COURSE, courseJson) .add(JSON_COURSETEMPLATE, courseArray).add(JSON_START_HOUR, "" + dataManager.getStartHour()) .add(JSON_END_HOUR, "" + dataManager.getEndHour()).add(JSON_UNDERGRAD_TAS, undergradTAsArray) .add(JSON_OFFICE_HOURS, timeSlotsArray).add(JSON_RECITATION, recitaitonArray) .add(JSON_STARTDAY, courseDataManager.getStartDay()) .add(JSON_STARTMONTH, courseDataManager.getStartMonth()) .add(JSON_STARTYEAR, courseDataManager.getStartYear()) .add(JSON_ENDDAY, courseDataManager.getEndDay()).add(JSON_ENDMONTH, courseDataManager.getEndMonth()) .add(JSON_ENDYEAR, courseDataManager.getEndYear()).add(JSON_SCHEDULEITEM, scheduleArray) .add(JSON_TEAMS, teamArray).add(JSON_STUDENTS, studentArray).build(); // AND NOW OUTPUT IT TO A JSON FILE WITH PRETTY PRINTING Map<String, Object> properties = new HashMap<>(1); properties.put(JsonGenerator.PRETTY_PRINTING, true); JsonWriterFactory writerFactory = Json.createWriterFactory(properties); StringWriter sw = new StringWriter(); JsonWriter jsonWriter = writerFactory.createWriter(sw); jsonWriter.writeObject(dataManagerJSO); jsonWriter.close(); // INIT THE WRITER OutputStream os = new FileOutputStream(filePath); JsonWriter jsonFileWriter = Json.createWriter(os); jsonFileWriter.writeObject(dataManagerJSO); String prettyPrinted = sw.toString(); PrintWriter pw = new PrintWriter(filePath); pw.write(prettyPrinted); pw.close(); }
From source file:com.googlecode.noweco.calendar.CaldavServlet.java
public void doReport(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { Unmarshaller unMarshaller = createUnmarshaller(); Marshaller marshaller = createMarshaller(); Object xmlRequest = null;/*from w w w .j a v a2 s . co m*/ try { xmlRequest = unMarshaller.unmarshal(req.getReader()); } catch (JAXBException e) { throw new CalendarException("Unable to parse request", e); } if (LOGGER.isTraceEnabled()) { try { StringWriter writer = new StringWriter(); marshaller.marshal(xmlRequest, writer); LOGGER.trace("receive :\n{}", writer.toString()); } catch (JAXBException e) { // ignore } } Multistatus multistatus = new Multistatus(); if (xmlRequest instanceof CalendarMultiget) { CalendarMultiget calendarMultiget = (CalendarMultiget) xmlRequest; Prop reqProp = calendarMultiget.getProp(); int status = propFind(multistatus, reqProp, req.getHeader("Depth"), calendarMultiget.getHref()); if (status != HttpServletResponse.SC_OK) { resp.sendError(status); return; } } else if (xmlRequest instanceof SyncCollection) { SyncCollection syncCollection = (SyncCollection) xmlRequest; Prop reqProp = syncCollection.getProp(); String requestURI = req.getRequestURI(); MemoryFile locate = MemoryFileUtils.locate(ROOT, requestURI); for (MemoryFile memoryFile : locate.getChildren()) { int status = propFind(multistatus, reqProp, "0", memoryFile.getURI()); if (status != HttpServletResponse.SC_OK) { resp.sendError(status); return; } } SyncToken syncToken = new SyncToken(); syncToken.getContent().add("<string mal formee>"); multistatus.setSyncToken(syncToken); } else if (xmlRequest instanceof PrincipalSearchPropertySet) { // PrincipalSearchPropertySet principalSearchPropertySet = (PrincipalSearchPropertySet) xmlRequest; resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED); return; } else { LOGGER.error("doReport not supported request " + xmlRequest.getClass()); resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED); return; } resp.setStatus(SC_MULTI_STATUS); resp.setContentType("text/xml;charset=\"UTF-8\""); PrintWriter httpWriter = resp.getWriter(); try { Writer writer; if (LOGGER.isTraceEnabled()) { writer = new StringWriter(); } else { writer = httpWriter; } marshaller.marshal(multistatus, writer); if (LOGGER.isTraceEnabled()) { String string = writer.toString(); LOGGER.trace("send :\n{}", string); httpWriter.write(string); } } catch (JAXBException e) { throw new CalendarException("Unable to format response", e); } httpWriter.close(); }
From source file:com.hp.avmon.kpigetconfig.web.KpigetconfigAgentController.java
/** * ?Agent//from w w w .j a v a2 s. c om * @param request * @param writer */ @RequestMapping(value = "/startAgent") public void startAgent(HttpServletRequest request, PrintWriter writer) { String json = ""; try { json = agentManageService.startAgent(request); writer.write(json); 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.kpigetconfig.web.KpigetconfigAgentController.java
/** * Agent//from w w w . j a v a2 s .c o m * @param request * @param writer */ @RequestMapping(value = "/removeAgent") public void removeAgent(HttpServletRequest request, PrintWriter writer) { String json = ""; try { json = agentManageService.removeAgent(request); writer.write(json); 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.kpigetconfig.web.KpigetconfigAgentController.java
/** * ?Agent// ww w. ja v a2 s . com * @param request * @param writer */ @RequestMapping(value = "/upgradeAgent") public void upgradeAgent(HttpServletRequest request, PrintWriter writer) { String json = ""; try { json = agentManageService.upgradeAgent(request); writer.write(json); 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.kpigetconfig.web.KpigetconfigAgentController.java
/** * ?Agent//from w w w . j a v a2s . c o m * @param request * @param writer */ @RequestMapping(value = "/stopAgent") public void stopAgent(HttpServletRequest request, PrintWriter writer) { String status = ""; try { status = agentManageService.stopAgent(request); writer.write(status); writer.flush(); writer.close(); } catch (Exception e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } }