List of usage examples for javax.servlet.http HttpServletRequest getMethod
public String getMethod();
From source file:in.xebia.poc.FileUploadUtils.java
public static boolean parseFileUploadRequest(HttpServletRequest request, File outputFile, Map<String, String> params) throws Exception { log.debug("Request class? " + request.getClass().toString()); log.debug("Request is multipart? " + ServletFileUpload.isMultipartContent(request)); log.debug("Request method: " + request.getMethod()); log.debug("Request params: "); for (Object key : request.getParameterMap().keySet()) { log.debug((String) key);// w w w . j av a 2 s .co m } log.debug("Request attribute names: "); boolean filedataInAttributes = false; Enumeration attrNames = request.getAttributeNames(); while (attrNames.hasMoreElements()) { String attrName = (String) attrNames.nextElement(); log.debug(attrName); if ("filedata".equals(attrName)) { filedataInAttributes = true; } } if (filedataInAttributes) { log.debug("Found filedata in request attributes, getting it out..."); log.debug("filedata class? " + request.getAttribute("filedata").getClass().toString()); FileItem item = (FileItem) request.getAttribute("filedata"); item.write(outputFile); for (Object key : request.getParameterMap().keySet()) { params.put((String) key, request.getParameter((String) key)); } return true; } /*ServletFileUpload upload = new ServletFileUpload(); //upload.setSizeMax(Globals.MAX_UPLOAD_SIZE); FileItemIterator iter = upload.getItemIterator(request); while(iter.hasNext()){ FileItemStream item = iter.next(); InputStream stream = item.openStream(); //If this item is a file if(!item.isFormField()){ log.debug("Found non form field in upload request with field name = " + item.getFieldName()); String name = item.getName(); if(name == null){ throw new Exception("File upload did not have filename specified"); } // Some browsers, including IE, return the full path so trim off everything but the file name name = getFileNameFromPath(name); //Enforce required file extension, if present if(!name.toLowerCase().endsWith( ".zip" )){ throw new Exception("File uploaded did not have required extension .zip"); } bufferedCopyStream(stream, new FileOutputStream(outputFile)); } else { params.put(item.getFieldName(), Streams.asString(stream)); } } return true;*/ // Create a factory for disk-based file items FileItemFactory factory = new DiskFileItemFactory(); // Create a new file upload handler ServletFileUpload upload = new ServletFileUpload(factory); // Parse the request List /* FileItem */ items = upload.parseRequest(request); // Process the uploaded items Iterator iter = items.iterator(); while (iter.hasNext()) { FileItem item = (FileItem) iter.next(); if (!item.isFormField()) { log.debug("Found non form field in upload request with field name = " + item.getFieldName()); String name = item.getName(); if (name == null) { throw new Exception("File upload did not have filename specified"); } // Some browsers, including IE, return the full path so trim off everything but the file name name = getFileNameFromPath(name); item.write(outputFile); } else { params.put(item.getFieldName(), item.getString()); } } return true; }
From source file:com.jaspersoft.jasperserver.rest.RESTUtils.java
public static boolean isMultipartContent(HttpServletRequest request) { if (!(RESTAbstractService.HTTP_PUT.equals(request.getMethod().toLowerCase()) || RESTAbstractService.HTTP_POST.equals(request.getMethod().toLowerCase()))) { return false; }/*from w ww.jav a 2 s . com*/ String contentType = request.getContentType(); if (contentType == null) { return false; } if (contentType.toLowerCase().startsWith("multipart/")) { return true; } return false; }
From source file:com.zimbra.cs.servlet.util.CsrfUtil.java
/** * @return//from w w w. jav a 2s. c o m */ public static boolean isPostReq(HttpServletRequest req) { boolean postReq = true; String method = req.getMethod(); if (!method.equalsIgnoreCase("POST") && !method.equalsIgnoreCase("PUT") && !method.equalsIgnoreCase("DELETE")) { postReq = false; } return postReq; }
From source file:com.jims.oauth2.common.utils.OAuthUtils.java
public static boolean isMultipart(HttpServletRequest request) { if (!"post".equals(request.getMethod().toLowerCase())) { return false; }//from w w w . ja v a2 s . c om String contentType = request.getContentType(); if (contentType == null) { return false; } if (contentType.toLowerCase().startsWith(MULTIPART)) { return true; } return false; }
From source file:ru.anr.base.facade.web.api.CommandUtils.java
/** * Building a command with data extracted from {@link HttpServletRequest} * (method, headers).//from w w w . j a v a2 s . com * * * @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:com.mob.forum.util.legacy.commons.fileupload.FileUploadBase.java
/** * Utility method that determines whether the request contains multipart * content./*from ww w . j a v a 2 s . c o m*/ * * @param req The servlet request to be evaluated. Must be non-null. * * @return <code>true</code> if the request is multipart; * <code>false</code> otherwise. * * @deprecated Use the method on <code>ServletFileUpload</code> instead. */ public static final boolean isMultipartContent(HttpServletRequest req) { if (!"post".equals(req.getMethod().toLowerCase())) { return false; } String contentType = req.getContentType(); if (contentType == null) { return false; } if (contentType.toLowerCase().startsWith(MULTIPART)) { return true; } return false; }
From source file:de.knowwe.core.user.UserContextUtil.java
/** * Returns a Map<String, String> with all parameters of a http request. This * is necessary because the parameter map of the http request is locked. * //ww w .j a v a2 s . c o m * @created Mar 9, 2011 * @param request the http request * @return map containing the parameters of the http request. */ public static Map<String, String> getParameters(HttpServletRequest request) { Map<String, String> parameters = new HashMap<>(); if (request != null) { Enumeration<?> iter = request.getParameterNames(); boolean decode = checkForFlowChart(request.getParameter("action")); while (iter.hasMoreElements()) { String key = (String) iter.nextElement(); String value = request.getParameter(key); parameters.put(key, decode ? Strings.decodeURL(value) : value); } if (request.getMethod() != null && request.getMethod().equals("POST")) { // do not handle file uploads, leave this to the action if (!ServletFileUpload.isMultipartContent(request)) { try { BufferedReader br = new BufferedReader(new InputStreamReader(request.getInputStream())); String line; StringBuilder bob = new StringBuilder(); while ((line = br.readLine()) != null) { bob.append(line).append("\n"); } parameters.put("data", bob.toString()); } catch (IOException e) { e.printStackTrace(); } } } } return parameters; }
From source file:com.aol.webservice_base.util.http.HttpHelper.java
/** * Checks if is gets the method./* www. j a va 2 s . c om*/ * * @param request the request * @return true, if is gets the method */ public static boolean isGetMethod(HttpServletRequest request) { return (request == null || "GET".equalsIgnoreCase(request.getMethod())); }
From source file:by.stub.yaml.stubs.StubRequest.java
public static StubRequest createFromHttpServletRequest(final HttpServletRequest request) throws IOException { final StubRequest assertionRequest = StubRequest.newStubRequest(request.getPathInfo(), HandlerUtils.extractPostRequestBody(request, "stubs")); assertionRequest.addMethod(request.getMethod()); final Enumeration<String> headerNamesEnumeration = request.getHeaderNames(); final List<String> headerNames = ObjectUtils.isNotNull(headerNamesEnumeration) ? Collections.list(request.getHeaderNames()) : new LinkedList<String>(); for (final String headerName : headerNames) { final String headerValue = request.getHeader(headerName); assertionRequest.getHeaders().put(StringUtils.toLower(headerName), headerValue); }//from www .j a v a2s . co m assertionRequest.getQuery().putAll(CollectionUtils.constructParamMap(request.getQueryString())); ConsoleUtils.logAssertingRequest(assertionRequest); return assertionRequest; }
From source file:com.comcast.cmb.common.util.AuthUtil.java
protected static String getCanonicalRequest(HttpServletRequest request, String contentSha256, Map<String, String> parameters, Map<String, String> headers) { String canonicalRequest = null; canonicalRequest = request.getMethod() + "\n" + getResourcePath(request) + "\n" + getCanonicalizedQueryString(request, parameters) + "\n" + getCanonicalizedHeaderString(headers) + "\n" + getSignedHeadersString(headers) + "\n" + contentSha256; logger.debug("AWS4 Canonical Request: '\"" + canonicalRequest + "\""); return canonicalRequest; }