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.erudika.para.rest.RestUtils.java

/**
 * Extracts the date field from a request. It can be a header or a parameter.
 * @param request a request/*from  w w  w  . j av  a  2 s  .  c  om*/
 * @return the date
 */
public static String extractDate(HttpServletRequest request) {
    if (request == null) {
        return "";
    }
    String date = request.getHeader("X-Amz-Date");
    if (StringUtils.isBlank(date)) {
        return request.getParameter("X-Amz-Date");
    } else {
        return date;
    }
}

From source file:com.bluepandora.therap.donatelife.service.DataService.java

public static void getHospitalList(HttpServletRequest request, HttpServletResponse response)
        throws JSONException {
    DatabaseService dbService = new DatabaseService(DRIVER_NAME, DATABASE_URL, USERNAME, PASSWORD);
    dbService.databaseOpen();//w  w w .j  av a  2  s .c  om
    String query = GetQuery.getHospitalListQuery();
    ResultSet result = dbService.getResultSet(query);
    JSONObject jsonObject = HospitalJson.getHospitalJson(result);
    jsonObject = RequestNameAdderJson.setRequestNameInJson(jsonObject, request.getParameter("requestName"));
    SendJsonData.sendJsonData(request, response, jsonObject);
    dbService.databaseClose();
}

From source file:com.bluepandora.therap.donatelife.service.DataService.java

public static void getDistrictList(HttpServletRequest request, HttpServletResponse response)
        throws JSONException {
    DatabaseService dbService = new DatabaseService(DRIVER_NAME, DATABASE_URL, USERNAME, PASSWORD);
    dbService.databaseOpen();//from  w w w  . j a  va  2  s  .c  o  m
    String query = GetQuery.getDistrictListQuery();
    ResultSet result = dbService.getResultSet(query);
    JSONObject jsonObject = DistrictJson.getDistrictJson(result);
    jsonObject = RequestNameAdderJson.setRequestNameInJson(jsonObject, request.getParameter("requestName"));
    SendJsonData.sendJsonData(request, response, jsonObject);
    dbService.databaseClose();
}

From source file:eu.eubrazilcc.lvl.storage.oauth2.security.OAuth2SecurityManager.java

private static final String getOAuth2AccessToken(final HttpServletRequest request,
        final @Nullable MultivaluedMap<String, String> form, final @Nullable HttpHeaders headers,
        final String resourceName) throws OAuthSystemException {
    try {//from  ww  w  .ja  v a  2s .c  om
        // make the OAuth request out of this request
        final OAuthAccessResourceRequest oauthRequest = new OAuthAccessResourceRequest(
                new OAuth2RequestWrapper(request, form, headers),
                isNotBlank(request.getParameter(AUTHORIZATION_QUERY_OAUTH2)) ? QUERY : HEADER);
        // get the access token
        return oauthRequest.getAccessToken();
    } catch (OAuthProblemException e) {
        // check if the error code has been set
        final String errorCode = e.getError();
        if (OAuthUtils.isEmpty(errorCode)) {
            // setup the OAuth error message
            final OAuthResponse oauthResponse = OAuthRSResponse.errorResponse(SC_UNAUTHORIZED)
                    .setRealm(resourceName).buildHeaderMessage();
            LOGGER.warn("Access from " + getClientAddress(request) + " is denied due to: bad request", e);
            // if no error code then throw a standard 401 unauthorized error
            throw new WebApplicationException(status(UNAUTHORIZED)
                    .header(WWW_AUTHENTICATE, oauthResponse.getHeader(WWW_AUTHENTICATE)).build());
        }
        final OAuthResponse oauthResponse = OAuthRSResponse.errorResponse(SC_UNAUTHORIZED)
                .setRealm(resourceName).setError(e.getError()).setErrorDescription(e.getDescription())
                .setErrorUri(e.getUri()).buildHeaderMessage();
        LOGGER.warn("Access from " + getClientAddress(request) + " is denied due to: " + e.getError() + "("
                + e.getDescription() + ")");
        throw new WebApplicationException(status(BAD_REQUEST)
                .header(WWW_AUTHENTICATE, oauthResponse.getHeader(WWW_AUTHENTICATE)).build());
    }
}

From source file:com.attribyte.essem.model.StoredGraph.java

/**
 * Parses the components of a graph from request parameters.
 * @param request The request.//from w  w  w. ja  v  a  2  s. c om
 * @param app The application name to use (overrides any parameter).
 * @return A parsed graph builder with all parameters set, or null if key is invalid.
 */
