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:svc.data.citations.datasources.tyler.TylerCitationDataSource.java

@Override
public List<Citation> getByLicenseAndDOB(String driversLicenseNumber, String driversLicenseState,
        LocalDate dob) {/*w w  w .  ja va 2 s .  c  o m*/
    UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(tylerConfiguration.rootUrl)
            .queryParam("licenseNumber", driversLicenseNumber).queryParam("dob", dob.format(dobFormatter))
            .queryParam("licenseState", driversLicenseState);

    return performRestTemplateCall(builder.build().encode().toUri());
}

From source file:com.orange.clara.cloud.cf.servicebroker.log.domain.SplunkDashboardUrlFactoryTest.java

@Test
public void splunk_app_dashboard_url_path_should_be_flashtimeline() throws Exception {
    final SplunkDashboardUrlFactory urlFactory = new SplunkDashboardUrlFactory(LOG_SERVER_URL);

    final String appDashboardUri = urlFactory.getAppDashboardUrl("app_uid");

    Assertions.assertThat(UriComponentsBuilder.fromHttpUrl(appDashboardUri).build().toUri().getPath())
            .isEqualTo("/en-US/app/search/flashtimeline");
}

From source file:org.cloudfoundry.identity.uaa.login.test.IntegrationTestRule.java

private boolean connectionAvailable() {
    UriComponents components = UriComponentsBuilder.fromHttpUrl(baseUrl).build();
    String host = components.getHost();
    int port = components.getPort();

    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;
    }//  w w w  .  java2 s  .  co m
}

From source file:net.paslavsky.springrest.UriBuilder.java

private UriComponentsBuilder createOrAdd(UriComponentsBuilder builder, String path) {
    if (StringUtils.hasText(path)) {
        if (builder != null) {
            if (!path.startsWith("/")) {
                builder.path("/");
            }//from  w w  w . ja  v  a 2  s . com
            builder.path(path);
        } else {
            builder = UriComponentsBuilder.fromHttpUrl(path);
        }
    }
    return builder;
}

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

@Override
public List<LeikiSearchHit> search(String searchTerm, Locale locale) {
    URI uri = UriComponentsBuilder.fromHttpUrl(baseUrl).path("/focus/api").queryParam("method", "searchc")
            .query("sourceallmatch").query("instancesearch").queryParam("lang", locale.getLanguage())
            .queryParam("query", searchTerm).queryParam("format", "json")
            .queryParam("t_type", LeikiTType.getByLocale(locale).getValue()).queryParam("max", maxSearchResults)
            .queryParam("fulltext", "true").queryParam("partialsearchpriority", "ontology").build().encode()
            .toUri();//ww  w  .  j a va  2  s.c om

    return getLeikiItemsData(uri, new ParameterizedTypeReference<LeikiResponse<LeikiSearchHit>>() {
    });
}

From source file:id.co.teleanjar.ppobws.restclient.RestClientService.java

public Map<String, Object> inquiry(String idpel, String idloket, String merchantCode) throws IOException {
    String uri = "http://localhost:8080/ppobws/api/produk";
    RestTemplate restTemplate = new RestTemplate();

    HttpHeaders headers = createHeaders("superuser", "passwordku");
    UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(uri).queryParam("idpel", idpel)
            .queryParam("idloket", idloket).queryParam("merchantcode", merchantCode);
    HttpEntity<?> entity = new HttpEntity<>(headers);

    ResponseEntity<String> httpResp = restTemplate.exchange(builder.build().encode().toUri(), HttpMethod.GET,
            entity, String.class);
    String json = httpResp.getBody();
    LOGGER.info("JSON [{}]", json);
    LOGGER.info("STATUS [{}]", httpResp.getStatusCode().toString());

    Map<String, Object> map = new HashMap<>();
    ObjectMapper mapper = new ObjectMapper();

    map = mapper.readValue(json, new TypeReference<HashMap<String, Object>>() {
    });//  w w w. java 2 s  .  c o m
    return map;
}

From source file:org.trustedanalytics.servicebroker.hdfs.users.UaaClientTokenRetriver.java

public String getToken() {
    HttpHeaders headers = new HttpHeaders();
    headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
    headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);

    URI uaaUri = UriComponentsBuilder.fromHttpUrl(uaaConfiguration.getTokenUri())
            .queryParam(GRANT_TYPE, GRANT_TYPE_CREDENTIALS).queryParam(RESPONSE_TYPE, RESPONSE_TYPE_TOKEN)
            .build().encode().toUri();//from  ww  w .jav a 2s . c  o  m
    HttpEntity<String> entity = new HttpEntity<>(PARAMETERS, headers);
    return uaaRestTemplate.postForObject(uaaUri, entity, UaaTokenResponse.class).getAccessToken();
}

From source file:svc.data.citations.datasources.tyler.TylerCitationDataSource.java

@Override
public List<Citation> getByNameAndMunicipalitiesAndDOB(String lastName, List<Long> municipalities,
        LocalDate dob) {// w w w .  ja v  a2 s  .co  m
    UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(tylerConfiguration.rootUrl)
            .queryParam("lastName", lastName).queryParam("dob", dob.format(dobFormatter));

    return performRestTemplateCall(builder.build().encode().toUri());
}

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

@Override
public Thermostat getThermostat(String identifier) {

    try {/*from w w w  .  jav  a 2  s.  co  m*/
        final Selection selection = Selection.thermostats(identifier);
        selection.getSelection().setIncludeRuntime(true);
        selection.getSelection().setIncludeSettings(true);
        selection.getSelection().setIncludeSensors(true);
        final String selectionStr = this.jsonMessageConverter.getObjectMapper().writeValueAsString(selection);
        URI uri = UriComponentsBuilder.fromHttpUrl(buildUri("/thermostat")).queryParam("json", selectionStr)
                .build().toUri();
        return this.restTemplate.getForObject(uri, Thermostats.class).getThermostats().get(0);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

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

@Override
public String execute() {
    String uri;/* www  .  ja  v a 2  s  .com*/
    UriComponentsBuilder uriBuilder;
    ApplicationInfo about;
    ApplicationInfoResource aboutRes;
    List<String> applList;
    List<ApplicationInfo> aboutList;

    aboutList = new ArrayList<ApplicationInfo>();
    applList = myApplMgr.listRunningApplications();
    for (String ctxPath : applList) {
        uriBuilder = UriComponentsBuilder.fromHttpUrl(myApplMgr.getBaseUrl());
        uriBuilder.path(ctxPath).path(ApplicationInfoResource.PATH);
        uriBuilder.queryParam(AbstractServerResource.QUERY_LOCALE, getLocale().toString());

        uri = uriBuilder.build().toUriString();
        aboutRes = ClientResource.create(uri, ApplicationInfoResource.class);
        try {
            about = aboutRes.getApplicationInfo();
        } catch (Exception ex) {
            myLogger.error(String.format("Failed to get %1$s.", uri), ex);
            about = new SimpleApplicationInfo(ctxPath);
        }
        if (about == null) {
            myLogger.error("Failed to get {}.", uri);
            about = new SimpleApplicationInfo(ctxPath);
        }

        aboutList.add(about);
    }

    Collections.sort(aboutList, new ApplicationInfoComparator());
    myApplList = aboutList;

    return Action.SUCCESS;
}