List of usage examples for javax.servlet.http HttpServletRequest getParameter
public String getParameter(String name);
String
, or null
if the parameter does not exist. From source file:com.photon.phresco.framework.commons.ApplicationsUtil.java
public static Map<String, String> getIdAndVersionAsMap(HttpServletRequest request, String[] ids) { Map<String, String> map = new HashMap<String, String>(15); for (String id : ids) { map.put(id, request.getParameter(id)); }//from ww w . j a v a 2 s .c o m return map; }
From source file:ch.cern.security.saml2.utils.UrlUtils.java
/** * Generates the URL response (IdP)//from w w w. j a v a 2 s. c o m * * @param request * @param isDebugEnabled * @return The logout URL: * https://login.cern.ch/adfs/ls/?SAMLResponse=value& * SigAlg=value&Signature=value * @throws DataFormatException * @throws ParserConfigurationException * @throws SAXException * @throws IOException * @throws UnrecoverableKeyException * @throws InvalidKeyException * @throws KeyStoreException * @throws NoSuchProviderException * @throws NoSuchAlgorithmException * @throws CertificateException * @throws SignatureException * @throws XMLStreamException */ public static String generateSamlResponse(HttpServletRequest request, boolean isDebugEnabled) throws DataFormatException, ParserConfigurationException, SAXException, IOException, UnrecoverableKeyException, InvalidKeyException, KeyStoreException, NoSuchProviderException, NoSuchAlgorithmException, CertificateException, SignatureException, XMLStreamException { // Get the request as an XML String xmlLogoutRequest = XMLUtils.xmlDecodeAndInflate(request.getParameter(Constants.SAML_REQUEST), isDebugEnabled); // Parse the xml request. Encapsulate the data in a SamlVO object SamlVO samlVO = XMLUtils.parseXMLmessage(xmlLogoutRequest, isDebugEnabled); // Add the destination: context-param in web.xml. This info is not in the logoutRequest samlVO.setDestination( (String) request.getSession().getServletContext().getAttribute(Constants.IDP_ENDPOINT)); // Generates the ID byte[] buf = new byte[16]; SecureRandom.getInstance(RANDOM_ALGORITHM).nextBytes(buf); samlVO.setId("_".concat(new String(Hex.encode(buf)))); // Set the issueInstant SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DATE_FORMAT); samlVO.setIssueInstant(simpleDateFormat.format(new Date())); // Get the entityID!!! samlVO.setIssuer((String) request.getSession().getServletContext().getAttribute(Constants.ENTITY_ID)); // Generate the LogoutResponse String samlResponse = XMLUtils.createXMLresponse(samlVO, isDebugEnabled); // Deflate and encode the LogoutResponse String base64response = XMLUtils.xmlDeflateAndEncode(samlResponse, isDebugEnabled); // URL-encode the deflatedResponse String urlEncodedresponse = URLEncoder.encode(base64response, Constants.CHARACTER_ENCODING); if (isDebugEnabled) nc.notice("Data to sign: " + Constants.SAML_RESPONSE + EQUAL + urlEncodedresponse + AMPERSAND + Constants.SIG_ALG + EQUAL + URLEncoder.encode( (String) request.getSession().getServletContext().getAttribute(Constants.SIG_ALG), Constants.CHARACTER_ENCODING)); // Sign the SAMLResponse=value&SigAlg=value String signature = SignatureUtils.sign( Constants.SAML_RESPONSE + EQUAL + urlEncodedresponse + AMPERSAND + Constants.SIG_ALG + EQUAL + URLEncoder.encode( (String) request.getSession().getServletContext().getAttribute(Constants.SIG_ALG), Constants.CHARACTER_ENCODING), (PrivateKey) request.getSession().getServletContext().getAttribute(Constants.SP_PRIVATE_KEY), (String) request.getSession().getServletContext().getAttribute(Constants.ALGORITHM), isDebugEnabled); // URL-encode the signature String urlEncodedSignature = URLEncoder.encode(signature, Constants.CHARACTER_ENCODING); if (isDebugEnabled) nc.notice("Final URL: " + (String) request.getSession().getServletContext().getAttribute(Constants.IDP_ENDPOINT) + QUESTION_MARK + Constants.SAML_RESPONSE + EQUAL + urlEncodedresponse + AMPERSAND + Constants.SIG_ALG + EQUAL + URLEncoder.encode( (String) request.getSession().getServletContext().getAttribute(Constants.SIG_ALG), Constants.CHARACTER_ENCODING) + AMPERSAND + SIGNATURE + EQUAL + urlEncodedSignature); // Constructs the final URL // https://endpoint/?SAMLResponse=value&SigAlg=value&Signature=value return (String) request.getSession().getServletContext().getAttribute(Constants.IDP_ENDPOINT) + QUESTION_MARK + Constants.SAML_RESPONSE + EQUAL + urlEncodedresponse + AMPERSAND + Constants.SIG_ALG + EQUAL + URLEncoder.encode( (String) request.getSession().getServletContext().getAttribute(Constants.SIG_ALG), Constants.CHARACTER_ENCODING) + AMPERSAND + SIGNATURE + EQUAL + urlEncodedSignature; }
From source file:com.jslsolucoes.tagria.lib.util.TagUtil.java
public static String queryString(HttpServletRequest request, List<String> excludesParams) throws UnsupportedEncodingException { List<String> queryString = new ArrayList<>(); Enumeration<String> en = request.getParameterNames(); while (en.hasMoreElements()) { String paramName = en.nextElement(); if (!excludesParams.contains(paramName)) queryString.add(paramName + "=" + URLEncoder.encode(request.getParameter(paramName), "UTF-8")); }//from ww w . j av a2 s . c o m return StringUtils.join(queryString, '&'); }
From source file:com.bluepandora.therap.donatelife.service.DataService.java
public static void getBloodGroupList(HttpServletRequest request, HttpServletResponse response) throws SQLException, IOException, JSONException { DatabaseService dbService = new DatabaseService(DRIVER_NAME, DATABASE_URL, USERNAME, PASSWORD); dbService.databaseOpen();/* www . ja v a2 s. co m*/ String query = GetQuery.getBloodGroupListQuery(); ResultSet result = dbService.getResultSet(query); JSONObject jsonObject = BloodGroupJson.getJsonBloodGroup(result); jsonObject = RequestNameAdderJson.setRequestNameInJson(jsonObject, request.getParameter("requestName")); SendJsonData.sendJsonData(request, response, jsonObject); dbService.databaseClose(); }
From source file:com.easou.common.util.CommonUtils.java
/** * Safe method for retrieving a parameter from the request without * disrupting the reader UNLESS the parameter actually exists in the query * string.//from w w w.jav a2 s . c o m * <p> * Note, this does not work for POST Requests for "logoutRequest". It works * for all other CAS POST requests because the parameter is ALWAYS in the * GET request. * <p> * If we see the "logoutRequest" parameter we MUST treat it as if calling * the standard request.getParameter. * * @param request * the request to check. * @param parameter * the parameter to look for. * @return the value of the parameter. */ public static String safeGetParameter(final HttpServletRequest request, final String parameter) { if ("POST".equals(request.getMethod()) && "logoutRequest".equals(parameter)) { LOG.debug( "safeGetParameter called on a POST HttpServletRequest for LogoutRequest. Cannot complete check safely. Reverting to standard behavior for this Parameter"); return request.getParameter(parameter); } return request.getQueryString() == null || request.getQueryString().indexOf(parameter) == -1 ? null : request.getParameter(parameter); }
From source file:org.nlp2rdf.webservice.NIFParameterWebserviceFactory.java
/** * Factory method/* ww w. j a va2 s. c om*/ * * @param httpServletRequest * @return */ public static NIFParameters getInstance(HttpServletRequest httpServletRequest, String defaultPrefix) throws ParameterException, IOException { //twice the size to split key value String[] args = new String[httpServletRequest.getParameterMap().size() * 2]; int x = 0; for (Object key : httpServletRequest.getParameterMap().keySet()) { String pname = (String) key; //transform key to CLI style pname = (pname.length() == 1) ? "-" + pname : "--" + pname; //collect CLI args args[x++] = pname; args[x++] = httpServletRequest.getParameter((String) key); } String line; String content = ""; try { BufferedReader reader = new BufferedReader(new InputStreamReader(httpServletRequest.getInputStream())); while ((line = reader.readLine()) != null) { if (line.startsWith("---") || line.startsWith("Content") || line.startsWith("html")) continue; content += line; } } catch (IOException e) { e.printStackTrace(); } if (args.length == 0 && !content.isEmpty()) { args = new String[4]; String[] params = content.split("&"); if (params.length > 0) { String[] i = params[0].split("="); String[] id = params[1].split("="); if (i.length > 0) { args[0] = "--" + i[0]; args[1] = URLDecoder.decode(i[1], "UTF-8"); } if (id.length > 0) { args[2] = "-" + id[0]; args[3] = URLDecoder.decode(id[1], "UTF-8"); } content = ""; } } // System.out.println(content); //parse CLI args OptionParser parser = ParameterParser.getParser(args, defaultPrefix); OptionSet options = ParameterParser.getOption(parser, args); // print help screen if (options.has("h")) { String addHelp = ""; ByteArrayOutputStream baos = new ByteArrayOutputStream(); parser.printHelpOn(baos); throw new ParameterException(baos.toString()); } // parse options with webservice setted to true return ParameterParserMS.parseOptions(options, true, content); }
From source file:com.photon.phresco.framework.commons.ApplicationsUtil.java
public static ApplicationType getApplicationType(HttpServletRequest request, String appTypeName) throws PhrescoException { ApplicationType applicationtype = null; try {/* w ww . j a v a 2 s. co m*/ String appType = request.getParameter(REQ_APPLICATION_TYPE); if (debugEnabled) { S_LOGGER.debug("Selected application type" + appType); } ProjectAdministrator administrator = PhrescoFrameworkFactory.getProjectAdministrator(); applicationtype = administrator.getApplicationType(appType); } catch (Exception e) { if (debugEnabled) { S_LOGGER.error("Entered into catch block of Applications.getApplicationType()" + FrameworkUtil.getStackTraceAsString(e)); } new LogErrorReport(e, "Getting application types"); } return applicationtype; }
From source file:org.openmrs.web.attribute.WebAttributeUtil.java
/** * Gets the value of an attribute out of an HTTP request, treating it according to the appropriate handler type. * * @param request//from w w w .j av a2 s . co m * @param handler * @param paramName * @return value of the attribute */ public static <T> T getValue(HttpServletRequest request, CustomDatatype<T> dt, CustomDatatypeHandler<CustomDatatype<T>, T> handler, String paramName) { if (handler != null) { if (handler instanceof FieldGenDatatypeHandler) { return ((FieldGenDatatypeHandler<CustomDatatype<T>, T>) handler).getValue(dt, request, paramName); } else if (handler instanceof WebDatatypeHandler) { return ((WebDatatypeHandler<CustomDatatype<T>, T>) handler).getValue(dt, request, paramName); } } String submittedValue = request.getParameter(paramName); if (StringUtils.isNotEmpty(submittedValue)) { // check empty instead of blank, because " " is meaningful return dt.fromReferenceString(submittedValue); } else { return null; } }
From source file:net.hillsdon.reviki.web.pages.impl.DefaultPageImpl.java
private static long getRevision(final HttpServletRequest request) throws InvalidInputException { Long givenRevision = getLong(request.getParameter(PARAM_REVISION), PARAM_REVISION); return givenRevision == null ? -1 : givenRevision; }
From source file:com.redhat.rhn.frontend.action.LoginHelper.java
/** static method shared by LoginAction and LoginSetupAction * @param request actual request//w w w . j av a 2 s .c om * @param response actual reponse * @param user logged in user * @return returns true, if redirect */ public static boolean successfulLogin(HttpServletRequest request, HttpServletResponse response, User user) { // set last logged in user.setLastLoggedIn(new Date()); UserManager.storeUser(user); // update session with actual user PxtSessionDelegateFactory.getInstance().newPxtSessionDelegate().updateWebUserId(request, response, user.getId()); LoginHelper.publishUpdateErrataCacheEvent(user.getOrg()); // redirect, if url_bounce set String urlBounce = request.getParameter("url_bounce"); String reqMethod = request.getParameter("request_method"); urlBounce = LoginAction.updateUrlBounce(urlBounce, reqMethod); try { if (urlBounce != null) { log.info("redirect: " + urlBounce); response.sendRedirect(urlBounce); return true; } } catch (IOException e) { e.printStackTrace(); } return false; }