本文整理匯總了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()
);
}