Example usage for javax.servlet.http HttpServletResponse getCharacterEncoding

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

Introduction

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

Prototype

public String getCharacterEncoding();

Source Link

Document

Returns the name of the character encoding (MIME charset) used for the body sent in this response.

Usage

From source file:org.wings.session.PortletWingServlet.java

/**
 * create a Device that is used to deliver the content, that is
 * not session specific, i.e. that is delivered by the SystemExternalizer.
 * The default// ww  w.  j a v  a2  s .  c  o m
 * implementation just creates a ServletDevice. You can override this
 * method to decide yourself what happens to the output. You might, for
 * instance, write some device, that logs the output for debugging
 * purposes, or one that creates a gziped output stream to transfer
 * data more efficiently. You get the request and response as well as
 * the ExternalizedResource to decide, what kind of device you want to create.
 * You can rely on the fact, that extInfo is not null.
 * Further, you can rely on the fact, that noting has been written yet
 * to the output, so that you can set you own set of Headers.
 *
 * @param request  the HttpServletRequest that is answered
 * @param response the HttpServletResponse.
 * @param extInfo  the externalized info of the resource about to be
 *                 delivered.
 */
protected Device createOutputDevice(HttpServletRequest request, HttpServletResponse response,
        ExternalizedResource extInfo) throws IOException {
    return new ServletDevice(response.getOutputStream(), response.getCharacterEncoding());
}

From source file:org.codelibs.fess.helper.CrawlingConfigHelper.java

protected void writeContentType(final HttpServletResponse response, final ResponseData responseData) {
    final String mimeType = responseData.getMimeType();
    if (logger.isDebugEnabled()) {
        logger.debug("mimeType: " + mimeType);
    }//from  w  w  w .j  a  v a 2 s .c om
    if (mimeType == null) {
        return;
    }
    if (mimeType.startsWith("text/")) {
        final String charset = response.getCharacterEncoding();
        if (charset != null) {
            response.setContentType(mimeType + "; charset=" + charset);
            return;
        }
    }
    response.setContentType(mimeType);
}

From source file:org.codehaus.groovy.grails.web.metaclass.RenderDynamicMethod.java

private boolean renderMarkup(Closure closure, HttpServletResponse response) {
    boolean renderView;
    StreamingMarkupBuilder b = new StreamingMarkupBuilder();
    b.setEncoding(response.getCharacterEncoding());
    Writable markup = (Writable) b.bind(closure);
    try {/*  w w  w .  ja v a2 s  .c  o m*/
        markup.writeTo(response.getWriter());
    } catch (IOException e) {
        throw new ControllerExecutionException(
                "I/O error executing render method for arguments [" + closure + "]: " + e.getMessage(), e);
    }
    renderView = false;
    return renderView;
}

From source file:eionet.util.Util.java

public static void forward2errorpage(HttpServletRequest request, HttpServletResponse response, Throwable t,
        String backURL) throws ServletException, IOException {

    String msg = t.getMessage();// w  w  w .j a v  a 2s  .c o m

    ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
    t.printStackTrace(new PrintStream(bytesOut));

    String trace = bytesOut.toString(response.getCharacterEncoding());

    request.setAttribute("DD_ERR_MSG", msg);
    request.setAttribute("DD_ERR_TRC", trace);
    request.setAttribute("DD_ERR_BACK_LINK", backURL);

    request.getRequestDispatcher("error.jsp").forward(request, response);
}

From source file:net.ymate.platform.webmvc.view.impl.JsonView.java

protected void __doRenderView() throws Exception {
    HttpServletResponse _response = WebContext.getResponse();
    if (StringUtils.isNotBlank(getContentType())) {
        _response.setContentType(getContentType());
    } else if (this.__withContentType) {
        if (__jsonCallback == null) {
            _response.setContentType(Type.ContentType.JSON.getContentType());
        } else {/*w w w  .  j av  a  2s  . c  o  m*/
            _response.setContentType(Type.ContentType.JAVASCRIPT.getContentType());
        }
    }
    StringBuilder _jsonStr = new StringBuilder(__jsonObj.toString());
    if (__jsonCallback != null) {
        _jsonStr.insert(0, __jsonCallback + "(").append(");");
    }
    IOUtils.write(_jsonStr.toString(), _response.getOutputStream(), _response.getCharacterEncoding());
}

From source file:org.opi.web.view.AbstractXslFoView.java

/**
 * Perform the actual transformation, writing to the HTTP response via the
 * FOP Driver./*from  w  ww .j a v a2  s .c o  m*/
 */
