Example usage for javax.servlet.http HttpServletResponse setCharacterEncoding

List of usage examples for javax.servlet.http HttpServletResponse setCharacterEncoding

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletResponse setCharacterEncoding.

Prototype

public void setCharacterEncoding(String charset);

Source Link

Document

Sets the character encoding (MIME charset) of the response being sent to the client, for example, to UTF-8.

Usage

From source file:com.mirth.connect.server.servlets.EngineServlet.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 ww. j  a v  a2 s . c om
        try {
            EngineController engineController = ControllerFactory.getFactory().createEngineController();
            ObjectXMLSerializer serializer = new ObjectXMLSerializer();
            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.CHANNEL_REDEPLOY)) {
                if (!isUserAuthorized(request, null) || doesUserHaveChannelRestrictions(request)) {
                    response.sendError(HttpServletResponse.SC_UNAUTHORIZED);
                } else {
                    engineController.redeployAllChannels(context);
                }
            } else if (operation.equals(Operations.CHANNEL_DEPLOY)) {
                List<String> channelIds = (List<String>) serializer.fromXML(request.getParameter("channelIds"));
                parameterMap.put("channelIds", channelIds);

                if (!isUserAuthorized(request, parameterMap)) {
                    response.sendError(HttpServletResponse.SC_UNAUTHORIZED);
                } else {
                    engineController.deployChannels(channelIds, context);
                }
            } else if (operation.equals(Operations.CHANNEL_UNDEPLOY)) {
                List<String> channelIds = (List<String>) serializer.fromXML(request.getParameter("channelIds"));
                parameterMap.put("channelIds", channelIds);

                if (!isUserAuthorized(request, parameterMap)) {
                    response.sendError(HttpServletResponse.SC_UNAUTHORIZED);
                } else {
                    engineController.undeployChannels(channelIds, context);
                }
            }
        } catch (RuntimeIOException rio) {
            logger.debug(rio);
        } catch (Throwable t) {
            logger.error(ExceptionUtils.getStackTrace(t));
            throw new ServletException(t);
        }
    }
}

From source file:feedme.controller.LogoutServlet.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./*from   ww  w . j  a v a 2  s. 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.setContentType("text/html;charset=UTF-8");
    response.setCharacterEncoding("UTF-8");

}

From source file:org.kemri.wellcome.controller.ReportDefinitionController.java

@RequestMapping(value = Views.EXPORT, method = RequestMethod.GET)
public void export(HttpServletResponse response) throws Exception {
    response.setContentType("application/xml");
    response.setCharacterEncoding("UTF-8");
    response.addHeader("Content-Disposition", "attachment; filename=ReportDefinition.xml");
    ReportTemplates templates = service.getReportTemplates();
    if (templates != null)
        service.marshallReportTemplates(response.getOutputStream(), templates);
}

From source file:ai.susi.server.api.susi.GenericScraper.java

/**
  * PrintJSON/* w w  w .j  a  v  a 2  s.co  m*/
  * @param response
  * @param JSONObject genericScraperData
  */
public void printJSON(HttpServletResponse response, JSONObject genericScraperData)
        throws ServletException, IOException {
    response.setCharacterEncoding("UTF-8");
    PrintWriter sos = response.getWriter();
    sos.print(genericScraperData.toString(2));
    sos.println();
}

From source file:com.casker.portfolio.controller.PortfolioAdminController.java

/**
 * ?? ?/*from  w w w .  ja v a 2 s.  com*/
 * 
 * @return
 */
@ResponseBody
@RequestMapping(value = "/manegement/portfolio/write", method = RequestMethod.POST)
public String writePortfolio(HttpServletResponse response, Portfolio portfolio) {

    portfolioService.addPortfolio(portfolio);

    response.setCharacterEncoding("UTF-8");
    return ScriptUtil.alertAndRedirect("?? ??.",
            "/admin/manegement/portfolio");
}

