Example usage for javax.servlet.http HttpServletRequest getParameter

List of usage examples for javax.servlet.http HttpServletRequest getParameter

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletRequest getParameter.

Prototype

public String getParameter(String name);

Source Link

Document

Returns the value of a request parameter as a String, or null if the parameter does not exist.

Usage

From source file:com.threewks.thundr.view.jsonp.JsonpViewResolver.java

public static String getCallback(HttpServletRequest req) {
    Object callback = req.getParameter("callback");
    String callbackStr = callback == null ? null : StringUtils.trimToNull(callback.toString());
    callbackStr = callbackStr == null ? "callback" : callbackStr;
    return callbackStr;
}

From source file:co.edu.unal.arqdsoft.presentacion.JSON.java

/**
 * /*from   w  w  w .j a v a2s .c o m*/
 * @param request
 * @return JSONObject con los parametros del request
 * @throws Exception 
 */
public static JSONObject toObject(HttpServletRequest request) throws Exception {
    if (request.getParameter("accion") != null) {//Servidor independiente
        JSONObject r = new JSONObject();
        r.put("accion", request.getParameter("accion"));
        r.put("datos", request.getParameter("datos"));
        return r;
    } else {//Servidor base netbeans
        InputStream is = request.getInputStream();
        byte[] charr = new byte[is.available()];
        is.read(charr);
        return (JSONObject) JSONValue.parse(new String(charr, "UTF-8"));
    }
}

From source file:common.web.controller.CommonActionsEmail.java

/**
 * executes an update, serves as a template method that incapsulates common logic for insert action
 * @param service/* w  w  w. j a v a  2 s.co m*/
 * @param config
 * @param val for validation
 * @param req resulting model (i.e. errors, command objects ...) will be placed here
 */
public static void doInsert(IInsertServiceNotificationUser service, IControllerConfig config,
        ABindValidator val, HttpServletRequest req) {
    String action = req.getParameter(ControllerConfig.ACTION_PARAM_NAME);
    Object command = service.getInsertBean();
    RequestUtils.copyRequestAttributesFromMap(req, service.initInsert());

    if ("insert".equals(action)) {
        /** bind command */
        BindingResult res = val.bindAndValidate(command, req);
        if (res.hasErrors()) {
            //m.putAll(res.getModel());
            req.setAttribute(res.MODEL_KEY_PREFIX + config.getContentDataAttribute(), res);
            req.setAttribute(config.getContentDataAttribute(), command);
            common.CommonAttributes.addErrorMessage("form_errors", req);
            //return false;
        } else {
            service.insert(command);
            String server = RequestUtils.getFullServerPathHttp(req);
            //TODO set groups for getting advertisment from DB
            service.sendInsertNotificationUser(command, server, "site name", null);
            req.setAttribute(config.getContentDataAttribute(), service.getInsertBean());
            common.CommonAttributes.addHelpMessage("operation_succeed", req);
            //return true;
        }
    } else {
        req.setAttribute(config.getContentDataAttribute(), command);
    }
}

From source file:net.sourceforge.fenixedu.presentationTier.Action.base.FenixContextDispatchAction.java

public static Boolean getFromRequestBoolean(String parameter, HttpServletRequest request) {
    return (request.getParameter(parameter) != null) ? Boolean.valueOf(request.getParameter(parameter))
            : (Boolean) request.getAttribute(parameter);
}

From source file:at.gv.egovernment.moa.id.util.legacy.LegacyHelper.java

public static boolean isUseMandateRequested(HttpServletRequest req) throws WrongParametersException {

    String useMandate = req.getParameter(PARAM_USEMANDATE);
    useMandate = StringEscapeUtils.escapeHtml(useMandate);
    if (!ParamValidatorUtils.isValidUseMandate(useMandate))
        throw new WrongParametersException("StartAuthentication", PARAM_USEMANDATE, "auth.12");

    //check UseMandate flag
    String useMandateString = null;
    if ((useMandate != null) && (useMandate.compareTo("") != 0)) {
        useMandateString = useMandate;/*from  w ww . ja va  2 s  . c om*/
    } else {
        useMandateString = "false";
    }

    if (useMandateString.compareToIgnoreCase("true") == 0)
        return true;
    else
        return false;
}

