Example usage for javax.servlet.http HttpServletRequest getContentType

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

Introduction

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

Prototype

public String getContentType();

Source Link

Document

Returns the MIME type of the body of the request, or null if the type is not known.

Usage

From source file:com.legstar.c2ws.servlet.C2wsProxy.java

/**
 * Check that the client is sending a content type that we understand.
 * @param request the http request/* w w w. j  a  va2 s  . c om*/
 * @return true if the request has supported encoding
 */
private boolean isSupportedContentType(final HttpServletRequest request) {
    if (request.getContentType().trim().compareToIgnoreCase(BINARY_CONTENT_TYPE) == 0
            || request.getContentType().trim().compareToIgnoreCase(APPLICATION_CONTENT_TYPE) == 0) {
        return true;
    }
    return false;
}

From source file:org.jamwiki.servlets.ImportTiddlyWikiServlet.java

/**
 * This method handles the request after its parent class receives control.
 *
 * @param request - Standard HttpServletRequest object.
 * @param response - Standard HttpServletResponse object.
 * @return A <code>ModelAndView</code> object to be handled by the rest of the Spring framework.
 *///  w  w  w . j  ava  2 s  .  c  om
protected ModelAndView handleJAMWikiRequest(HttpServletRequest request, HttpServletResponse response,
        ModelAndView next, WikiPageInfo pageInfo) throws Exception {
    String contentType = ((request.getContentType() == null) ? "" : request.getContentType().toLowerCase());
    if (contentType.indexOf("multipart") == -1) {
        view(request, next, pageInfo);
    } else {
        importFile(request, next, pageInfo);
    }
    return next;
}

From source file:org.jbpm.formModeler.service.bb.mvc.controller.requestChain.MultipartProcessor.java

public boolean processRequest(CommandRequest request) throws Exception {
    HTTPSettings httpSettings = HTTPSettings.lookup();
    HttpServletRequest httpReq = request.getRequestObject();
    HttpServletResponse httpRes = request.getResponseObject();
    String contentType = httpReq.getContentType();
    String method = httpReq.getMethod();
    if ("POST".equalsIgnoreCase(method) && contentType != null && contentType.startsWith("multipart")
            && httpSettings.isMultipartProcessing()) {
        log.debug("Found multipart request. Building wrapper");

        String tmpDir = SessionTmpDirFactory.getTmpDir(httpReq);
        if (log.isDebugEnabled())
            log.debug("Extracting to dir " + tmpDir);

        int maxSize = httpSettings.getMaxPostSize() * 1024;
        if (log.isDebugEnabled()) {
            log.debug("Max post size is : " + maxSize + " bytes");
            log.debug("Framework encoding is: " + httpSettings.getEncoding());
        }// w  ww. j a va  2  s  . c  om

        try {
            RequestMultipartWrapper wrap = new RequestMultipartWrapper(httpReq, tmpDir, maxSize,
                    httpSettings.getEncoding());
            log.debug("Multipart request parsed: ");
            log.debug("getting files from request");
            ControllerServletHelper.lookup().initThreadLocal(wrap, httpRes);
        } catch (IOException ioe) {
            log.warn("IOException processing multipart ", ioe);
            log.warn("Invalid " + method + ": URL=" + httpReq.getRequestURL() + ". QueryString="
                    + httpReq.getQueryString());
            URLMarkupGenerator markupGenerator = URLMarkupGenerator.lookup();
            if (markupGenerator != null) {
                Map paramsMap = new HashMap();
                paramsMap.put(RedirectionHandler.PARAM_PAGE_TO_REDIRECT, errorRedirectPage);
                String uri = ContextTag.getContextPath(markupGenerator.getMarkup(
                        "org.jbpm.formModeler.service.mvc.components.RedirectionHandler", "redirectToSection",
                        paramsMap), httpReq);
                uri = StringEscapeUtils.unescapeHtml4(uri);
                ControllerStatus.lookup()
                        .setResponse(new RedirectToURLResponse(uri, !uri.startsWith(httpReq.getContextPath())));
            }
            return false;
        }
    }
    return true;
}

From source file:org.jamwiki.servlets.ImportServlet.java

/**
 * This method handles the request after its parent class receives control.
 *
 * @param request - Standard HttpServletRequest object.
 * @param response - Standard HttpServletResponse object.
 * @return A <code>ModelAndView</code> object to be handled by the rest of the Spring framework.
 *//*from  w ww . j  a v  a 2 s. c om*/
