List of usage examples for java.net URI getQuery
public String getQuery()
From source file:org.kotemaru.browser.ActionBrowserFrame.java
/** * ?//from ww w . ja va2 s .c om * <li>BeanUtils ?? * <li>????? * <li>? UTF8 ? * @param uri Action URI * @param action Action */ protected void copyQuery(URI uri, Action action) throws Exception { String query = uri.getQuery(); if (query == null) return; String[] params = query.split("&"); for (int i = 0; i < params.length; i++) { String[] kv = params[i].split("="); String key = kv[0]; if (kv.length == 2) { String val = URLDecoder.decode(kv[1], "UTF-8"); BeanUtils.setProperty(action, key, val); } else if (params[i].indexOf('=') >= 0) { BeanUtils.setProperty(action, key, ""); } } }
From source file:org.openlmis.fulfillment.service.request.RequestHelperTest.java
@Test public void shouldCreateUriWithNullParameters() throws Exception { URI uri = RequestHelper.createUri(URL); assertThat(uri.getQuery(), is(nullValue())); }
From source file:gate.tagger.tagme.TaggerTagMeWS.java
public static String recodeForDbp38(String uriString) { String ret;/*w w w . j a va 2s.co m*/ URI uri = null; if (uriString.startsWith("http://") || uriString.startsWith("https://")) { // First try to parse the string as an URI so that any superfluous // percent-encodings can get decoded later try { uri = new URI(uriString); } catch (Exception ex) { throw new GateRuntimeException("Could not parse URI " + uriString, ex); } // now use this constructor to-recode only the necessary parts try { String path = uri.getPath(); path = path.trim(); path = path.replaceAll(" +", "_"); uri = new URI(uri.getScheme(), null, uri.getHost(), -1, path, uri.getQuery(), uri.getFragment()); } catch (Exception ex) { throw new GateRuntimeException("Could not re-construct URI: " + uri); } ret = uri.toString(); } else { if (uriString.contains("\\u")) { uriString = StringEscapeUtils.unescapeJava(uriString); } uriString = uriString.trim(); uriString = uriString.replaceAll(" +", "_"); // We need to %-encode colons, otherwise the getPath() method will return // null ... uriString = uriString.replaceAll(":", "%3A"); try { uri = new URI(uriString); // decode and prepare for minimal percent encoding uriString = uri.getPath(); } catch (URISyntaxException ex) { // do nothing: the uriString must already be ready for percent-encoding } uriString = uriString.replaceAll(" +", "_"); try { uri = new URI(null, null, null, -1, "/" + uriString, null, null); } catch (Exception ex) { throw new GateRuntimeException("Could not re-construct URI part: " + uriString); } ret = uri.toString().substring(1); } return ret; }
From source file:com.blogspot.sgdev.blog.GrantByAuthorizationCodeProviderTest.java
@Test public void getJwtTokenByAuthorizationCode() throws JsonParseException, JsonMappingException, IOException, URISyntaxException { String redirectUrl = "http://localhost:" + port + "/resources/user"; ResponseEntity<String> response = new TestRestTemplate("user", "password").postForEntity( "http://localhost:" + port + "/oauth/authorize?response_type=code&client_id=normal-app&redirect_uri={redirectUrl}", null, String.class, redirectUrl); assertEquals(HttpStatus.OK, response.getStatusCode()); List<String> setCookie = response.getHeaders().get("Set-Cookie"); String jSessionIdCookie = setCookie.get(0); String cookieValue = jSessionIdCookie.split(";")[0]; HttpHeaders headers = new HttpHeaders(); headers.add("Cookie", cookieValue); response = new TestRestTemplate("user", "password").postForEntity("http://localhost:" + port + "oauth/authorize?response_type=code&client_id=normal-app&redirect_uri={redirectUrl}&user_oauth_approval=true&authorize=Authorize", new HttpEntity<Void>(headers), String.class, redirectUrl); assertEquals(HttpStatus.FOUND, response.getStatusCode()); assertNull(response.getBody());/* ww w . j a va 2 s . com*/ String location = response.getHeaders().get("Location").get(0); URI locationURI = new URI(location); String query = locationURI.getQuery(); location = "http://localhost:" + port + "/oauth/token?" + query + "&grant_type=authorization_code&client_id=normal-app&redirect_uri={redirectUrl}"; response = new TestRestTemplate("normal-app", "").postForEntity(location, new HttpEntity<Void>(new HttpHeaders()), String.class, redirectUrl); assertEquals(HttpStatus.OK, response.getStatusCode()); HashMap jwtMap = new ObjectMapper().readValue(response.getBody(), HashMap.class); String accessToken = (String) jwtMap.get("access_token"); headers = new HttpHeaders(); headers.set("Authorization", "Bearer " + accessToken); response = new TestRestTemplate().exchange("http://localhost:" + port + "/resources/client", HttpMethod.GET, new HttpEntity<String>(null, headers), String.class); assertEquals(HttpStatus.FORBIDDEN, response.getStatusCode()); response = new TestRestTemplate().exchange("http://localhost:" + port + "/resources/user", HttpMethod.GET, new HttpEntity<String>(null, headers), String.class); assertEquals(HttpStatus.OK, response.getStatusCode()); response = new TestRestTemplate().exchange("http://localhost:" + port + "/resources/principal", HttpMethod.GET, new HttpEntity<String>(null, headers), String.class); assertEquals("user", response.getBody()); response = new TestRestTemplate().exchange("http://localhost:" + port + "/resources/roles", HttpMethod.GET, new HttpEntity<String>(null, headers), String.class); assertEquals("[{\"authority\":\"ROLE_USER\"}]", response.getBody()); }
From source file:org.opennms.netmgt.collectd.HttpCollector.java
private static HttpGet buildGetMethod(final URI uri, final HttpCollectionSet collectionSet) { URI uriWithQueryString = null; List<NameValuePair> queryParams = buildRequestParameters(collectionSet); try {//from w w w. j a va 2s.c om StringBuffer query = new StringBuffer(); query.append(URLEncodedUtils.format(queryParams, "UTF-8")); if (uri.getQuery() != null && !uri.getQuery().trim().isEmpty()) { if (query.length() > 0) { query.append("&"); } query.append(uri.getQuery()); } final URIBuilder ub = new URIBuilder(uri); if (query.length() > 0) { final List<NameValuePair> params = URLEncodedUtils.parse(query.toString(), Charset.forName("UTF-8")); if (!params.isEmpty()) { ub.setParameters(params); } } uriWithQueryString = ub.build(); return new HttpGet(uriWithQueryString); } catch (URISyntaxException e) { LOG.warn(e.getMessage(), e); return new HttpGet(uri); } }
From source file:nu.yona.server.DOSProtectionService.java
private String getKey(URI uri, HttpServletRequest request) { String key = request.getRemoteAddr() + "@" + uri.getPath(); String query = uri.getQuery(); if (query != null) { key += query;//from w w w. j av a2s . c o m } return key; }
From source file:com.eviware.soapui.impl.rest.actions.oauth.OltuOAuth2ClientFacade.java
private void appendAccessTokenToQuery(HttpRequestBase request, OAuthBearerClientRequest oAuthClientRequest) throws OAuthSystemException { String queryString = getQueryStringFromOAuthClientRequest(oAuthClientRequest); URI oldUri = request.getURI(); String requestQueryString = oldUri.getQuery() != null ? oldUri.getQuery() + "&" + queryString : queryString; try {//from w w w . ja va2 s. c o m request.setURI(URIUtils.createURI(oldUri.getScheme(), oldUri.getHost(), oldUri.getPort(), oldUri.getRawPath(), requestQueryString, oldUri.getFragment())); } catch (URISyntaxException e) { throw new OAuthSystemException(e); } }
From source file:com.vmware.thinapp.common.util.AfUtil.java
/** * Checks whether the given URL string begins with a protocol (http://, * ftp://, etc.) If it does, the string is returned unchanged. If it does * not, full URL is returned and is constructed as parentUrl "/" url. * * @param url input URL string in absolute or relative form * @param parentUrl base URL to use if the given URL is in relative form * @return an absolute URL/*from w ww . j a v a2 s . com*/ */ public static URI relToAbs(String url, URI parentUrl) throws URISyntaxException { if (!StringUtils.hasLength(url)) { throw new URISyntaxException(url, "The input url was empty!"); } URI parent2 = new URI(parentUrl.getScheme(), parentUrl.getUserInfo(), parentUrl.getAuthority(), parentUrl.getPort(), parentUrl.getPath() + "/", // Parent URL path must end with "/" for // this to work. resolve() removes any // duplicates. parentUrl.getQuery(), parentUrl.getFragment()); return parent2.resolve(url.trim()); }
From source file:org.apache.hadoop.gateway.hbase.HBaseCookieManager.java
protected HttpRequest createKerberosAuthenticationRequest(HttpUriRequest userRequest) { URI userUri = userRequest.getURI(); try {/*from w ww . j av a 2s.c o m*/ URI authUri = new URI(userUri.getScheme(), null, userUri.getHost(), userUri.getPort(), "/version", userUri.getQuery(), null); HttpRequest authRequest = new HttpGet(authUri); return authRequest; } catch (URISyntaxException e) { throw new IllegalArgumentException(userUri.toString(), e); } }
From source file:org.openlmis.fulfillment.service.request.RequestHelperTest.java
@Test public void shouldCreateUriWithoutParameters() throws Exception { URI uri = RequestHelper.createUri(URL, RequestParameters.init()); assertThat(uri.getQuery(), is(nullValue())); }