public static StoredGraph.Builder parseGraph(final HttpServletRequest request, String app) {
    if (app == null) {
        app = request.getParameter("app");
        if (app == null)
            app = request.getParameter("application");
    }
    MetricKey key = MetricKey.parseKey(request, app);
    if (!key.isValidIdentifier()) {
        return null;
    }

    StoredGraph.Builder graphBuilder = new StoredGraph.Builder();
    graphBuilder.setMetricKey(key);
    graphBuilder.setRangeName(request.getParameter("range"));

    String startTimestampStr = Strings.nullToEmpty(request.getParameter("startTimestamp"));
    if (!startTimestampStr.isEmpty()) {
        graphBuilder.setStartTimestamp(Long.parseLong(startTimestampStr));
    }

    String endTimestampStr = Strings.nullToEmpty(request.getParameter("endTimestamp"));
    if (!endTimestampStr.isEmpty()) {
        graphBuilder.setEndTimestamp(Long.parseLong(endTimestampStr));
    }

    graphBuilder.setDownsampleFn(request.getParameter("downsampleFn"));
    graphBuilder.setRateUnit(request.getParameter("rateUnit"));
    graphBuilder.setTitle(toValidIdentifier(request.getParameter("title")));
    graphBuilder.setDescription(toValidIdentifier(request.getParameter("description")));
    graphBuilder.setXLabel(toValidIdentifier(request.getParameter("xLabel")));
    graphBuilder.setYLabel(toValidIdentifier(request.getParameter("yLabel")));

    String[] tags = request.getParameterValues("tag");
    if (tags != null && tags.length > 0) {
        graphBuilder.setTags(ImmutableSet.copyOf(tags));
    } else if (request.getParameter("tagString") != null) {
        for (String tag : Util.csvSplitter.split(request.getParameter("tagString"))) {
            graphBuilder.addTag(toValidIdentifier(tag));
        }
    }

    return graphBuilder;
}

From source file:com.erudika.para.rest.RestUtils.java

/**
 * Extracts the access key from a request. It can be a header or a parameter.
 * @param request a request//from   w w w. j a  va2 s  . co m
 * @return the access key
 */
public static String extractAccessKey(HttpServletRequest request) {
    if (request == null) {
        return "";
    }
    String auth = request.getHeader(HttpHeaders.AUTHORIZATION);
    if (StringUtils.isBlank(auth)) {
        auth = request.getParameter("X-Amz-Credential");
        if (StringUtils.isBlank(auth)) {
            return "";
        } else {
            return StringUtils.substringBefore(auth, "/");
        }
    } else {
        String credential = StringUtils.substringBetween(auth, "Credential=", ",");
        return StringUtils.substringBefore(credential, "/");
    }
}

From source file:fr.paris.lutece.portal.service.util.AppPathService.java

/**
 * Retrieve the url to redirect to after login. It is given by the
 * redirectUrl parameter if found. The request parameters are copied (except
 * the login and acces code). This is to be used by the doLogin method of
 * AdminLoginJspBean.//from  w w w  .  ja  v a 2 s  .  c o  m
 *
 * @param request the http request
 * @param strDefaultRedirectUrl the default url to go to after login
 * @return an UrlItem corresponding to the url to redirect to after login.
 */
public static UrlItem resolveRedirectUrl(HttpServletRequest request, String strDefaultRedirectUrl) {
    String strUrl = strDefaultRedirectUrl;

    String strUrlKey = request.getParameter(Parameters.REDIRECT_URL);
    String strRedirectUrl = null;

    if (strUrlKey != null) {
        strRedirectUrl = AppPropertiesService.getProperty(PROPERTY_PREFIX_URL + strUrlKey);
    }

    if (strRedirectUrl != null) {
        strUrl = strRedirectUrl;
    }

    Enumeration enumParams = request.getParameterNames();
    UrlItem url = new UrlItem(getBaseUrl(request) + strUrl);

    String strParamName;

    while (enumParams.hasMoreElements()) {
        strParamName = (String) enumParams.nextElement();

        if (!strParamName.equals(Parameters.REDIRECT_URL) && !strParamName.equals(Parameters.ACCESS_CODE)
                && !strParamName.equals(Parameters.PASSWORD)) {
            url.addParameter(strParamName, request.getParameter(strParamName));
        }
    }

    return url;
}

From source file:com.stratelia.silverpeas.pdcPeas.servlets.PdcSearchRequestRouterHelper.java

/**
 * put in the request the primary axis and eventually the secondary axis accroding to search
 * context//from w  w  w  .j  av a  2 s. c  o m
 *
 * @param pdcSC
 * @param request
 * @throws Exception
 */
