List of usage examples for org.apache.http.client.utils URLEncodedUtils parse
public static List<NameValuePair> parse(final String s, final Charset charset)
From source file:io.soabase.web.filters.LanguageFilter.java
private String getFromQueryString(String queryString, AtomicReference<String> fixedQueryString) { if ((queryString != null) && !queryString.trim().isEmpty()) { fixedQueryString.set(queryString); List<NameValuePair> nameValuePairs = URLEncodedUtils.parse(queryString, Charsets.UTF_8); Optional<NameValuePair> first = nameValuePairs.stream() .filter(vp -> vp.getName().equals(queryParameterName)).findFirst(); if (first.isPresent()) { try { List<NameValuePair> copy = nameValuePairs.stream().filter(p -> p != first.get()) .collect(Collectors.toList()); fixedQueryString.set(URLEncodedUtils.format(copy, Charsets.UTF_8)); return validate(first.get().getValue()); } catch (IllegalArgumentException ignore) { log.debug("Query param set to invalid language", first.get()); }//from ww w . j a v a 2 s. c o m } } return null; }
From source file:com.hp.autonomy.hod.client.api.authentication.AuthenticationServiceImplTest.java
@Test public void generatesANonce() { final SignedRequest request = service.combinedRequest(ALLOWED_ORIGINS, TOKEN, DOMAIN, APPLICATION, USER_STORE_DOMAIN, USER_STORE_NAME, TokenType.Simple.INSTANCE, true); final List<NameValuePair> bodyPairs = URLEncodedUtils.parse(request.getBody(), StandardCharsets.UTF_8); final NameValuePair noncePair = getParameterPair(bodyPairs, "nonce"); assertThat(noncePair, notNullValue()); final String nonce = noncePair.getValue(); assertThat(nonce, notNullValue());/*from w w w. j av a 2 s .co m*/ }
From source file:com.linkedin.drelephant.clients.azkaban.AzkabanWorkflowClient.java
/** * Sets the workflow execution id given the azkaban workflow url * @param azkabanWorkflowUrl The url of the azkaban workflow * @throws MalformedURLException//from w ww .j a v a 2s .c o m * @throws URISyntaxException */ private void setExecutionId(String azkabanWorkflowUrl) throws MalformedURLException, URISyntaxException { List<NameValuePair> params = URLEncodedUtils.parse(new URI(azkabanWorkflowUrl), "UTF-8"); for (NameValuePair param : params) { if (param.getName() == "execid") { this._executionId = param.getValue(); } } }
From source file:org.forgerock.openam.mobile.example.oauth2.activities.webview.AuthorizeWebClient.java
/** * Each time the page is finished we check whether or not we are on the * page to which we intend to be redirected. Once we've ascertained we are * on the right place, we take the code parameter from the end of the URL and * return that to the user in a new UnwrappedResponse object. * * @param view/* w w w . j av a2 s . c o m*/ * @param url */ @Override public void onPageFinished(WebView view, String url) { String prefix = authZClient.getOAuth2ServerResource().getRedirectUri(); if (url.startsWith(prefix)) { URI tempUri = null; try { tempUri = new URI(url); } catch (URISyntaxException e) { Log.e(TAG, "Unable to validate URI correctly.", e); } List<NameValuePair> params = URLEncodedUtils.parse(tempUri, RestConstants.UTF8); for (NameValuePair nvp : params) { if (nvp.getName().equals(AuthZConstants.CODE)) { UnwrappedResponse res = new UnwrappedResponse(RestConstants.HTTP_SUCCESS, nvp.getValue(), OAuthAction.GET_CODE, OAuthAction.GET_CODE_FAIL); activity.onEvent(OAuthAction.GET_CODE, res); } } } }
From source file:org.pepstock.jem.node.https.SubmitHandler.java
@Override public void handle(final HttpRequest request, final HttpResponse response, final HttpContext context) throws HttpException, IOException { // extracts the host String host = context.getAttribute(JOB_SUBMIT_IP_ADDRESS_KEY).toString(); // gets HTTP method (uses locale ENGLISH to be sure to have POST) String method = request.getRequestLine().getMethod().toUpperCase(Locale.ENGLISH); // if NOT post, exception! if (!method.equals(POST)) { LogAppl.getInstance().emit(NodeMessage.JEMC284W, method, host); throw new MethodNotSupportedException( NodeMessage.JEMC284W.toMessage().getFormattedMessage(method, host)); }// w w w. ja v a 2s . c o m // gets the URI or the request String target = request.getRequestLine().getUri(); // if is not the same , accepts, exception! if (!target.equalsIgnoreCase(DEFAULT_ACTION)) { LogAppl.getInstance().emit(NodeMessage.JEMC285W, target, host); throw new MethodNotSupportedException( NodeMessage.JEMC285W.toMessage().getFormattedMessage(target, host)); } // checks the HTTP request if (request instanceof HttpEntityEnclosingRequest) { // gets the entity of the request HttpEntity entity = ((HttpEntityEnclosingRequest) request).getEntity(); // gets the body in string format String result = EntityUtils.toString(entity, CharSet.DEFAULT); // reads the first line, // with all URL encoded variables String vars = StringUtils.substringBefore(result, DELIMITER); // loads a map with all parms Map<String, String> parms = loadParametersMap(URLEncodedUtils.parse(vars, CharSet.DEFAULT)); // gets the USER String user = parms.get(SubmitParameters.USER.getName()); // if JEM is configured to have the Socket Interceptor on HC // the client MUST provide a SIGNATURE (using own private key) with // the user crypted inside if (Main.getHazelcastConfig().getNetworkConfig().getSocketInterceptorConfig().isEnabled()) { // checks if there is the signature if (parms.containsKey(USER_SIGNATURE_KEY)) { // gets the signature in HEX format String cryptedUserString = parms.get(USER_SIGNATURE_KEY); // gets keys stores KeyStoresInfo keyStoresInfo = KeyStoreUtil.getKeyStoresInfo(); try { // extracts from the USER key store the PUBLIC KEY (upload by UI) for the user PublicKey publicKey = KeysUtil.getPublicKeyByAlias(keyStoresInfo.getUserKeystoreInfo(), user); // creates tne SIGNATURE verifying steps Signature signature = Signature.getInstance("SHA256withRSA"); // sets public key signature.initVerify(publicKey); // sets content to check. It uses USER signature.update(user.getBytes(CharSet.DEFAULT_CHARSET_NAME)); // checks if is verified if (!signature.verify(Hex.decodeHex(cryptedUserString.toCharArray()))) { // if not, log and EXCEPTION LogAppl.getInstance().emit(NodeMessage.JEMC286W, user, host); throw new HttpException( NodeMessage.JEMC286W.toMessage().getFormattedMessage(user, host)); } } catch (MessageException e) { LogAppl.getInstance().emit(NodeMessage.JEMC286W, user, host); throw new ProtocolException(e.getMessage(), e); } catch (KeyException e) { throw new ProtocolException(e.getMessage(), e); } catch (DecoderException e) { throw new ProtocolException(e.getMessage(), e); } catch (NoSuchAlgorithmException e) { throw new ProtocolException(e.getMessage(), e); } catch (SignatureException e) { throw new ProtocolException(e.getMessage(), e); } } else { LogAppl.getInstance().emit(NodeMessage.JEMC287W, user, host); // if here, the signature is missing throw new HttpException(NodeMessage.JEMC287W.toMessage().getFormattedMessage(user, host)); } } // gets JEM environemnt name and its passwrod String env = parms.get(SubmitParameters.ENV.getName()); String password = parms.get(SubmitParameters.PASSWORD.getName()); // checks if password and env are same, // comparing with the HC configuration if (!Main.getHazelcastConfig().getGroupConfig().getName().equalsIgnoreCase(env) || !Main.getHazelcastConfig().getGroupConfig().getPassword().equalsIgnoreCase(password)) { // if not equals, exception LogAppl.getInstance().emit(NodeMessage.JEMC288W, host); throw new HttpException(NodeMessage.JEMC288W.toMessage().getFormattedMessage(host)); } // reads teh second row of the body, with the JCL String jcl = StringUtils.substringAfter(result, DELIMITER); // sets the entity to send back, submitting the job. // it returns the JOBID StringEntity resultEntity = new StringEntity(submit(jcl, user, host, parms), ContentType.create(RESPONSE_MIME_TYPE, CharSet.DEFAULT_CHARSET_NAME)); // sets STATUS code and entity response.setStatusCode(HttpStatus.SC_OK); response.setEntity(resultEntity); } else { // if here, the request is not correct LogAppl.getInstance().emit(NodeMessage.JEMC284W, method, host); throw new MethodNotSupportedException( NodeMessage.JEMC284W.toMessage().getFormattedMessage(method, host)); } }
From source file:com.fortify.bugtracker.tgt.tfs.connection.TFSRestConnection.java
private String getIssueId(TargetIssueLocator targetIssueLocator) { String id = targetIssueLocator.getId(); if (StringUtils.isBlank(id)) { String deepLink = targetIssueLocator.getDeepLink(); @SuppressWarnings("deprecation") List<NameValuePair> params = URLEncodedUtils.parse(URI.create(deepLink), "UTF-8"); for (NameValuePair param : params) { if ("id".equals(param.getName())) { return param.getValue(); }// w w w. ja va2 s. c om } } return id; }
From source file:com.bazaarvoice.seo.sdk.url.BVSeoSdkURLBuilder.java
/** * TODO: This method can be further optimized. but make sure that the functionality doesn't break. * @return// w ww .j a va 2 s . c om */ private URI c2013Uri() { ContentType contentType = null; SubjectType subjectType = null; String subjectId = null; List<NameValuePair> parameters = URLEncodedUtils.parse(queryString, Charset.forName("UTF-8")); for (NameValuePair parameter : parameters) { if (parameter.getName().equals(BV_PAGE)) { StringTokenizer tokens = new StringTokenizer(parameter.getValue(), "/"); while (tokens.hasMoreTokens()) { String token = tokens.nextToken(); if (token.startsWith("pg") && StringUtils.isBlank(bvParameters.getPageNumber())) { bvParameters.setPageNumber(getValue(token)); } else if (token.startsWith("ct")) { contentType = ContentType.ctFromKeyWord(getValue(token)); } else if (token.startsWith("st")) { subjectType = SubjectType.subjectType(getValue(token)); } else if (token.startsWith("id")) { subjectId = getValue(token); } } } } contentType = (contentType == null) ? bvParameters.getContentType() : contentType; subjectType = (subjectType == null) ? bvParameters.getSubjectType() : subjectType; subjectId = (StringUtils.isBlank(subjectId)) ? bvParameters.getSubjectId() : subjectId; if (StringUtils.isBlank(bvParameters.getPageNumber())) { bvParameters.setPageNumber(NUM_ONE_STR); } String path = getPath(contentType, subjectType, bvParameters.getPageNumber(), subjectId, bvParameters.getContentSubType()); if (isContentFromFile()) { return fileUri(path); } return httpUri(path); }
From source file:com.wikitude.example.SimpleARBrowserActivity.java
/** * <p>/*from w w w . j a v a2 s .co m*/ * interface method of {@link ArchitectUrlListener} class * called when an url with host "architectsdk://" is discovered * * can be parsed and allows to react to events triggered in the ARchitect World * </p> */ @Override public boolean urlWasInvoked(String url) { //parsing the retrieved url string List<NameValuePair> queryParams = URLEncodedUtils.parse(URI.create(url), "UTF-8"); String id = ""; // getting the values of the contained GET-parameters for (NameValuePair pair : queryParams) { if (pair.getName().equals("id")) { id = pair.getValue(); } } //get the corresponding poi bean for the given id PoiBean bean = poiBeanList.get(Integer.parseInt(id)); //start a new intent for displaying the content of the bean Intent intent = new Intent(this, PoiDetailActivity.class); intent.putExtra("POI_NAME", bean.getName()); intent.putExtra("POI_DESC", bean.getDescription()); this.startActivity(intent); return true; }