List of usage examples for javax.servlet.http HttpServletRequest getContentType
public String getContentType();
null
if the type is not known. From source file:com.fengduo.bee.web.utils.InvokeTypeTools.java
public static boolean isHtml5(HttpServletRequest request) { return HTML5_FILE_UPLOAD_CONTENT_TYPE.equals(request.getContentType()); }
From source file:com.qwazr.webapps.transaction.body.HttpBodyInterface.java
static HttpBodyInterface newEntity(HttpServletRequest request) throws IOException, ServletException { final String contentTypeString = request.getContentType(); if (contentTypeString != null) { final ContentType contentType = ContentType.parse(contentTypeString); final String mimeType = contentType.getMimeType(); if ("application/x-www-form-urlencoded".equals(mimeType)) return new FormHttpBody(request); if ("multipart/form-data".equals(mimeType)) return new MultipartHttpBody(request); if ("application/xml".equals(mimeType)) return new XMLHttpBody(request); }/* w ww . j a va 2s . c o m*/ throw new WebappException(Status.NOT_ACCEPTABLE, Title.BODY_ERROR, "Not supported content type: " + contentTypeString); }
From source file:io.neba.spring.mvc.SlingMultipartResolver.java
private static boolean isMultipartContent(HttpServletRequest request) { return equalsIgnoreCase(request.getMethod(), "POST") && startsWithIgnoreCase(request.getContentType(), "multipart/"); }
From source file:org.apache.jena.fuseki.FusekiLib.java
/** Get the content type of an action or return the default. * @param request/*from ww w .jav a2 s . c om*/ * @return ContentType */ public static ContentType getContentType(HttpServletRequest request) { String contentTypeHeader = request.getContentType(); if (contentTypeHeader == null) return null; return ContentType.create(contentTypeHeader); }
From source file:org.ow2.chameleon.fuchsia.push.base.hub.dto.ContentNotification.java
private static void validateRequest(HttpServletRequest request) throws InvalidContentNotification { if (!MediaType.APPLICATION_FORM_URLENCODED.equals(request.getContentType())) { throw new InvalidContentNotification("Invalid content type"); }/*from ww w. j a v a2s .c om*/ if (request.getParameter(HUB_MODE) == null) { throw new InvalidContentNotification("No " + HUB_MODE + " provided"); } if (request.getParameter(HUB_URL) == null) { throw new InvalidContentNotification("No " + HUB_URL + " provided"); } }
From source file:ste.web.beanshell.jetty.BeanShellUtils.java
/** * Returns true if the request content is supposed to contain a json object * as per the specified content type//from ww w. j a va2 s . c om * * @param request the request * * @return true if the content type is "application/json", false otherwise */ public static boolean hasJSONBody(HttpServletRequest request) { String contentType = request.getContentType(); if (contentType == null) { return false; } return CONTENT_TYPE_JSON.equals(contentType) || contentType.startsWith(CONTENT_TYPE_JSON + ";"); }
From source file:ru.anr.base.facade.web.api.CommandUtils.java
/** * Building a command with data extracted from {@link HttpServletRequest} * (method, headers).// w w w .ja v a2s . co m * * * @param commandId * Identifier of Command * @param apiVersion * API Version * @param request * Http request * @return A command instance */ public static APICommand build(String commandId, String apiVersion, HttpServletRequest request) { APICommand cmd = new APICommand(commandId, apiVersion); if (MediaType.APPLICATION_XML_VALUE.equals(request.getContentType())) { cmd.setRequestFormat(RawFormatTypes.XML); } else { cmd.setRequestFormat(RawFormatTypes.JSON); } if (MediaType.APPLICATION_XML_VALUE.equals(request.getHeader("Accept"))) { cmd.setResponseFormat(RawFormatTypes.XML); } else { cmd.setResponseFormat(RawFormatTypes.JSON); } cmd.method(request.getMethod()); return cmd; }
From source file:org.pac4j.cas.client.CasClientWrapper.java
private static boolean isMultipartRequest(final HttpServletRequest request) { return request.getContentType() != null && request.getContentType().toLowerCase().startsWith("multipart"); }
From source file:info.magnolia.cms.util.ServletUtil.java
/** * Returns true if the request has a content type that indicates that is a multipart request. *//*from ww w . j a v a 2s . c om*/ public static boolean isMultipart(HttpServletRequest request) { String contentType = request.getContentType(); return contentType != null && contentType.toLowerCase().startsWith("multipart/"); }
From source file:de.egore911.opengate.FileuploadServletRequest.java
public static FileuploadServletRequest wrap(HttpServletRequest req, User user) throws ServletException, IOException { if (req.getContentType().toLowerCase(Locale.ENGLISH).startsWith(FileUploadBase.MULTIPART)) { Map<String, Object> parameters = new HashMap<String, Object>(); Map<String, List<String>> parameterValues = new HashMap<String, List<String>>(); ServletFileUpload upload = new ServletFileUpload(); try {/*from w ww.ja v a 2s .c o m*/ FileItemIterator iter = upload.getItemIterator(req); while (iter.hasNext()) { FileItemStream stream = iter.next(); InputStream s = stream.openStream(); try { String fieldName = stream.getFieldName(); if (stream.isFormField()) { if (parameters.containsKey(fieldName)) { if (!parameterValues.containsKey(fieldName)) { parameterValues.put(fieldName, new ArrayList<String>()); parameterValues.get(fieldName).add((String) parameters.get(fieldName)); } parameterValues.get(fieldName).add(IOUtils.toString(s)); } else { parameters.put(fieldName, IOUtils.toString(s)); } } else { byte[] byteArray = IOUtils.toByteArray(s); if (byteArray.length > 0) { BinaryData binaryData = new BinaryData(); binaryData.setData(new Blob(byteArray)); binaryData.setMimetype(stream.getContentType()); binaryData.setFilename(stream.getName()); binaryData.setSize(byteArray.length); AbstractEntity.setCreated(binaryData, user); parameters.put(fieldName, binaryData); } } } finally { s.close(); } } } catch (FileUploadException e) { throw new ServletException(e); } return new FileuploadServletRequest(parameters, parameterValues); } else { return new FileuploadServletRequest(req); } }