protected void doTransform(Map model, Source source, HttpServletRequest request, HttpServletResponse response)
        throws Exception {
    response.setHeader("Content-Disposition", "inline");
    response.setContentType("application/pdf");

    FopFactory fopFactory = FopFactory.newInstance();

    if (log.isInfoEnabled()) {
        log.info("ContextPath = " + request.getSession().getServletContext().getRealPath("/"));
    }

    OutputStream os = response.getOutputStream();

    Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, os);

    Result intermediateFile = new SAXResult(fop.getDefaultHandler());

    // Delegate to the superclass for the actual output having constructed the result.
    super.doTransform(source, getParameters(request), intermediateFile, response.getCharacterEncoding());

    log.info("success");
}

From source file:nl.opengeogroep.dbk.DBKAPI.java

/**
 * Processes the request for retrieving the media belonging to a DBK.
 * @param method The part of the url after /api/, containing the file name (and possible subdirectory)
 * @param request The http request/*from ww  w . j av a2s.  co m*/
 * @param response The http response
 * @param out The outputstream to which the file must be written.
 * @throws IOException 
 */
private void processMedia(String method, HttpServletRequest request, HttpServletResponse response,
        OutputStream out) throws IOException {
    FileInputStream fis = null;
    File requestedFile = null;
    String basePath = request.getServletContext().getInitParameter("dbk.media.path");
    try {
        String fileArgument = method.substring(method.indexOf(MEDIA) + MEDIA.length());
        String totalPath = basePath + File.separatorChar + fileArgument;

        totalPath = URLDecoder.decode(totalPath, response.getCharacterEncoding());
        requestedFile = new File(totalPath);

        fis = new FileInputStream(requestedFile);
        response.setContentType(request.getServletContext().getMimeType(totalPath));
        Long size = requestedFile.length();
        response.setContentLength(size.intValue());
        IOUtils.copy(fis, out);
    } catch (IOException ex) {
        log.error("Error retrieving media.", ex);
        if (requestedFile != null) {
            log.error("Cannot load media: " + requestedFile.getCanonicalPath() + " from basePath: " + basePath);
        }
        response.setStatus(HttpServletResponse.SC_NOT_FOUND);
    } finally {
        if (fis != null) {
            fis.close();
        }
    }
}

From source file:org.apache.myfaces.renderkit.html.util.DefaultAddResource.java

/**
 * Writes the response//from   ww  w . j  ava  2 s .c  o  m
 */
public void writeResponse(HttpServletRequest request, HttpServletResponse response) throws IOException {
    ResponseWriter writer = new HtmlResponseWriterImpl(response.getWriter(),
            HtmlRendererUtils.selectContentType(request.getHeader("accept")), response.getCharacterEncoding());
    writer.write(originalResponse.toString());
}

From source file:net.ymate.platform.mvc.web.view.impl.JsonView.java

protected void renderView() throws Exception {
    HttpServletResponse response = WebContext.getResponse();
    if (StringUtils.isNotBlank(getContentType())) {
        response.setContentType(getContentType());
    } else if (this.withContentType) {
        if (this.jsonpCallback == null) {
            response.setContentType(JSON_CONTENT_TYPE);
        } else {/*from w  w w.j ava 2  s  .com*/
            response.setContentType(JAVASCRIPT_CONTENT_TYPE);
        }
    }
    StringBuilder _jsonStr = new StringBuilder(jsonObj.toString());
    if (this.jsonpCallback != null) {
        _jsonStr.insert(0, this.jsonpCallback + "(").append(");");
    }
    IOUtils.write(_jsonStr.toString(), response.getOutputStream(), StringUtils
            .defaultIfEmpty(WebMVC.getConfig().getCharsetEncoding(), response.getCharacterEncoding()));
}

From source file:org.apache.myfaces.tomahawk.application.jsp.JspTilesTwoViewHandlerImpl.java

private void handleCharacterEncodingPostDispatch(ExternalContext externalContext) {
    // handle character encoding as of section 2.5.2.2 of JSF 1.1
    if (externalContext.getRequest() instanceof HttpServletRequest) {
        HttpServletResponse response = (HttpServletResponse) externalContext.getResponse();
        HttpServletRequest request = (HttpServletRequest) externalContext.getRequest();
        HttpSession session = request.getSession(false);

        if (session != null) {
            session.setAttribute(ViewHandler.CHARACTER_ENCODING_KEY, response.getCharacterEncoding());
        }/* w w  w  .j  a v  a 2 s  .  c o m*/
    }
}