List of usage examples for javax.servlet.http HttpServletResponse getWriter
public PrintWriter getWriter() throws IOException;
PrintWriter
object that can send character text to the client. From source file:org.apache.cxf.fediz.service.idp.MetadataServlet.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/xml; charset=utf-8"); PrintWriter out = response.getWriter(); try {// w w w.j a v a2 s. co m ConfigService cs = (ConfigService) getApplicationContext().getBean("config"); Idp idpConfig = cs.getIDP(realm); LOG.debug(idpConfig.toString()); MetadataWriter mw = new MetadataWriter(); Document metadata = mw.getMetaData(idpConfig); out.write(DOM2Writer.nodeToString(metadata)); } catch (Exception ex) { LOG.error("Failed to get metadata document: ", ex); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } }
From source file:com.cimpoint.mes.server.servlets.CustomCodeServlet.java
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { if (request.getParameter("action").equals("GetModule")) { PrintWriter out = response.getWriter(); DynamicForm form = createTestForm(); JavaScriptObject jsObj = form.getJsObj(); String src = jsObj.toSource(); out.write(src);/*from www . jav a2 s .co m*/ } }
From source file:com.netease.channel.controller.BaseController.java
protected void successRes(HttpServletResponse respose, String res) { respose.setContentType(JSON_CONTENT_TYPE); try {/*from ww w .j a v a 2 s .c o m*/ respose.getWriter().write(res); respose.getWriter().close(); } catch (IOException e) { LOG.info("Controller response error"); } }
From source file:org.ng200.openolympus.controller.auth.OpenOlympusAuthenticationSuccessHandler.java
@Override public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException { response.setContentType("application/json"); AuthenticationResponder.writeLoginStatusJson(response.getWriter(), "succeded", null); }
From source file:es.tid.cep.esperanza.Events.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request//from w w w . j a v a2s .com * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { logger.debug("events doPost"); PrintWriter out = response.getWriter(); try { response.setContentType("application/json;charset=UTF-8"); ServletInputStream sis = request.getInputStream(); byte[] b = new byte[request.getContentLength()]; sis.read(b, 0, b.length); sis.close(); String eventText = new String(b); logger.debug("event as text:" + eventText); org.json.JSONObject jo = new JSONObject(eventText); logger.debug("event as JSONObject: " + jo); Map<String, Object> otro = Utils.JSONObject2Map(jo); logger.debug("event as map: " + otro); epService.getEPRuntime().sendEvent(otro, "iotEvent"); logger.debug("event was sent: " + otro); } catch (JSONException je) { logger.debug("error: " + je.getMessage()); response.setStatus(HttpServletResponse.SC_BAD_REQUEST); out.printf("{\"error\":\"%s\"}\n", je.getMessage()); } finally { out.close(); } }
From source file:io.neba.core.selftests.SelftestConsolePlugin.java
private void writeScriptIncludes(HttpServletRequest request, HttpServletResponse response) throws IOException { response.getWriter().write("<script src=\"" + getLabel() + "/static/script.js\"></script>"); }
From source file:com.enonic.cms.core.tools.LivePortalTraceController.java
private void returnJson(String json, HttpServletResponse res) throws Exception { res.setHeader("Content-Type", "application/json; charset=UTF-8"); res.getWriter().println(json); }
From source file:com.suntek.gztpb.controller.ChangeContactControll.java
@RequestMapping(value = "success.htm", method = RequestMethod.POST) public @ResponseBody String saveTest(DriverChangeModel driverInfo, HttpServletRequest request, HttpServletResponse response) throws Exception { response.setContentType("text/html"); response.setCharacterEncoding("utf-8"); PrintWriter out = response.getWriter(); String applyNum = IdGenerator.getInstance().getBizCode("ITMS_SEQ", 5); driverInfo.setApplynum(applyNum);/*from w w w.j ava2 s. c om*/ System.out.println("applyNum=" + applyNum); driverInfo.setBiztype("3001"); driverInfo.setCreatedtime(new Date()); driverInfo.setCreator("admin"); driverInfo.setSource(0); driverInfo.setSubmittime(new Date()); driverInfo.setFinish(0); try { driverChangeService.signUp(driverInfo); out.write("<script>parent.saveCallback(1,'" + applyNum + "')</script>"); } catch (Exception e) { e.printStackTrace(); out.write("<script>parent.saveCallback(0)</script>"); } return null; }
From source file:edu.lafayette.metadb.web.attributesman.UpdateAdminDescAttributes.java
/** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) *///from w ww .ja v a 2 s .c o m protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter out = response.getWriter(); JSONObject output = new JSONObject(); String project = (String) request.getSession(false).getAttribute(Global.SESSION_PROJECT); String notification = ""; boolean success = true; try { JSONObject inputs = new JSONObject(request.getParameter("data")); String type = inputs.getString("type"); JSONArray data = (JSONArray) inputs.get("data"); for (int i = 0; i < data.length(); i++) { JSONObject datum = (JSONObject) data.get(i); String element = datum.getString("elements"); String label = datum.getString("label"); int id = -1; try { id = Integer.parseInt(datum.getString("id")); } catch (NumberFormatException e) { id = -1; } boolean isSorted = datum.getString("sorted").equals("true"); boolean isLarge = datum.getString("large").equals("true"); boolean isControlled = datum.getString("controlled").equals("true"); boolean isMultiple = datum.getString("multiple").equals("true"); boolean isAdditions = datum.getString("additions").equals("true"); boolean isReadableDate = datum.getString("display-date").equals("true"); boolean isSearchableDate = datum.getString("search-date").equals("true"); try { AdminDescAttributesDAO.update(project, id, element, label, type, isLarge, isReadableDate, isSearchableDate, isControlled, isMultiple, isAdditions, isSorted, i); } catch (DuplicateAttributeException e) { // MetaDbHelper.note("DuplicateAttributeException caught in servlet"); success = false; notification += "Duplicate element.qualifier fields are not permitted. The second instance of <b><i>" + element + (label.equals("") ? "" : "." + label) + "</b></i> could not be saved. <br/>"; //MetaDbHelper.note("Duplicate fields found."); } catch (Exception e) { success = false; notification += "Attr " + i + " cannot be updated:<br/>"; notification += "Project " + project + ", field " + element + " " + label + " at index " + i + "<br/>"; //MetaDbHelper.note("Cannot update: "+project+" "+element+" "+label+" "+type+" "+isLarge+" "+isControlled+" "+isSorted+" "+isMultiple+" "+isAdditions+" "+i); } } output.put("success", success); output.put("message", notification); out.print(output); } catch (Exception e) { MetaDbHelper.logEvent(e); } out.close(); }
From source file:net.mindengine.oculus.frontend.web.controllers.report.ReportUploadFileController.java
@Override public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { response.setContentType("text/html"); PrintWriter pw = response.getWriter(); log.info("uploading file"); boolean isMultipart = ServletFileUpload.isMultipartContent(request); if (isMultipart) { DefaultMultipartHttpServletRequest multipartRequest = (DefaultMultipartHttpServletRequest) request; int i = 0; boolean bNext = true; while (bNext) { i++;//from w ww .j a va 2 s . co m MultipartFile multipartFile = multipartRequest.getFile("file" + i); if (multipartFile != null) { fileId++; Date date = new Date(); String path = FileUtils.generatePath(date); String fullDirPath = config.getDataFolder() + File.separator + path; File dir = new File(fullDirPath); dir.mkdirs(); //FileUtils.mkdirs(config.getDataFolder() + File.separator + path); String fileType = FileUtils.getFileType(multipartFile.getOriginalFilename()).toLowerCase(); path += File.separator + date.getTime() + "_" + fileId + "." + fileType; File file = new File(config.getDataFolder() + File.separator + path); file.createNewFile(); FileOutputStream fos = new FileOutputStream(file); fos.write(multipartFile.getBytes()); fos.close(); if (fileType.equals("png") || fileType.equals("jpg") || fileType.equals("gif") || fileType.equals("bmp")) { pw.println("[uploaded]?type=image-" + fileType + "&object=" + date.getTime() + "&item=" + fileId); } if (fileType.equals("txt") || fileType.equals("json") || fileType.equals("xml")) { pw.println("[uploaded]?type=text-" + fileType + "&object=" + date.getTime() + "&item=" + fileId); } } else bNext = false; } } else pw.print("[error]not a multipart content"); return null; }