public ModelAndView handleJAMWikiRequest(HttpServletRequest request, HttpServletResponse response,
        ModelAndView next, WikiPageInfo pageInfo) throws Exception {
    String contentType = ((request.getContentType() == null) ? "" : request.getContentType().toLowerCase());
    if (contentType.indexOf("multipart") == -1) {
        view(request, next, pageInfo);
    } else {
        importFile(request, next, pageInfo);
    }
    return next;
}

From source file:org.mojavemvc.core.HttpParameterMapSource.java

private boolean isMultipartContent(HttpServletRequest req) {

    if (!"post".equals(req.getMethod().toLowerCase())) {
        return false;
    }//from   w  w w  . ja v a2 s  .c  om
    String contentType = req.getContentType();
    if (contentType == null) {
        return false;
    }
    return contentType.toLowerCase().startsWith("multipart/");
}

From source file:info.magnolia.cms.filters.MultipartRequestFilter.java

/**
 * @see javax.servlet.Filter#doFilter(ServletRequest, ServletResponse, FilterChain)
 *///from  www.  ja va 2 s . c  om
public void doFilter(ServletRequest req, ServletResponse res, FilterChain filterChain)
        throws IOException, ServletException {
    HttpServletRequest request = (HttpServletRequest) req;
    String type = null;
    String type1 = request.getHeader("Content-Type"); //$NON-NLS-1$
    String type2 = request.getContentType();
    if (type1 == null && type2 != null) {
        type = type2;
    } else if (type2 == null && type1 != null) {
        type = type1;
    } else if (type1 != null) {
        type = (type1.length() > type2.length() ? type1 : type2);
    }
    if ((type != null) && type.toLowerCase().startsWith("multipart/form-data")) { //$NON-NLS-1$
        parseParameters(request);
    }
    filterChain.doFilter(req, res);
}

From source file:org.addsimplicity.anicetus.web.TelemetryServletFilter.java

@SuppressWarnings("unchecked")
private void setRequestOnSession(TelemetryHttpSession session, HttpServletRequest request) {
    session.setMethod(request.getMethod());
    session.setProtocol(request.getProtocol());
    if (request.getContentType() != null) {
        session.setContentType(request.getContentType(), HeaderType.Request);
    }//from  ww  w  . j a  va 2s  .c  om
    session.setRequestURL(request.getRequestURI());

    Enumeration<String> pnames = request.getParameterNames();
    while (pnames.hasMoreElements()) {
        String name = pnames.nextElement();
        session.setParameter(name, request.getParameter(name));
    }

    Enumeration<String> hnames = request.getHeaderNames();
    while (hnames.hasMoreElements()) {
        String name = hnames.nextElement();
        String value = request.getHeader(name);
        if (value != null) {
            session.setHeader(name, request.getHeader(name), HeaderType.Request);
        }
    }

    String parent = request.getHeader(s_PARENT_NAME);
    if (parent == null) {
        parent = request.getParameter(s_PARENT_NAME);
    }

    if (parent != null) {
        try {
            UUID parentId = UUID.fromString(parent);
            session.setParentId(parentId);
        } catch (IllegalArgumentException iae) {
            // TODO - Exception handler
        }

    }
}

From source file:org.springframework.web.multipart.support.StandardServletMultipartResolver.java

@Override
public boolean isMultipart(HttpServletRequest request) {
    // Same check as in Commons FileUpload...
    if (!"post".equalsIgnoreCase(request.getMethod())) {
        return false;
    }/* www .  j a  va2 s. c om*/
    String contentType = request.getContentType();
    return StringUtils.startsWithIgnoreCase(contentType, "multipart/");
}

From source file:org.apache.wink.test.mock.MockHttpServletRequestWrapperTestCase.java

@Test
public void testContentType() {
    HttpServletRequest req = MockRequestConstructor.constructMockRequest("POST", "/test", "application/json",
            "application/x-www-form-urlencoded", null);
    Assert.assertEquals("application/x-www-form-urlencoded", req.getContentType());
    Assert.assertEquals("application/json", req.getHeader("Accept"));
}

From source file:com.github.glue.mvc.RequestHandler.java

private boolean isMultipartContent(HttpServletRequest request) {
    if (!"post".equalsIgnoreCase(request.getMethod())) {
        return false;
    }/* w w  w .  j  a  v a2 s.  c  o  m*/
    String contentType = request.getContentType();
    if (contentType == null) {
        return false;
    }
    if (contentType.toLowerCase().startsWith("multipart/")) {
        return true;
    }
    return false;
}