当前位置: 首页>>代码示例>>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;未经允许,请勿转载。