public static void setPertinentAxis(PdcSearchSessionController pdcSC, HttpServletRequest request)
        throws Exception {
    SilverTrace.info("pdcPeas", "PdcPeasRequestRouterHelper.setPertinentAxis()", "root.MSG_GEN_ENTER_METHOD");

    String showSecondarySearchAxis = request.getParameter("ShowSndSearchAxis");

    // does the user want to see secondary axis ?
    if (showSecondarySearchAxis == null) {
        showSecondarySearchAxis = pdcSC.getSecondaryAxis();
    } else {
        pdcSC.setSecondaryAxis(showSecondarySearchAxis);
    }

    SilverTrace.info("pdcPeas", "PdcPeasRequestRouterHelper.setAttributesAdvancedSearch()",
            "root.MSG_GEN_PARAM_VALUE", "avant getAxis(P)");

    // we get primary and eventually secondary axis
    List<SearchAxis> primarySearchAxis = pdcSC.getAxis("P");
    List<SearchAxis> pertinentPrimaryAxis = new ArrayList<SearchAxis>();
    for (SearchAxis axis : primarySearchAxis) {
        List<Value> values = pdcSC.getDaughterValues(Integer.toString(axis.getAxisId()), "0");
        if (values != null && !values.isEmpty()) {
            axis.setValues(values);
            pertinentPrimaryAxis.add(axis);
        }
    }

    SilverTrace.info("pdcPeas", "PdcPeasRequestRouterHelper.setAttributesAdvancedSearch()",
            "root.MSG_GEN_PARAM_VALUE", "avant getAxis(S)");
    List<SearchAxis> secondarySearchAxis = null;
    List<SearchAxis> pertinentSecondaryAxis = new ArrayList<SearchAxis>();
    if ("YES".equals(showSecondarySearchAxis)) {
        // user wants to see secondary axis
        secondarySearchAxis = pdcSC.getAxis("S");
        for (SearchAxis axis : secondarySearchAxis) {
            List<Value> values = pdcSC.getDaughterValues(Integer.toString(axis.getAxisId()), "0");
            if (values != null && !values.isEmpty()) {
                axis.setValues(values);
                pertinentSecondaryAxis.add(axis);
            }
        }
    }

    // We set axis into the request
    request.setAttribute("ShowPrimaryAxis", pertinentPrimaryAxis);
    request.setAttribute("ShowSecondaryAxis", pertinentSecondaryAxis);
    request.setAttribute("ShowSndSearchAxis", pdcSC.getSecondaryAxis());

    SilverTrace.info("pdcPeas", "PdcPeasRequestRouterHelper.setPertinentAxis()", "root.MSG_GEN_EXIT_METHOD");
}

From source file:edu.stanford.epad.epadws.security.EPADSessionOperations.java

public static EPADSessionResponse authenticateUser(HttpServletRequest httpRequest) {
    String username = extractUserNameFromAuthorizationHeader(httpRequest);
    String password = extractPasswordFromAuthorizationHeader(httpRequest);
    if (username == null || username.length() == 0) {
        username = httpRequest.getParameter("username");
        password = httpRequest.getParameter("password");
    }/*from  w w  w  .j a v  a 2  s  .c o  m*/
    EPADSession session = null;
    try {
        if (username != null && password == null && httpRequest.getParameter("adminuser") != null) {
            session = EPADSessionOperations.createProxySession(username, httpRequest.getParameter("adminuser"),
                    httpRequest.getParameter("adminpassword"));
        } else if (username == null && httpRequest.getAuthType().equals("WebAuth")
                && httpRequest.getRemoteUser() != null) {
            if (password != null && password.equals(EPADConfig.webAuthPassword))
                session = EPADSessionOperations.createPreAuthenticatedSession(httpRequest.getRemoteUser());
        } else {
            session = EPADSessionOperations.createNewEPADSession(username, password);
        }
        EPADSessionResponse response = new EPADSessionResponse(HttpServletResponse.SC_OK,
                session.getSessionId(), "");
        log.info("Session ID " + response.response + " generated for user " + username);
        return response;
    } catch (Exception x) {
        EPADSessionResponse response = new EPADSessionResponse(HttpServletResponse.SC_UNAUTHORIZED, null,
                x.getMessage());
        return response;
    }
}

From source file:fr.paris.lutece.plugins.workflow.modules.notifygru.service.Validator.java

/**
 * Checks if is valide build provider service.
 *
 * @param request the request/*  w  w  w .  j a va 2  s .  c  o  m*/
 * @param config the config
 * @param providerService the _provider service
 * @param locale the locale
 * @param task the task
 * @return the string
 */
public static String isValideBuildProviderService(HttpServletRequest request, TaskNotifyGruConfig config,
        AbstractServiceProvider providerService, Locale locale, ITask task) {
    String strUrlRedirector = "";
    String strProvider = request.getParameter(Constants.PARAMETER_SELECT_PROVIDER);
    int nDemandStatus = (VALUE_CHECKBOX.equals(request.getParameter(Constants.PARAMETER_DEMAND_STATUS))) ? 1
            : 0;

    if ((strProvider != null) && ServiceConfigTaskForm.isBeanExiste(strProvider, task)) {
        config.setIdSpringProvider(strProvider);
        config.setDemandStatus(nDemandStatus);
    }

    /*if the provider is already register*/
    else if (config.getIdSpringProvider() == null) {
        Object[] tabRequiredFields = {
                I18nService.getLocalizedString(Constants.MESSAGE_MANDATORY_PROVIDER, locale), };

        strUrlRedirector = AdminMessageService.getMessageUrl(request, Constants.MESSAGE_MANDATORY_PROVIDER,
                tabRequiredFields, AdminMessage.TYPE_STOP);
    }

    return strUrlRedirector;
}