List of usage examples for org.springframework.web.util UriComponentsBuilder fromHttpUrl
public static UriComponentsBuilder fromHttpUrl(String httpUrl)
From source file:com.orange.ngsi2.client.Ngsi2Client.java
/** * Discover registration matching entities and their attributes * @param bulkQueryRequest defines the list of entities, attributes and scopes to match registrations * @param offset an optional offset (0 for none) * @param limit an optional limit (0 for none) * @param count true to return the total number of matching entities * @return a paginated list of registration *///ww w.j a va 2s . c o m public ListenableFuture<Paginated<Registration>> bulkDiscover(BulkQueryRequest bulkQueryRequest, int offset, int limit, boolean count) { UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(baseURL); builder.path("v2/op/discover"); addPaginationParams(builder, offset, limit); if (count) { addParam(builder, "options", "count"); } return adaptPaginated( request(HttpMethod.POST, builder.toUriString(), bulkQueryRequest, Registration[].class), offset, limit); }
From source file:no.kantega.publishing.modules.linkcheck.check.LinkCheckerJob.java
private void checkRemoteUrl(String link, LinkOccurrence occurrence, CloseableHttpClient client) { log.debug("Checking remote url {}", link); HttpGet get;/*from w w w . j ava2 s.c om*/ try { URI uri = UriComponentsBuilder.fromHttpUrl(clean(link)).build().toUri(); get = new HttpGet(uri); } catch (Exception e) { occurrence.setStatus(CheckStatus.INVALID_URL); log.error("INVALID_URL " + link, e); return; } int httpStatus = -1; CheckStatus status = CheckStatus.OK; try (CloseableHttpResponse response = client.execute(get)) { log.debug("Checking remote url {}, before client.execute(get)", link); httpStatus = response.getStatusLine().getStatusCode(); log.debug("Checking remote url {}, after client.execute(get), status: {}", link, httpStatus); if (httpStatus != HttpStatus.SC_OK && httpStatus != HttpStatus.SC_UNAUTHORIZED && httpStatus != HttpStatus.SC_MULTIPLE_CHOICES && httpStatus != HttpStatus.SC_MOVED_TEMPORARILY && httpStatus != HttpStatus.SC_TEMPORARY_REDIRECT) { status = CheckStatus.HTTP_NOT_200; } } catch (UnknownHostException e) { status = CheckStatus.UNKNOWN_HOST; } catch (ConnectTimeoutException e) { status = CheckStatus.CONNECTION_TIMEOUT; } catch (ConnectException e) { log.debug("ConnectException when checking link " + link, e); status = CheckStatus.CONNECT_EXCEPTION; } catch (IOException e) { log.debug("IOException when checking link " + link, e); status = CheckStatus.IO_EXCEPTION; } catch (Exception e) { log.error("Error getting " + link, e); status = CheckStatus.INVALID_URL; } occurrence.setStatus(status); occurrence.setHttpStatus(httpStatus); }
From source file:org.apache.geode.management.internal.web.http.support.HttpRequester.java
/** * build the url using the path and query params * /*from w w w . j a va2 s . com*/ * @param path : the part after the baseUrl * @param queryParams this needs to be an even number of strings in the form of paramName, * paramValue.... */ public static URI createURI(String baseUrl, String path, String... queryParams) { UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(baseUrl).path(path); if (queryParams != null) { if (queryParams.length % 2 != 0) { throw new IllegalArgumentException("invalid queryParams count"); } for (int i = 0; i < queryParams.length; i += 2) { builder.queryParam(queryParams[i], queryParams[i + 1]); } } return builder.build().encode().toUri(); }
From source file:org.cloudfoundry.identity.client.integration.IsUAAListeningRule.java
private boolean connectionAvailable() { UriComponents components = UriComponentsBuilder.fromHttpUrl(baseUrl).build(); String host = components.getHost(); int port = components.getPort(); if (port == -1) { if (baseUrl.startsWith("https")) { port = 443;/*from w ww .java2 s.co m*/ } else { port = 80; } } logger.info("Testing connectivity for " + baseUrl); try (Socket socket = new Socket(host, port)) { logger.info("Connectivity test succeeded for " + baseUrl); return true; } catch (IOException e) { logger.warn("Connectivity test failed for " + baseUrl, e); return false; } }
From source file:org.cloudfoundry.identity.uaa.mock.token.TokenMvcMockTests.java
@Test public void testGetTokenScopesNotInAuthentication() throws Exception { String basicDigestHeaderValue = "Basic " + new String( org.apache.commons.codec.binary.Base64.encodeBase64(("identity:identitysecret").getBytes())); ScimUser user = setUpUser(generator.generate() + "@test.org"); String zoneadmingroup = "zones." + generator.generate() + ".admin"; ScimGroup group = new ScimGroup(null, zoneadmingroup, IdentityZone.getUaa().getId()); group = groupProvisioning.create(group); ScimGroupMember member = new ScimGroupMember(user.getId()); groupMembershipManager.addMember(group.getId(), member); MockHttpSession session = getAuthenticatedSession(user); String state = generator.generate(); MockHttpServletRequestBuilder authRequest = get("/oauth/authorize") .header("Authorization", basicDigestHeaderValue).header("Accept", MediaType.APPLICATION_JSON_VALUE) .session(session).param(OAuth2Utils.GRANT_TYPE, "authorization_code") .param(OAuth2Utils.RESPONSE_TYPE, "code").param(OAuth2Utils.STATE, state) .param(OAuth2Utils.CLIENT_ID, "identity").param(OAuth2Utils.REDIRECT_URI, "http://localhost/test"); MvcResult result = getMockMvc().perform(authRequest).andExpect(status().is3xxRedirection()).andReturn(); String location = result.getResponse().getHeader("Location"); UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(location); String code = builder.build().getQueryParams().get("code").get(0); authRequest = post("/oauth/token").header("Authorization", basicDigestHeaderValue) .header("Accept", MediaType.APPLICATION_JSON_VALUE) .param(OAuth2Utils.GRANT_TYPE, "authorization_code").param(OAuth2Utils.RESPONSE_TYPE, "token") .param("code", code).param(OAuth2Utils.CLIENT_ID, "identity") .param(OAuth2Utils.REDIRECT_URI, "http://localhost/test"); result = getMockMvc().perform(authRequest).andExpect(status().is2xxSuccessful()).andReturn(); OAuthToken oauthToken = JsonUtils.readValue(result.getResponse().getContentAsString(), OAuthToken.class); OAuth2Authentication a1 = tokenServices.loadAuthentication(oauthToken.accessToken); assertEquals(4, a1.getOAuth2Request().getScope().size()); assertThat(a1.getOAuth2Request().getScope(), containsInAnyOrder( new String[] { zoneadmingroup, "openid", "cloud_controller.read", "cloud_controller.write" })); }
From source file:org.cloudfoundry.identity.uaa.mock.util.MockMvcUtils.java
public static String getUserOAuthAccessTokenAuthCode(MockMvc mockMvc, String clientId, String clientSecret, String userId, String username, String password, String scope) throws Exception { String basicDigestHeaderValue = "Basic " + new String( org.apache.commons.codec.binary.Base64.encodeBase64((clientId + ":" + clientSecret).getBytes())); UaaPrincipal p = new UaaPrincipal(userId, username, "test@test.org", OriginKeys.UAA, "", IdentityZoneHolder.get().getId()); UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken(p, "", UaaAuthority.USER_AUTHORITIES); Assert.assertTrue(auth.isAuthenticated()); SecurityContextHolder.getContext().setAuthentication(auth); MockHttpSession session = new MockHttpSession(); session.setAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY, new MockSecurityContext(auth)); String state = new RandomValueStringGenerator().generate(); MockHttpServletRequestBuilder authRequest = get("/oauth/authorize") .header("Authorization", basicDigestHeaderValue).header("Accept", MediaType.APPLICATION_JSON_VALUE) .session(session).param(OAuth2Utils.GRANT_TYPE, "authorization_code") .param(OAuth2Utils.RESPONSE_TYPE, "code") .param(TokenConstants.REQUEST_TOKEN_FORMAT, TokenConstants.OPAQUE).param(OAuth2Utils.STATE, state) .param(OAuth2Utils.CLIENT_ID, clientId).param(OAuth2Utils.REDIRECT_URI, "http://localhost/test"); if (StringUtils.hasText(scope)) { authRequest.param(OAuth2Utils.SCOPE, scope); }//from w w w .j av a 2 s .com MvcResult result = mockMvc.perform(authRequest).andExpect(status().is3xxRedirection()).andReturn(); String location = result.getResponse().getHeader("Location"); UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(location); String code = builder.build().getQueryParams().get("code").get(0); authRequest = post("/oauth/token").header("Authorization", basicDigestHeaderValue) .header("Accept", MediaType.APPLICATION_JSON_VALUE) .param(OAuth2Utils.GRANT_TYPE, "authorization_code").param(OAuth2Utils.RESPONSE_TYPE, "token") .param("code", code).param(OAuth2Utils.CLIENT_ID, clientId) .param(OAuth2Utils.REDIRECT_URI, "http://localhost/test"); if (StringUtils.hasText(scope)) { authRequest.param(OAuth2Utils.SCOPE, scope); } result = mockMvc.perform(authRequest).andExpect(status().is2xxSuccessful()).andReturn(); InjectedMockContextTest.OAuthToken oauthToken = JsonUtils .readValue(result.getResponse().getContentAsString(), InjectedMockContextTest.OAuthToken.class); return oauthToken.accessToken; }
From source file:org.project.openbaton.nubomedia.paas.core.openshift.AuthenticationManager.java
public String authenticate(String baseURL, String username, String password) throws UnauthorizedException { String res = ""; String authBase = username + ":" + password; String authHeader = "Basic " + Base64.encodeBase64String(authBase.getBytes()); logger.debug("Auth header " + authHeader); String url = baseURL + suffix; HttpHeaders authHeaders = new HttpHeaders(); authHeaders.add("Authorization", authHeader); authHeaders.add("X-CSRF-Token", "1"); UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(url) .queryParam("client_id", "openshift-challenging-client").queryParam("response_type", "token"); HttpEntity<String> authEntity = new HttpEntity<>(authHeaders); ResponseEntity<String> response = null; try {/*from w w w .j av a2 s. c o m*/ response = template.exchange(builder.build().encode().toUriString(), HttpMethod.GET, authEntity, String.class); } catch (ResourceAccessException e) { return "PaaS Missing"; } catch (HttpClientErrorException e) { throw new UnauthorizedException("Username: " + username + " password: " + password + " are invalid"); } logger.debug("Response " + response.toString()); if (response.getStatusCode().equals(HttpStatus.FOUND)) { URI location = response.getHeaders().getLocation(); logger.debug("Location " + location); res = this.getToken(location.toString()); } else if (response.getStatusCode().equals(HttpStatus.UNAUTHORIZED)) { throw new UnauthorizedException("Username: " + username + " password: " + password + " are invalid"); } return res; }
From source file:org.rippleosi.common.service.AbstractEtherCISService.java
private String getQueryURI(String query) { query = encodeParameter(query);/* w w w . j a v a 2 s . c o m*/ return UriComponentsBuilder.fromHttpUrl(etherCISAddress + "/query").queryParam("sql", query).build() .toUriString(); }
From source file:org.rippleosi.common.service.AbstractEtherCISService.java
private String getCreateURI(String template, String ehrId) { template = encodeParameter(template); return UriComponentsBuilder.fromHttpUrl(etherCISAddress + "/composition").queryParam("templateId", template) .queryParam("ehrId", ehrId).queryParam("format", "FLAT").build().toUriString(); }
From source file:org.rippleosi.common.service.AbstractEtherCISService.java
private String getUpdateURI(String compositionId, String template, String ehrId) { template = encodeParameter(template); return UriComponentsBuilder.fromHttpUrl(etherCISAddress + "/composition").queryParam("uid", compositionId) .queryParam("templateId", template).queryParam("ehrId", ehrId).queryParam("format", "FLAT").build() .toUriString();/*from w w w.j a v a 2 s . c om*/ }