List of usage examples for javax.servlet ServletRequest getParameter
public String getParameter(String name);
String
, or null
if the parameter does not exist. From source file:dk.netarkivet.common.webinterface.HTMLUtils.java
/** * Checks that the given parameters exist. If any of them do not exist, forwards to the error page and throws * ForwardedToErrorPage./*w w w.j a va2 s . co m*/ * * @param context The context of the current JSP page * @param parameters List of parameters that must exist * @throws IOFailure If the forward fails * @throws ForwardedToErrorPage If a parameter is missing */ public static void forwardOnMissingParameter(PageContext context, String... parameters) throws ForwardedToErrorPage { // Note that we may not want to be to strict here // as otherwise information could be lost. ArgumentNotValid.checkNotNull(context, "context"); ArgumentNotValid.checkNotNull(parameters, "parameters"); ServletRequest request = context.getRequest(); for (String parameter : parameters) { String value = request.getParameter(parameter); if (value == null) { forwardWithErrorMessage(context, I18N, "errormsg;missing.parameter.0", parameter); throw new ForwardedToErrorPage("Missing parameter '" + parameter + "'"); } } }
From source file:dk.netarkivet.archive.webinterface.BatchGUI.java
/** * Method for creating the page for a batchjob. It contains the following informations: * <p>//from w w w .j av a 2 s . c o m * <br/> * - Creates a line with the name of the batchjob.<br/> * - Write the description if the batchjob has a metadata resource annotation description of the batchjob class.<br/> * - The last run information, date and size of the error and output files. <br/> * - The arguments of the batchjob, with information if they have been defined in the resource annotations of the * class.<br/> * - Radio buttons for choosing the replica.<br/> * - Input box for regular expression for filenames to match.<br/> * - Execution button.<br/> * * @param context The context of the page. Must contains a class name of the batchjob. * @throws UnknownID If the class cannot be found. * @throws ArgumentNotValid If the context is null. * @throws IllegalState If the class is not an instance of FileBatchJob. * @throws ForwardedToErrorPage If the context does not contain the required information. * @throws IOFailure If there is problems with the JspWriter. */ @SuppressWarnings("rawtypes") public static void getPageForClass(PageContext context) throws UnknownID, ArgumentNotValid, IllegalState, ForwardedToErrorPage, IOFailure { ArgumentNotValid.checkNotNull(context, "PageContext context"); HTMLUtils.forwardOnEmptyParameter(context, Constants.BATCHJOB_PARAMETER); try { // Retrieve variables Locale locale = context.getResponse().getLocale(); ServletRequest request = context.getRequest(); String className = request.getParameter(Constants.BATCHJOB_PARAMETER); JspWriter out = context.getOut(); // retrieve the batch class and the constructor. Class c = getBatchClass(className); out.print(I18N.getString(locale, "batchpage;Name.of.batchjob", new Object[] {}) + ": <b>" + c.getName() + "</b><br/>\n"); out.print(getClassDescription(c, locale)); out.print(getPreviousRuns(c.getName(), locale)); // begin form out.println("<form method=\"post\" action=\"" + Constants.URL_BATCHJOB_EXECUTE + "?" + Constants.BATCHJOB_PARAMETER + "=" + className + "\">"); out.print(getHTMLarguments(c, locale)); out.print(getReplicaRadioButtons(locale)); out.print(getRegularExpressionInputBox(locale)); out.print(getSubmitButton(locale)); // end form out.print("</form>"); } catch (IOException e) { String errMsg = "Could not create page with batchjobs."; log.warn(errMsg, e); throw new IOFailure(errMsg, e); } }
From source file:org.apache.cxf.fediz.spring.web.FederationAuthenticationFilter.java
private String getResponseToken(ServletRequest request) { if (request.getParameter(FederationConstants.PARAM_RESULT) != null) { return request.getParameter(FederationConstants.PARAM_RESULT); } else if (request.getParameter(SAMLSSOConstants.SAML_RESPONSE) != null) { return request.getParameter(SAMLSSOConstants.SAML_RESPONSE); }/*w w w . j a va 2s. c o m*/ return null; }
From source file:dk.netarkivet.harvester.webinterface.ExtendedFieldValueDefinition.java
public static void processRequest(PageContext context, I18n i18n, ExtendableEntity entity, int type) { ArgumentNotValid.checkNotNull(context, "PageContext context"); ArgumentNotValid.checkNotNull(i18n, "I18n i18n"); ExtendedFieldDAO extdao = ExtendedFieldDBDAO.getInstance(); Iterator<ExtendedField> it = extdao.getAll(type).iterator(); ServletRequest request = context.getRequest(); while (it.hasNext()) { String value = ""; ExtendedField ef = it.next();/*from ww w . ja v a2s .c o m*/ String parameterName = ef.getJspFieldname(); switch (ef.getDatatype()) { case ExtendedFieldDataTypes.BOOLEAN: String[] parb = request.getParameterValues(parameterName); if (parb != null && parb.length > 0) { value = ExtendedFieldConstants.TRUE; } else { value = ExtendedFieldConstants.FALSE; } break; case ExtendedFieldDataTypes.SELECT: String[] pars = request.getParameterValues(parameterName); if (pars != null && pars.length > 0) { value = pars[0]; } else { value = ""; } break; default: value = request.getParameter(parameterName); if (ef.isMandatory()) { if (value == null || value.length() == 0) { value = ef.getDefaultValue(); } if (value == null || value.length() == 0) { HTMLUtils.forwardWithErrorMessage(context, i18n, "errormsg;extendedfields.field.0.is.empty." + "but.mandatory", ef.getName()); throw new ForwardedToErrorPage("Mandatory field " + ef.getName() + " is empty."); } } ExtendedFieldDefaultValue def = new ExtendedFieldDefaultValue(value, ef.getFormattingPattern(), ef.getDatatype()); if (!def.isValid()) { HTMLUtils.forwardWithRawErrorMessage(context, i18n, "errormsg;extendedfields.value.invalid"); throw new ForwardedToErrorPage("errormsg;extendedfields.value.invalid"); } value = def.getDBValue(); break; } entity.updateExtendedFieldValue(ef.getExtendedFieldID(), value); } }
From source file:dk.netarkivet.archive.webinterface.BatchGUI.java
/** * Method for executing a batchjob./* w w w. j av a 2 s .c om*/ * * @param context The page context containing the needed information for executing the batchjob. */ @SuppressWarnings("rawtypes") public static void execute(PageContext context) { try { ServletRequest request = context.getRequest(); // get parameters String filetype = request.getParameter(Constants.FILETYPE_PARAMETER); String jobId = request.getParameter(Constants.JOB_ID_PARAMETER); String jobName = request.getParameter(Constants.BATCHJOB_PARAMETER); String repName = request.getParameter(Constants.REPLICA_PARAMETER); FileBatchJob batchjob; // Retrieve the list of arguments. List<String> args = new ArrayList<String>(); String arg; Integer i = 1; // retrieve the constructor to find out how many arguments Class c = getBatchClass(jobName); Constructor con = findStringConstructor(c); // retrieve the arguments and put them into the list. while (i <= con.getParameterTypes().length) { arg = request.getParameter("arg" + i.toString()); if (arg != null) { args.add(arg); } else { log.warn("Should contain argument number " + i + ", but " + "found a null instead, indicating missing " + "argument. Use empty string instead."); args.add(""); } i++; } File jarfile = getJarFile(jobName); if (jarfile == null) { // get the constructor and instantiate it. Constructor construct = findStringConstructor(getBatchClass(jobName)); batchjob = (FileBatchJob) construct.newInstance(args.toArray()); } else { batchjob = new LoadableJarBatchJob(jobName, args, jarfile); } // get the regular expression. String regex = jobId + "-"; if (filetype.equals(BatchFileType.Metadata.toString())) { regex += Constants.REGEX_METADATA; } else if (filetype.equals(BatchFileType.Content.toString())) { // TODO fix this 'content' regex. (NAS-1394) regex += Constants.REGEX_CONTENT; } else { regex += Constants.REGEX_ALL; } // validate the regular expression (throws exception if wrong). Pattern.compile(regex); Replica rep = Replica.getReplicaFromName(repName); new BatchExecuter(batchjob, regex, rep).start(); JspWriter out = context.getOut(); out.write("Executing batchjob with the following parameters. " + "<br/>\n"); out.write("BatchJob name: " + jobName + "<br/>\n"); out.write("Replica: " + rep.getName() + "<br/>\n"); out.write("Regular expression: " + regex + "<br/>\n"); } catch (Exception e) { throw new IOFailure("Could not instantiate the batchjob.", e); } }
From source file:com.navercorp.lucy.security.xss.servletfilter.XssEscapeServletFilterTest.java
private void assertFiltered(String paramName, String filteredValue) { ServletRequest filteredRequest = chain.getRequest(); assertThat(filteredRequest.getParameter(paramName), is(filteredValue)); }
From source file:ru.org.linux.auth.CaptchaService.java
public void checkCaptcha(ServletRequest request, Errors errors) { String captchaChallenge = request.getParameter("recaptcha_challenge_field"); String captchaResponse = request.getParameter("recaptcha_response_field"); if (captchaChallenge == null || captchaResponse == null) { errors.reject(null, " "); return;/*w ww . ja v a 2 s. co m*/ } try { ReCaptchaResponse response = captcha.checkAnswer(request.getRemoteAddr(), captchaChallenge, captchaResponse); if (!response.isValid()) { errors.reject(null, " ?"); } } catch (ReCaptchaException e) { logger.warn("Unable to check captcha", e); errors.reject(null, "Unable to check captcha: " + e.getMessage()); } }
From source file:cc.kune.core.server.rack.filters.rest.RESTServiceFilter.java
private String getCallbackMethod(final ServletRequest httpRequest) { return httpRequest.getParameter("callback"); }
From source file:com.redhat.rhn.frontend.taglibs.list.AlphaBarHelper.java
/** * Returns the alpha value..//from w w w . ja v a2s . c o m * @param listName the name of this list, ncessary for unique identification * @param req the servlet request. * @return the alpha value */ public String getAlphaValue(String listName, ServletRequest req) { return req.getParameter(makeAlphaKey(listName)); }
From source file:org.eclipse.skalli.view.internal.filter.SearchFilter.java
@Override protected boolean showNearestProjects(User user, ServletRequest request, ServletResponse response) { String userquery = request.getParameter(Consts.PARAM_USER); return userquery == null || user == null || !userquery.equals(user.getUserId()); }