From source file:net.sourceforge.fenixedu.presentationTier.Action.base.FenixContextDispatchAction.java

public static String getFromRequest(String parameter, HttpServletRequest request) {
    if (request.getParameter(parameter) != null) {
        return request.getParameter(parameter);
    } else if (request.getAttribute(parameter) != null) {
        if (request.getAttribute(parameter) instanceof String) {
            return (String) request.getAttribute(parameter);
        }//from   w ww  .j a va2 s  .  c o  m
    }
    return null;
}

From source file:com.daimler.spm.storefront.util.CSRFTokenManager.java

/**
 * Returns the CSRF token from the httpServletRequest.
 *
 * @param httpServletRequest//from   w w  w.ja va 2s  .  c o m
 *           the httpServletRequest to retrieve CSRF token from
 * @return the CSRF token
 */
public static String getTokenFromRequest(final HttpServletRequest httpServletRequest) {
    final String requestCsrfToken = httpServletRequest.getParameter(CSRF_PARAM_NAME);

    if (requestCsrfToken == null) {
        return httpServletRequest.getHeader(CSRF_PARAM_NAME);
    } else {
        return requestCsrfToken;
    }
}

From source file:com.adeptj.modules.security.core.credential.UsernamePasswordCredential.java

public static UsernamePasswordCredential from(HttpServletRequest request) {
    String username = request.getParameter(PARAM_USERNAME);
    String password = request.getParameter(PARAM_PWD);
    if (METHOD_POST.equals(request.getMethod())
            && StringUtils.endsWith(request.getRequestURI(), LOGIN_URI_SUFFIX)
            && StringUtils.isNoneEmpty(username, password)) {
        return new UsernamePasswordCredential(username, password.toCharArray());
    }//from   w  w  w .j a  va2  s.com
    return null;
}

From source file:org.ow2.chameleon.fuchsia.push.base.hub.dto.SubscriptionRequest.java

private static void validateRequest(HttpServletRequest request) throws InvalidContentNotification {

    if (request.getParameter(HUB_CALLBACK) == null || request.getParameter(HUB_MODE) == null
            || request.getParameter(HUB_TOPIC) == null || request.getParameter(HUB_VERIFY) == null) {
        throw new InvalidContentNotification("Parameters requested not defined in the request");
    }/*w w  w  .  j av  a2s.  c  o  m*/
}

From source file:com.dotcms.LicenseTestUtil.java

public static void getLicense() throws Exception {

    if (LicenseUtil.getLevel() < 200) {
        String license;//from   ww w .j  ava 2 s  . c  o m
        HttpServletRequest req = Mockito.mock(HttpServletRequest.class);
        Mockito.when(req.getParameter("iwantTo")).thenReturn("request_code");
        Mockito.when(req.getParameter("license_type")).thenReturn("trial");
        Mockito.when(req.getParameter("license_level")).thenReturn("400");

        final StringBuilder reqcode = new StringBuilder();

        Mockito.doAnswer(new Answer() {
            public Object answer(com.dotcms.repackage.org.mockito.invocation.InvocationOnMock invocation)
                    throws Throwable {
                reqcode.append(invocation.getArguments()[1].toString());
                return null;
            }
        }).when(req).setAttribute(Mockito.eq("requestCode"), Mockito.any(String.class));

        LicenseUtil.processForm(req);

        HttpClient client = new HttpClient();
        PostMethod post = new PostMethod("http://support.dotcms.com/app/licenseRequest3");
        post.setRequestBody(new NameValuePair[] { new NameValuePair("code", reqcode.toString()) });
        client.executeMethod(post);

        if (post.getStatusCode() == 200) {
            license = post.getResponseBodyAsString();
            HttpServletRequest req2 = Mockito.mock(HttpServletRequest.class);
            Mockito.when(req2.getParameter("iwantTo")).thenReturn("paste_license");
            Mockito.when(req2.getParameter("license_text")).thenReturn(license);
            LicenseUtil.processForm(req2);
        }
    }
}