當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpServletRequest.getContentType方法代碼示例

本文整理匯總了Java中javax.servlet.http.HttpServletRequest.getContentType方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpServletRequest.getContentType方法的具體用法?Java HttpServletRequest.getContentType怎麽用?Java HttpServletRequest.getContentType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.servlet.http.HttpServletRequest的用法示例。


在下文中一共展示了HttpServletRequest.getContentType方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: isFormContentType

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
private boolean isFormContentType(HttpServletRequest request) {
	String contentType = request.getContentType();
	if (contentType != null) {
		try {
			MediaType mediaType = MediaType.parseMediaType(contentType);
			return (MediaType.APPLICATION_FORM_URLENCODED.includes(mediaType));
		}
		catch (IllegalArgumentException ex) {
			return false;
		}
	}
	else {
		return false;
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:16,代碼來源:HttpPutFormContentFilter.java

示例2: getValue

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
@Override
public Object getValue(HttpServletRequest request) throws Exception {
  Object body = request.getAttribute(RestConst.BODY_PARAMETER);
  if (body != null) {
    return convertValue(body, targetType);
  }

  // for standard HttpServletRequest, getInputStream will never return null
  // but for mocked HttpServletRequest, maybe get a null
  //  like org.apache.servicecomb.provider.springmvc.reference.ClientToHttpServletRequest
  InputStream inputStream = request.getInputStream();
  if (inputStream == null) {
    return null;
  }

  String contentType = request.getContentType();
  if (contentType != null && !contentType.toLowerCase(Locale.US).startsWith(MediaType.APPLICATION_JSON)) {
    // TODO: we should consider body encoding
    return IOUtils.toString(inputStream, "UTF-8");
  }
  return RestObjectMapper.INSTANCE.readValue(inputStream, targetType);
}
 
開發者ID:apache,項目名稱:incubator-servicecomb-java-chassis,代碼行數:23,代碼來源:BodyProcessorCreator.java

示例3: processMultipart

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
/**
 * <p>If this is a multipart request, wrap it with a special wrapper.
 * Otherwise, return the request unchanged.</p>
 *
 * @param request The HttpServletRequest we are processing
 */
protected HttpServletRequest processMultipart(HttpServletRequest request) {

    if (!"POST".equalsIgnoreCase(request.getMethod())) {
        return (request);
    }
    
    String contentType = request.getContentType();
    if ((contentType != null) &&
        contentType.startsWith("multipart/form-data")) {
        return (new MultipartRequestWrapper(request));
    } else {
        return (request);
    }

}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:22,代碼來源:RequestProcessor.java

示例4: getRequestDocumentType

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
/**
 * Return the document type by checking the request content type and the extension of the request path
 * @param request
 * @return
 */
public int getRequestDocumentType(HttpServletRequest request) {
	String contentType = request.getContentType();
	int result = getDocumentType(contentType);
	if (result!=CONTENT_UNKNOWN) {
		return result;
	}
	String pathInfo = request.getPathInfo();
	if (pathInfo==null) {
		return CONTENT_DOCUMENT;
	}
	if (pathInfo.endsWith(".css")) {
		return CONTENT_CSS;
	}
	if (pathInfo.endsWith(".js")) {
		return CONTENT_JAVASCRIPT;
	}
	if (pathInfo.endsWith(".gif") 
		|| pathInfo.endsWith(".jpeg") 
		|| pathInfo.endsWith(".jpg") 
		|| pathInfo.endsWith(".png") 
		|| pathInfo.endsWith(".tiff")) {
		return CONTENT_IMAGE;
	}
	return CONTENT_DOCUMENT;
}
 
開發者ID:xtianus,項目名稱:yadaframework,代碼行數:31,代碼來源:YadaHttpUtil.java

示例5: getContentType

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
private MediaType getContentType(HttpServletRequest request) {
    String contentType = request.getContentType();
    if (contentType == null) {
        if (logger.isTraceEnabled()) {
            logger.trace("No Content-Type header found, defaulting to application/octet-stream");
        }
        return MediaType.APPLICATION_OCTET_STREAM;
    }
    return MediaType.parseMediaType(contentType);
}
 
開發者ID:devefx,項目名稱:validator-web,代碼行數:11,代碼來源:HttpMessageReaderExtractor.java

示例6: get

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
@Override
public ParamSource get(WObject wObject, Class<?> porterClass, Method porterFun) throws Exception
{
    HttpServletRequest request = wObject.getRequest().getOriginalRequest();

    String ctype = request.getContentType();
    if (ctype != null && ctype.indexOf(ContentType.APP_FORM_URLENCODED.getType()) != -1)
    {
        String encode = getEncode(ctype);

        String body = FileTool.getString(request.getInputStream());
        if(body==null){
            return null;
        }
        String[] strs = body.split("&");
        final HashMap<String, Object> paramsMap = new HashMap<>(strs.length);
        int index;
        for (String string : strs)
        {
            index = string.indexOf('=');
            if (index != -1)
            {
                paramsMap.put(string.substring(0, index),
                        URLDecoder.decode(string.substring(index + 1), encode));
            }
        }

        ParamSource paramSource = new DefaultParamSource(paramsMap, wObject.getRequest());

        return paramSource;

    }
    return null;
}
 
開發者ID:gzxishan,項目名稱:OftenPorter,代碼行數:35,代碼來源:PutParamSourceHandle.java

示例7: getInputStreamEntity

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
private InputStreamEntity getInputStreamEntity(HttpServletRequest request) throws IOException
{
    int contentLength = request.getContentLength();

    ContentType contentType = null;
    if (request.getContentType() != null) {
        contentType = ContentType.parse(request.getContentType());
    }

    return new InputStreamEntity(request.getInputStream(), contentLength, contentType);
}
 
開發者ID:coveo,項目名稱:k8s-proxy,代碼行數:12,代碼來源:K8sReverseProxy.java

示例8: isMultipartRequest

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
public static boolean isMultipartRequest(HttpServletRequest request)
{
    String contentType = request.getContentType();
    return contentType != null && contentType.toLowerCase(Locale.ENGLISH).startsWith("multipart/");
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:6,代碼來源:AbstractFileUpload.java

示例9: isMultipart

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
@Override
public boolean isMultipart(HttpServletRequest request) {
	// Same check as in Commons FileUpload...
	if (!"post".equals(request.getMethod().toLowerCase())) {
		return false;
	}
	String contentType = request.getContentType();
	return (contentType != null && contentType.toLowerCase().startsWith("multipart/"));
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:10,代碼來源:StandardServletMultipartResolver.java

示例10: loadFromRequest

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
public void loadFromRequest(HttpServletRequest request) 
{
	String contentType = request.getContentType();
	if ( ! "application/xml".equals(contentType) ) {
		errorMessage = "Content Type must be application/xml";
		Log.info(errorMessage+"\n"+contentType);
		return;
	}

	setAuthHeader(request.getHeader("Authorization"));
	if ( oauth_body_hash == null ) {
		errorMessage = "Did not find oauth_body_hash";
		Log.info(errorMessage+"\n"+header);
		return;
	}

	try {
		Reader in = request.getReader();
		postBody = readPostBody(in);
	} catch(Exception e) {
		errorMessage = "Could not read message body:"+e.getMessage();
		return;
	}

	validatePostBody();
	if (errorMessage != null) return;

	parsePostBody();
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:30,代碼來源:IMSPOXRequest.java

示例11: doFilter

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
/**
 * Enforces the content-type to be application/octet-stream for
 * POST and PUT requests.
 *
 * @param request servlet request.
 * @param response servlet response.
 * @param chain filter chain.
 *
 * @throws IOException thrown if an IO error occurrs.
 * @throws ServletException thrown if a servet error occurrs.
 */
@Override
public void doFilter(ServletRequest request, ServletResponse response,
                     FilterChain chain)
  throws IOException, ServletException {
  boolean contentTypeOK = true;
  HttpServletRequest httpReq = (HttpServletRequest) request;
  HttpServletResponse httpRes = (HttpServletResponse) response;
  String method = httpReq.getMethod();
  if (method.equals("PUT") || method.equals("POST")) {
    String op = httpReq.getParameter(HttpFSFileSystem.OP_PARAM);
    if (op != null && UPLOAD_OPERATIONS.contains(
        StringUtils.toUpperCase(op))) {
      if ("true".equalsIgnoreCase(httpReq.getParameter(HttpFSParametersProvider.DataParam.NAME))) {
        String contentType = httpReq.getContentType();
        contentTypeOK =
          HttpFSFileSystem.UPLOAD_CONTENT_TYPE.equalsIgnoreCase(contentType);
      }
    }
  }
  if (contentTypeOK) {
    chain.doFilter(httpReq, httpRes);
  }
  else {
    httpRes.sendError(HttpServletResponse.SC_BAD_REQUEST,
                      "Data upload requests must have content-type set to '" +
                      HttpFSFileSystem.UPLOAD_CONTENT_TYPE + "'");

  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:41,代碼來源:CheckUploadContentTypeFilter.java

示例12: isMultipartContent

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
/**
 * multipart
 */
public static boolean isMultipartContent(HttpServletRequest request) {
    if (HttpMethod.POST.name().equals(request.getMethod().toUpperCase())) {
        String contentType = request.getContentType();
        if (contentType != null)
            if (contentType.toLowerCase(Locale.ENGLISH).startsWith(MULTIPART)) {
                return true;
            }
    }
    return false;
}
 
開發者ID:Xlongshu,項目名稱:EasyController,代碼行數:14,代碼來源:WebUtils.java

示例13: isMultipartRequest

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
public static boolean isMultipartRequest(HttpServletRequest request) {
    String contentType = request.getContentType();
    return contentType != null && contentType.toLowerCase().indexOf("multipart") != -1;
}
 
開發者ID:yangfuhai,項目名稱:jboot,代碼行數:5,代碼來源:RequestUtils.java

示例14: isFormPost

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
private boolean isFormPost(HttpServletRequest request){
	String contentType = request.getContentType();
	boolean isFormContent = contentType != null
			&& contentType.contains(ContentType.APPLICATION_FORM_URLENCODED.getMimeType());
	return isFormContent && "POST".equalsIgnoreCase(request.getMethod());
}
 
開發者ID:hotpads,項目名稱:datarouter,代碼行數:7,代碼來源:DefaultSignatureValidator.java

示例15: gatherRequestInfo

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
private void gatherRequestInfo(ParameterShuttle infoShuttle, HttpServletRequest request) throws IOException {
		infoShuttle.sessionID = request.getSession().getId();

		infoShuttle.postFromUser = request.getMethod().equals("POST");
		if (infoShuttle.postFromUser) {
			infoShuttle.userContentType = request.getContentType();
			infoShuttle.userContentLength = request.getContentLength();
		}

/*		String query = request.getQueryString();
		if (query != null) {
			int pos = 0;

			infoShuttle.postToSite = query.startsWith(ParameterShuttle.bridgePostTag);
			if (infoShuttle.postToSite)
				pos = ParameterShuttle.bridgePostTag.length();

			if (query.startsWith(ParameterShuttle.bridgeGotoTag, pos)) {
				int p2 = query.indexOf(ParameterShuttle.bridgeThenTag, pos);

				if (p2 > -1) {
					infoShuttle.userGoto = query.substring(pos + ParameterShuttle.bridgeGotoTag.length(), p2);
					infoShuttle.userThen = query.substring(p2 + ParameterShuttle.bridgeThenTag.length());
				}
				else {
					infoShuttle.userGoto = query.substring(pos + ParameterShuttle.bridgeGotoTag.length());
				}
			}
			else if (query.startsWith(ParameterShuttle.bridgeThenTag, pos)) {
				infoShuttle.userThen = query.substring(pos + ParameterShuttle.bridgeThenTag.length());
			}
		}*/
		infoShuttle.postToSite = infoShuttle.postFromUser;//request.getParameter(Parameter.ProxyPost.getName()) != null;
		infoShuttle.userGoto = request.getParameter(Parameter.ProxyGoto.getName());
		infoShuttle.userThen = request.getParameter(Parameter.ProxyThen.getName());

		Enumeration<String> allHeaderNames = GenericUtils.cast(request.getHeaderNames());
		while (allHeaderNames.hasMoreElements()) {
			String name = (String) allHeaderNames.nextElement();
			infoShuttle.userHeaderNames.add(name.toLowerCase());
			infoShuttle.userHeaderValues.add(request.getHeader(name));
		}

		ParameterShuttle.getSelfURL(
			request.getScheme(),
			request.getServerName(),
			request.getServerPort(),
			request.getRequestURI()
		);
	}
 
開發者ID:convertigo,項目名稱:convertigo-engine,代碼行數:51,代碼來源:ProxyServletRequester.java


注:本文中的javax.servlet.http.HttpServletRequest.getContentType方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。