@RequirePOST public HttpResponse doScan(StaplerRequest req) throws IOException, GeneralSecurityException { if(req.hasParameter("background")) { start(false); } else if(req.hasParameter("schedule")) { scanOnBoot.on(); } else if(req.hasParameter("dismiss")) { disable(true); } else throw HttpResponses.error(400,"Invalid request submission: " + req.getParameterMap()); return HttpResponses.redirectViaContextPath("/manage"); }
/** * returns true if request contains key * * @param key parameter name * @return */ private boolean containsKey(String key) throws javax.servlet.ServletException, java.io.IOException { // JENKINS-16043, POST can be multipart encoded if there's a file parameter in the job if (isMultipartEncoded) { return parsedFormData.containsKey(key); } else { return request.getParameterMap().containsKey(key); } } }
/** * Helper to get the parameter value * * @param request the {@link javax.servlet.http.HttpServletRequest} to get the parameter value from * @param name the parameter name * @return the parameter value */ private String getParameterValue(StaplerRequest request, String name) { if (request.getParameterMap().containsKey(name)) { String parameter = request.getParameter(name); return gson.fromJson(StringUtils.isNotBlank(parameter) ? parameter : "", JsonElement.class).getAsString(); } else { return null; } }
/** * This is a method to get a parameter map from the stapelerRequest. * * @param request the staplerReqeust. This is the request that is sent to jenkins * @return Map that contains the servlet request parameters. Also the StaplerRequest.getRootPath() value is added in to this map */ public static Map<String, String[]> getParameterMapFromRequest(StaplerRequest request) { Map<String, String[]> retMap = new HashMap<String, String[]>(); Map<String, String[]> currentMap = request.getParameterMap(); // Check whether the map in request is not null if (currentMap != null) { retMap.putAll(currentMap); // We will be adding the root path as a parameter in this map. This is read by other classes String rootPath = request.getRootPath(); retMap.put("rootPath", new String[]{rootPath}); } return retMap; }
@SuppressWarnings("unchecked") private Parameter[] prepareParameters(StaplerRequest req, Script tempScript) { // retain default parameter values Map<String, Parameter> params = new HashMap<String, Parameter>(); for (Parameter param : tempScript.getParameters()) { params.put(param.getName(), param); } // overwrite parameters that are passed as parameters for (Map.Entry<String, String[]> param : (Set<Map.Entry<String, String[]>>) req.getParameterMap().entrySet()) { if (params.containsKey(param.getKey())) { params.put(param.getKey(), new Parameter(param.getKey(), param.getValue()[0])); } } Parameter[] paramArray = params.values().toArray(new Parameter[params.size()]); return paramArray; }
public HttpResponse doInvoke(final StaplerRequest request) { String postContent = null; Map<String, String[]> parameterMap = null; Map<String, List<String>> headers = null; try { headers = getHeaders(request); parameterMap = request.getParameterMap(); postContent = IOUtils.toString(request.getInputStream(), UTF_8.name()); } catch (final IOException e) { LOGGER.log(SEVERE, "", e); } final String givenToken = getGivenToken(headers, parameterMap); return doInvoke(headers, parameterMap, postContent, givenToken); }
/** * Locates the operation in the submitted form. * * @param req Request * @return Located operation * @throws Descriptor.FormException Cannot find any command field from * the enum */ @Nonnull static SubmittedOperation fromRequest(@Nonnull StaplerRequest req) throws Descriptor.FormException { final Map<?, ?> map = req.getParameterMap(); for (SubmittedOperation val : SubmittedOperation.values()) { if (map.containsKey(val.toString())) { return val; } } throw new Descriptor.FormException("Cannot find an action in the request", "submit"); } }
/** * Calling getSubmittedForm, if no form is present in a {@link StaplerRequest} * will throw an ugly exception. Call this to avoid the exception. * <p> * This can happen when triggering jobs that do not have parameters, and * thus trigger a build purely via an HTTP GET without a form. * * @return the JSON form, or null if none is present (or the request was not a POST) */ public static final JSONObject getSubmittedFormSafely(StaplerRequest req) { if (!req.getMethod().equals("POST")) { return null; } //Check if it looks like a form submission Map<?,?> pMap = req.getParameterMap(); String cType = req.getContentType(); boolean hasFormContent = ( (pMap != null && pMap.containsKey("json")) || (cType != null && cType.startsWith("multipart/")) ); if (!hasFormContent) { return null; } try { return req.getSubmittedForm(); } catch (ServletException e) { return null; } } }
/** * returns the value of the key as a String. if multiple values have been * submitted, the first one will be returned. * * @param key * @return */ private String getString(String key) throws javax.servlet.ServletException, java.io.IOException { if (isMultipartEncoded) { // borrowed from org.kohsuke.staple.RequestImpl FileItem item = parsedFormData.get(key); if (item!=null && item.isFormField()) { if (item.getContentType() == null && request.getCharacterEncoding() != null) { // JENKINS-11543: If client doesn't set charset per part, use request encoding try { return item.getString(request.getCharacterEncoding()); } catch (java.io.UnsupportedEncodingException uee) { LOGGER.log(Level.WARNING, "Request has unsupported charset, using default for '"+key+"' parameter", uee); return item.getString(); } } else { return item.getString(); } } else { throw new IllegalArgumentException("Parameter not found: " + key); } } else { return (String) (((Object[]) request.getParameterMap().get(key))[0]); } }
public void doUpdateRetentionStrategies(StaplerRequest req, StaplerResponse res) throws ServletException, IOException { Hudson.getInstance().checkPermission(getRequiredPermission()); List<RetentionStragegy> selectedStrategies = new ArrayList<RetentionStragegy>(); if(req.getParameterValues("retentionStrategies") != null){ for(String selectedStrategyId : req.getParameterValues("retentionStrategies")){ RetentionStragegy retentionStrategy = RetentionStragegy.valueOf(selectedStrategyId); retentionStrategy.updateState(req.getParameterMap()); selectedStrategies.add(retentionStrategy); } } business.updateRetentionStrategies(selectedStrategies); respondAjaxOk(res); }
@RequirePOST public HttpResponse doScan(StaplerRequest req) throws IOException, GeneralSecurityException { if(req.hasParameter("background")) { start(false); } else if(req.hasParameter("schedule")) { scanOnBoot.on(); } else if(req.hasParameter("dismiss")) { disable(true); } else throw HttpResponses.error(400,"Invalid request submission: " + req.getParameterMap()); return HttpResponses.redirectViaContextPath("/manage"); }
Map pMap = req.getParameterMap(); String cType = req.getContentType(); boolean hasFormContent = (