Example usage for org.springframework.web.util UriComponentsBuilder fromHttpUrl

List of usage examples for org.springframework.web.util UriComponentsBuilder fromHttpUrl

Introduction

In this page you can find the example usage for org.springframework.web.util UriComponentsBuilder fromHttpUrl.

Prototype

public static UriComponentsBuilder fromHttpUrl(String httpUrl) 

Source Link

Document

Create a URI components builder from the given HTTP URL String.

Usage

From source file:ca.qhrtech.services.implementations.BGGServiceImpl.java

private URI buildUriForQuery(Game game) {
    UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(BASE_BGG_URL + END_POINT_SEARCH);
    builder.queryParam("query", game.getName());
    builder.queryParam("type", "boardgame");
    return builder.build().encode().toUri();
}

From source file:org.cloudfoundry.identity.uaa.login.feature.AutologinIT.java

@Test
public void testAutologinFlow() throws Exception {
    webDriver.get(baseUrl + "/logout.do");

    HttpHeaders headers = getAppBasicAuthHttpHeaders();

    Map<String, String> requestBody = new HashMap<>();
    requestBody.put("username", testAccounts.getUserName());
    requestBody.put("password", testAccounts.getPassword());

    ResponseEntity<Map> autologinResponseEntity = restOperations.exchange(baseUrl + "/autologin",
            HttpMethod.POST, new HttpEntity<>(requestBody, headers), Map.class);
    String autologinCode = (String) autologinResponseEntity.getBody().get("code");

    String authorizeUrl = UriComponentsBuilder.fromHttpUrl(baseUrl).path("/oauth/authorize")
            .queryParam("redirect_uri", appUrl).queryParam("response_type", "code")
            .queryParam("scope", "openid").queryParam("client_id", "app").queryParam("code", autologinCode)
            .build().toUriString();/*w w w.  j  a v  a 2s .co m*/

    webDriver.get(authorizeUrl);

    webDriver.get(baseUrl);

    assertEquals(testAccounts.getUserName(), webDriver.findElement(By.cssSelector(".header .nav")).getText());
}

From source file:springfox.documentation.spring.web.AbstractPathProvider.java

private UriComponentsBuilder agnosticUriComponentBuilder(String url) {
    UriComponentsBuilder uriComponentsBuilder;
    if (url.startsWith("http")) {
        uriComponentsBuilder = UriComponentsBuilder.fromHttpUrl(url);
    } else {/*from w  w  w  . ja  v  a2s  .  c o m*/
        uriComponentsBuilder = UriComponentsBuilder.fromPath(url);
    }
    return uriComponentsBuilder;
}

From source file:io.lavagna.web.security.HSTSFilter.java

private static void sendRedirectAbsolute(String baseApplicationUrl, HttpServletResponse resp, String page,
        Map<String, List<String>> params) throws IOException {
    UriComponents urlToRedirect = UriComponentsBuilder.fromHttpUrl(baseApplicationUrl).path(page)
            .queryParams(new LinkedMultiValueMap<>(params)).build();
    resp.sendRedirect(urlToRedirect.toUriString());
}

From source file:org.avidj.zuul.client.ZuulRestClient.java

@Override
public boolean lock(String sessionId, List<String> path, LockType type, LockScope scope) {
    RestTemplate restTemplate = new RestTemplate();

    HttpHeaders headers = new HttpHeaders();
    headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
    HttpEntity<String> entity = new HttpEntity<String>("parameters", headers);

    Map<String, String> parameters = new HashMap<>();
    parameters.put("id", sessionId); // set the session id
    UriComponentsBuilder uriBuilder = UriComponentsBuilder.fromHttpUrl(serviceUrl + lockPath(path))
            .queryParam("t", type(type)).queryParam("s", scope(scope));

    ResponseEntity<String> result = restTemplate.exchange(uriBuilder.build().encode().toUri(), HttpMethod.PUT,
            entity, String.class);

    LOG.info(result.toString());/*from   w  w  w.j a va  2  s  . c o  m*/
    HttpStatus code = result.getStatusCode();
    return code.equals(HttpStatus.CREATED);
}

From source file:fi.helsinki.opintoni.integration.leiki.LeikiRestClient.java

@Override
public List<LeikiCourseRecommendation> getCourseRecommendations(String studentNumber) {
    URI uri = UriComponentsBuilder.fromHttpUrl(baseUrl).path("/focus/api").queryParam("method", "getsocial")
            .queryParam("similaritylimit", "99").queryParam("format", "json").queryParam("t_type", "kurssit")
            .queryParam("max", maxRecommendations).queryParam("uid", recommendationUidPrefix + studentNumber)
            .queryParam("showtags", "true").queryParam("unreadonly", "true").build().encode().toUri();

    try {//from   w w  w .j av a 2 s . c o  m
        return getLeikiItemsData(uri,
                new ParameterizedTypeReference<LeikiResponse<LeikiCourseRecommendation>>() {
                });
    } catch (Exception e) {
        LOGGER.error("Caught exception when fetching Leiki course recommendations", e);
        return Lists.newArrayList();
    }
}

