Example usage for javax.servlet.http HttpServletResponse getContentType

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

Introduction

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

Prototype

public String getContentType();

Source Link

Document

Returns the content type used for the MIME body sent in this response.

Usage

From source file:com.laxser.blitz.web.instruction.InputStreamInstruction.java

@Override
protected void doRender(Invocation inv) throws IOException, ServletException, Exception {
    InputStream inputStream = this.inputStream;
    if (inputStream == null) {
        return;//from w  w  w  . ja v a 2  s.com
    }
    HttpServletResponse response = inv.getResponse();
    if (response.getContentType() == null) {
        response.setContentType("application/octet-stream");
        if (logger.isDebugEnabled()) {
            logger.debug("set response.contentType by default:" + response.getContentType());
        }
    }
    try {
        byte[] buffer = new byte[bufferSize];
        int read;
        OutputStream out = null;
        while ((read = inputStream.read(buffer)) != -1) {
            if (read == 0) {
                continue;
            }
            if (out == null) {
                out = inv.getResponse().getOutputStream();
            }
            out.write(buffer, 0, read);
        }
        out.flush();
    } finally {
        inputStream.close();
    }
}

From source file:com.qwazr.webapps.exception.WebappException.java

@Override
public void sendQuietly(HttpServletResponse response) {
    try {//www.j  a va  2s.  co  m
        String contentType = response.getContentType();
        response.setStatus(error.status);
        if (contentType != null) {
            if (contentType.startsWith("application/xml")) {
                sendQuietlyXML(response);
                return;
            } else if (contentType.startsWith("application/json")) {
                sendQuietlyJSON(response);
                return;
            }
        }
        sendQuietlyHTML(response);
    } catch (IOException e) {
        if (logger.isWarnEnabled())
            logger.warn(e.getMessage(), e);
    }
}

From source file:fragment.web.LogoControllerTest.java

private void checkCorrectnessOfMethod(HttpServletResponse response) {
    Assert.assertTrue(response.getContentType().contains("image/"));
    Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatus());
}

From source file:com.dreambox.web.logger.LoggingFilter.java

private boolean isJson(HttpServletResponse response) {
    return response.getContentType() != null && response.getContentType().startsWith("application/json");
}

From source file:eu.freme.broker.tools.loggingfilter.LoggingFilter.java

public boolean checkAgainstWhitelist(HttpServletResponse response) {
    String compare = response.getContentType();
    return checkAgainstWhitelist(compare);
}

From source file:cn.guoyukun.spring.web.filter.DebugRequestAndResponseFilter.java

private void debugResponse(HttpServletResponse response) {
    log.debug("=====================response begin==========================");
    log.debug("status:{}", response.getStatus(), response.getContentType());
    log.debug("contentType:{}, characterEncoding:{}", response.getContentType(),
            response.getCharacterEncoding());
    log.debug("===header begin============================================");
    Collection<String> headerNames = response.getHeaderNames();
    for (String name : headerNames) {
        String value = StringUtils.join(response.getHeaders(name), "||");
        log.debug("{}={}", name, value);
    }//from  w  ww.j a  v a2  s  . c  om
    log.debug("===header   end============================================");
    log.debug("=====================response   end==========================");
}

From source file:com.qwazr.library.freemarker.FreeMarkerTool.java

public void template(final String templatePath, final Locale locale, final Map<String, Object> dataModel,
        final HttpServletResponse response) throws TemplateException, IOException {
    if (response.getContentType() == null)
        response.setContentType(defaultContentType == null ? DEFAULT_CONTENT_TYPE : defaultContentType);
    response.setCharacterEncoding(DEFAULT_CHARSET);
    final Template template = cfg.getTemplate(templatePath, locale);
    template.process(dataModel, response.getWriter());
}

From source file:org.zkoss.zkgrails.ZKGrailsPageFilter.java

private void detectContentTypeFromPage(Page page, HttpServletResponse response) {
    String contentType = page.getProperty("meta.http-equiv.Content-Type");
    if (contentType != null && "text/html".equals(response.getContentType())) {
        response.setContentType(contentType);
    }/*from w ww  .j av a 2  s. co  m*/
}

From source file:fr.mby.portal.coreimpl.message.AbstractMimeReply.java

/**
 * @param backingOutputStream//from   w  ww.  j ava 2s.  com
 * @param backingStream
 * 
 */
public AbstractMimeReply(final HttpServletResponse response, final OutputStream backingOutputStream) {
    super();

    this.contentType = response.getContentType();
    this.characterEncoding = response.getCharacterEncoding();
    this.backingStream = backingOutputStream;
}

From source file:org.jasig.portlet.cms.controller.DownloadPostAttachmentController.java

@RequestMapping
protected void handleRequest(final HttpServletRequest request, final HttpServletResponse response)
        throws Exception {

    final HttpSession session = request.getSession();
    final Attachment attachment = (Attachment) session.getAttribute("attachment");

    logDebug("Attempting to download attachment: " + attachment);

    response.setContentType("application/x-download");

    logDebug("Set content type to: " + response.getContentType());

    final String encoding = response.getCharacterEncoding();

    logDebug("Encoded file name based on: " + encoding);

    final String fileName = URLEncoder.encode(attachment.getFileName(), encoding);
    response.setHeader("Content-Disposition", "attachment; filename=" + fileName);

    logDebug("Downloading file: " + fileName);

    final OutputStream out = response.getOutputStream();
    out.write(attachment.getContents());
    out.flush();//from   w  ww.j a va2 s . c om

    logDebug("Clearing session attribute");
    session.setAttribute("attachment", null);

}