From source file:com.mirth.connect.server.servlets.AlertServlet.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  va2 s  .co m
        try {
            AlertController alertController = ControllerFactory.getFactory().createAlertController();
            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.ALERT_GET)) {
                Alert alert = (Alert) serializer.fromXML(request.getParameter("alert"));
                parameterMap.put("alert", alert);

                if (!isUserAuthorized(request, parameterMap)) {
                    response.sendError(HttpServletResponse.SC_UNAUTHORIZED);
                } else {
                    response.setContentType(APPLICATION_XML);
                    serializer.toXML(alertController.getAlert(alert), out);
                }
            } else if (operation.equals(Operations.ALERT_UPDATE)) {
                List<Alert> alerts = (List<Alert>) serializer.fromXML(request.getParameter("alerts"));
                parameterMap.put("alerts", alerts);

                if (!isUserAuthorized(request, parameterMap)) {
                    response.sendError(HttpServletResponse.SC_UNAUTHORIZED);
                } else {
                    alertController.updateAlerts(alerts);
                }
            } else if (operation.equals(Operations.ALERT_REMOVE)) {
                Alert alert = (Alert) serializer.fromXML(request.getParameter("alert"));
                parameterMap.put("alert", alert);

                if (!isUserAuthorized(request, parameterMap)) {
                    response.sendError(HttpServletResponse.SC_UNAUTHORIZED);
                } else {
                    alertController.removeAlert(alert);
                }
            }
        } catch (RuntimeIOException rio) {
            logger.debug(rio);
        } catch (Throwable t) {
            logger.error(ExceptionUtils.getStackTrace(t));
            throw new ServletException(t);
        }
    }
}

From source file:com.casker.portfolio.controller.PortfolioAdminController.java

/**
 * ?? /*from  ww  w  .  jav a  2  s. co  m*/
 * 
 * @return
 */
@ResponseBody
@RequestMapping(value = "/manegement/portfolio/edit", method = RequestMethod.POST)
public String editPortfolio(HttpServletResponse response, Portfolio portfolio) {

    portfolioService.editPortfolio(portfolio);

    response.setCharacterEncoding("UTF-8");
    return ScriptUtil.alertAndRedirect("?? ?.",
            "/admin/manegement/portfolio");
}

From source file:org.inbio.common.web.controller.XMLResponseMultiActionController.java

/**
 * //w w w  .  j  a va 2s  .co m
 * @param request
 * @param response
 * @param doc
 * @return
 * @throws Exception
 */
public ModelAndView writeXMLDocumentOnResponse(HttpServletRequest request, HttpServletResponse response,
        Document doc) throws Exception {

    // return response XML
    XMLOutputter xmlOutputter = new XMLOutputter();

    response.setCharacterEncoding(urlCharset);
    response.setContentType("text/xml;charset=" + urlCharset);
    ServletOutputStream out = response.getOutputStream(); // binary output

    xmlOutputter.output(doc, out);
    out.flush();
    out.close();

    return null;
}

From source file:com.surfs.storage.web.controller.storage.LoginController.java

@RequestMapping(method = RequestMethod.GET, value = "/test.do")
@ResponseBody/*from   www.  j a  va  2  s  . c o  m*/
public void test(HttpServletRequest request, HttpServletResponse response) {
    try {
        response.setHeader("Content-Type", "text/event-stream");
        response.setHeader("Cache-Control", "no-cache");
        response.setCharacterEncoding("UTF-8");
        response.getWriter().println("data:" + new Date().toString());
        response.getWriter().println();
        response.getWriter().flush();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:org.easyj.rest.view.EasyView.java

protected void setUpResponse(HttpServletResponse response) {
    response.setContentType(getContentType());
    response.setCharacterEncoding(getEncoding());
    if (isPreventCache()) {
        responsePreventCache(response);/* ww  w . j ava 2 s.co  m*/
    }
}