From source file:io.pivotal.cla.webdriver.AuthenticationTests.java

@Test
public void adminRequiresAuthenticationAndCreatesValidOAuthTokenRequest() throws Exception {
    String redirect = mockMvc.perform(get("/admin/cla/link")).andExpect(status().is3xxRedirection()).andReturn()
            .getResponse().getRedirectedUrl();

    UriComponents redirectComponent = UriComponentsBuilder.fromHttpUrl(redirect).build();

    assertThat(redirectComponent.getScheme()).isEqualTo("https");
    assertThat(redirectComponent.getHost()).isEqualTo("github.com");
    MultiValueMap<String, String> params = redirectComponent.getQueryParams();
    assertThat(params.getFirst("client_id")).isEqualTo(config.getMain().getClientId());
    assertThat(urlDecode(params.getFirst("redirect_uri"))).isEqualTo("http://localhost/login/oauth2/github");
    assertThat(params.getFirst("state")).isNotNull();

    String[] scopes = urlDecode(params.getFirst("scope")).split(",");
    assertThat(scopes).containsOnly("user:email", "repo:status", "admin:repo_hook", "admin:org_hook",
            "read:org");
}

From source file:com.greglturnquist.spring.social.ecobee.api.impl.ThermostatTemplate.java

@Override
public ThermostatSummary getThermostatSummary() {

    try {//from w w  w. j  a v a 2 s . c  om
        final Selection selection = Selection.allThermostats();
        final String selectionStr = this.jsonMessageConverter.getObjectMapper().writeValueAsString(selection);
        URI uri = UriComponentsBuilder.fromHttpUrl(buildUri("/thermostatSummary"))
                .queryParam("json", selectionStr).build().toUri();
        return this.restTemplate.getForObject(uri, ThermostatSummary.class);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:org.appverse.web.framework.backend.frontfacade.rest.MvcExceptionHandlerTests.java

@Test
public void testNotFound() throws Exception {
    // Login first
    TestLoginInfo loginInfo = login();//  w w w. j  av a2  s  . c  om
    HttpHeaders headers = new HttpHeaders();
    headers.set("Cookie", loginInfo.getJsessionid());
    HttpEntity<String> entity = new HttpEntity<String>(headers);

    // Calling protected resource - requires CSRF token
    UriComponentsBuilder builder = UriComponentsBuilder
            .fromHttpUrl("http://localhost:" + port + baseApiPath + "/badurl")
            .queryParam(DEFAULT_CSRF_PARAMETER_NAME, loginInfo.getXsrfToken());

    ResponseEntity<String> responseEntity = restTemplate.exchange(builder.build().encode().toUri(),
            HttpMethod.GET, entity, String.class);
    assertEquals(HttpStatus.NOT_FOUND, responseEntity.getStatusCode());
}

From source file:it.scoppelletti.wui.ActivityPanelAction.java

/**
 * Elenco delle attivit&agrave;.//w  w  w  .  j  ava 2s. c o m
 * 
 * @param  applList Applicazioni.
 * @return          Collezione.
 */
private List<Activity> listActivities(List<String> applList) {
    String uri;
    UriComponentsBuilder uriBuilder;
    ActivityListResource activityRes;
    List<Activity> activityList, list;

    activityList = new ArrayList<Activity>();
    for (String ctxPath : applList) {
        uriBuilder = UriComponentsBuilder.fromHttpUrl(myApplMgr.getBaseUrl());
        uriBuilder.path(ctxPath).path(ActivityListResource.PATH);
        uriBuilder.queryParam(AbstractServerResource.QUERY_LOCALE, getLocale().toString());
        if (!Strings.isNullOrEmpty(myCatgFilter)) {
            uriBuilder.queryParam(ActivityListResource.QUERY_CATEGORY, myCatgFilter);
        }

        uri = uriBuilder.build().toUriString();
        activityRes = ClientResource.create(uri, ActivityListResource.class);
        try {
            list = activityRes.listActivities();
        } catch (Exception ex) {
            myLogger.error(String.format("Failed to get %1$s.", uri), ex);
            continue;
        }
        if (list == null) {
            myLogger.error("Failed to get {}.", uri);
            continue;
        }

        activityList.addAll(list);
    }

    Collections.sort(activityList, new ActivityComparator());

    return activityList;
}