本文整理汇总了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;
}
}
示例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);
}
示例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);
}
}
示例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;
}
示例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);
}
示例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;
}
示例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);
}
示例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/");
}
示例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/"));
}
示例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();
}
示例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 + "'");
}
}
示例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;
}
示例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;
}
示例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());
}
示例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()
);
}