List of usage examples for javax.servlet.http HttpServletResponse setCharacterEncoding
public void setCharacterEncoding(String charset);
From source file:feedme.controller.HomePageServlet.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.//from w w w . ja v a 2s . c o 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.setCharacterEncoding("UTF-8"); request.setCharacterEncoding("UTF-8"); }
From source file:ch.ralscha.extdirectspring.controller.SSEWriter.java
public SSEWriter(HttpServletResponse response) { this.response = response; response.setContentType(EVENT_STREAM.toString()); response.setCharacterEncoding(EVENT_STREAM.getCharSet().name()); }
From source file:net.sourceforge.subsonic.controller.M3UController.java
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { response.setContentType("audio/x-mpegurl"); response.setCharacterEncoding(StringUtil.ENCODING_UTF8); Player player = playerService.getPlayer(request, response); String url = request.getRequestURL().toString(); url = url.replaceFirst("play.m3u.*", "stream?"); // Rewrite URLs in case we're behind a proxy. if (settingsService.isRewriteUrlEnabled()) { String referer = request.getHeader("referer"); url = StringUtil.rewriteUrl(url, referer); }/*from w ww . j a va2s . c o m*/ url = settingsService.rewriteRemoteUrl(url); if (player.isExternalWithPlaylist()) { createClientSidePlaylist(response.getWriter(), player, url); } else { createServerSidePlaylist(response.getWriter(), player, url); } return null; }
From source file:com.thinkberg.moxo.dav.LockHandler.java
private void sendLockAcquiredResponse(HttpServletResponse response, Lock lock) throws IOException { response.setContentType("text/xml"); response.setCharacterEncoding("UTF-8"); response.setHeader(HEADER_LOCK_TOKEN, "<" + lock.getToken() + ">"); Document propDoc = DocumentHelper.createDocument(); Element propEl = propDoc.addElement(TAG_PROP, "DAV:"); Element lockdiscoveryEl = propEl.addElement(TAG_LOCKDISCOVERY); lock.serializeToXml(lockdiscoveryEl); XMLWriter xmlWriter = new XMLWriter(response.getWriter()); xmlWriter.write(propDoc);/*from w w w .j a va 2 s .c om*/ log(propDoc); }
From source file:de.highbyte_le.weberknecht.request.view.JsonActionProcessor.java
public boolean processView(HttpServletRequest request, HttpServletResponse response, JsonView action) throws IOException, JSONException { response.setContentType("application/json"); response.setCharacterEncoding("UTF-8"); BufferedWriter writer = null; try {//from w w w. jav a 2 s . co m writer = new BufferedWriter(response.getWriter()); JSONWriter jsonWriter = new JSONWriter(writer); action.writeJson(jsonWriter); writer.flush(); } finally { if (writer != null) writer.close(); } return true; }
From source file:com.suntek.gztpb.controller.ChemicalController.java
@RequestMapping(value = "isCarrierExists.htm", method = RequestMethod.POST) public @ResponseBody String isCarrierExists(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException { response.setCharacterEncoding("utf-8"); String carrierNo = ""; try {/*from w ww .j ava 2 s . c o m*/ carrierNo = URLDecoder.decode(request.getParameter("carrierNo"), "utf-8"); } catch (UnsupportedEncodingException e) { System.out.println( "[gztpbwebsite]?????????!" + e.getMessage()); } if (carrierNo == "null" || carrierNo == "") { return "0"; } else { String carrier = chemicalService.isCarrierExists(carrierNo); if (carrierNo.equals("0")) return "0"; else return java.net.URLEncoder.encode(carrier, "utf-8"); } }
From source file:com.mirth.connect.server.servlets.CodeTemplateServlet.java
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // MIRTH-1745 response.setCharacterEncoding("UTF-8"); if (!isUserLoggedIn(request)) { response.sendError(HttpServletResponse.SC_FORBIDDEN); } else {//from w w w . j a v a 2s. c o m try { CodeTemplateController codeTemplateController = ControllerFactory.getFactory() .createCodeTemplateController(); ObjectXMLSerializer serializer = new ObjectXMLSerializer(); PrintWriter out = response.getWriter(); Operation operation = Operations.getOperation(request.getParameter("op")); Map<String, Object> parameterMap = new HashMap<String, Object>(); if (operation.equals(Operations.CODE_TEMPLATE_GET)) { CodeTemplate codeTemplate = (CodeTemplate) serializer .fromXML(request.getParameter("codeTemplate")); parameterMap.put("codeTemplate", codeTemplate); if (!isUserAuthorized(request, parameterMap)) { response.sendError(HttpServletResponse.SC_UNAUTHORIZED); } else { response.setContentType(APPLICATION_XML); serializer.toXML(codeTemplateController.getCodeTemplate(codeTemplate), out); } } else if (operation.equals(Operations.CODE_TEMPLATE_UPDATE)) { List<CodeTemplate> codeTemplates = (List<CodeTemplate>) serializer .fromXML(request.getParameter("codeTemplates")); parameterMap.put("codeTemplates", codeTemplates); if (!isUserAuthorized(request, parameterMap)) { response.sendError(HttpServletResponse.SC_UNAUTHORIZED); } else { codeTemplateController.updateCodeTemplates(codeTemplates); } } else if (operation.equals(Operations.CODE_TEMPLATE_REMOVE)) { CodeTemplate codeTemplate = (CodeTemplate) serializer .fromXML(request.getParameter("codeTemplate")); parameterMap.put("codeTemplate", codeTemplate); if (!isUserAuthorized(request, parameterMap)) { response.sendError(HttpServletResponse.SC_UNAUTHORIZED); } else { codeTemplateController.removeCodeTemplate(codeTemplate); } } } catch (RuntimeIOException rio) { logger.debug(rio); } catch (Throwable t) { logger.error(ExceptionUtils.getStackTrace(t)); throw new ServletException(t); } } }
From source file:net.acesinc.convergentui.content.ContentService.java
public String getDownstreamResponse() { RequestContext context = RequestContext.getCurrentContext(); // there is no body to send if (context.getResponseBody() == null && context.getResponseDataStream() == null) { return null; }/*from w ww. j a v a 2 s . c o m*/ String body = null; if (RequestContext.getCurrentContext().getResponseBody() != null) { body = RequestContext.getCurrentContext().getResponseBody(); } else { try { HttpServletResponse servletResponse = context.getResponse(); servletResponse.setCharacterEncoding("UTF-8"); InputStream is = null; boolean isGzipRequested = false; final String requestEncoding = context.getRequest().getHeader(ZuulHeaders.ACCEPT_ENCODING); if (requestEncoding != null && requestEncoding.equals("gzip")) { isGzipRequested = true; } is = context.getResponseDataStream(); InputStream inputStream = is; if (is != null) { if (context.sendZuulResponse()) { // if origin response is gzipped, and client has not requested gzip, // decompress stream // before sending to client // else, stream gzip directly to client if (context.getResponseGZipped() && !isGzipRequested) { try { inputStream = new GZIPInputStream(is); } catch (java.util.zip.ZipException ex) { System.out.println("gzip expected but not " + "received assuming unencoded response" + RequestContext.getCurrentContext().getRequest().getRequestURL() .toString()); inputStream = is; } } else if (context.getResponseGZipped() && isGzipRequested) { servletResponse.setHeader(ZuulHeaders.CONTENT_ENCODING, "gzip"); } body = IOUtils.toString(inputStream, "utf8"); } } } catch (IOException ioe) { log.warn("IOException getting output stream", ioe); } } return body; }
From source file:com.mirth.connect.server.servlets.DatabaseTaskServlet.java
@Override public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // MIRTH-1745 response.setCharacterEncoding("UTF-8"); if (!isUserLoggedIn(request)) { response.sendError(HttpServletResponse.SC_FORBIDDEN); } else {//from w w w. j ava 2 s .c o m try { DatabaseTaskController databaseTaskController = ControllerFactory.getFactory() .createDatabaseTaskController(); ObjectXMLSerializer serializer = ObjectXMLSerializer.getInstance(); PrintWriter out = response.getWriter(); Operation operation = Operations.getOperation(request.getParameter("op")); Map<String, Object> parameterMap = new HashMap<String, Object>(); ServerEventContext context = new ServerEventContext(); context.setUserId(getCurrentUserId(request)); if (operation.equals(Operations.DATABASE_TASKS_GET)) { if (!isUserAuthorized(request, null)) { response.sendError(HttpServletResponse.SC_UNAUTHORIZED); } else { serializer.serialize(databaseTaskController.getDatabaseTasks(), out); } } else if (operation.equals(Operations.DATABASE_TASK_RUN)) { DatabaseTask databaseTask = serializer .deserialize((String) request.getParameter("databaseTask"), DatabaseTask.class); parameterMap.put("databaseTask", databaseTask); if (!isUserAuthorized(request, parameterMap)) { response.sendError(HttpServletResponse.SC_UNAUTHORIZED); } else { String result = databaseTaskController.runDatabaseTask(databaseTask); if (StringUtils.isNotBlank(result)) { out.write(result); } } } else if (operation.equals(Operations.DATABASE_TASK_CANCEL)) { DatabaseTask databaseTask = serializer .deserialize((String) request.getParameter("databaseTask"), DatabaseTask.class); parameterMap.put("databaseTask", databaseTask); if (!isUserAuthorized(request, parameterMap)) { response.sendError(HttpServletResponse.SC_UNAUTHORIZED); } else { databaseTaskController.cancelDatabaseTask(databaseTask); } } } catch (RuntimeIOException rio) { logger.debug(rio); } catch (Throwable t) { logger.error(ExceptionUtils.getStackTrace(t)); throw new ServletException(t); } } }
From source file:com.nesscomputing.jmx.jolokia.JolokiaServlet.java
private void sendResponse(final HttpServletResponse resp, final String contentType, final String jsonTxt) throws IOException { resp.setCharacterEncoding("utf-8"); resp.addHeader("Access-Control-Allow-Origin", "*"); resp.setContentType(contentType);/* ww w. jav a2s . c o m*/ resp.setStatus(HttpServletResponse.SC_OK); final PrintWriter writer = resp.getWriter(); writer.write(jsonTxt); writer.flush(); }