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:de.appsolve.padelcampus.external.cloudflare.CloudFlareApiClient.java

private String getDnsEntriesUrl(String zoneId, String recordType, String recordName) {
    UriComponentsBuilder builder = UriComponentsBuilder
            .fromHttpUrl(CLOUDFLARE_API_URL + "zones/" + zoneId + "/dns_records");
    if (!StringUtils.isEmpty(recordType)) {
        builder.queryParam("type", recordType);
    }/*from  w  w w .j  a  v a2s  .com*/
    if (!StringUtils.isEmpty(recordName)) {
        builder.queryParam("name", recordName);
    }
    return builder.toUriString();
}

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

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

    final String appDashboardUri = urlFactory.getAllAppsDashboardUrl();

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

From source file:fi.helsinki.opintoni.integration.flamma.FlammaRestClient.java

private String getFeedUri(String pathSegment) {
    return UriComponentsBuilder.fromHttpUrl(baseUrl).path("infotaulu").pathSegment(pathSegment).toUriString();
}

From source file:de.blizzy.documentr.markdown.macro.impl.FlattrMacro.java

@Override
public String getHtml(IMacroContext macroContext) {
    try {/* w w w.j  a  v  a2 s . co  m*/
        IMacroSettings settings = macroContext.getSettings();
        String userId = settings.getSetting("userId"); //$NON-NLS-1$
        if (StringUtils.isNotBlank(userId)) {
            HtmlSerializerContext htmlSerializerContext = macroContext.getHtmlSerializerContext();
            String projectName = htmlSerializerContext.getProjectName();
            String branchName = htmlSerializerContext.getBranchName();
            String path = htmlSerializerContext.getPagePath();
            String pageUri = htmlSerializerContext.getPageUri(path);
            String pageUrl = htmlSerializerContext.getUrl(pageUri);
            IPageStore pageStore = htmlSerializerContext.getPageStore();
            Page page = pageStore.getPage(projectName, branchName, path, false);
            String title = page.getTitle();
            String tags = StringUtils.join(page.getTags(), ","); //$NON-NLS-1$
            // http://developers.flattr.net/auto-submit/
            UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("https://flattr.com/submit/auto") //$NON-NLS-1$
                    .queryParam("user_id", userId) //$NON-NLS-1$
                    .queryParam("url", pageUrl) //$NON-NLS-1$
                    .queryParam("title", title) //$NON-NLS-1$
                    .queryParam("category", "text"); //$NON-NLS-1$ //$NON-NLS-2$
            if (StringUtils.isNotBlank(tags)) {
                builder.queryParam("tags", tags); //$NON-NLS-1$
            }
            String url = builder.build().encode(Charsets.UTF_8.name()).toUriString();
            return "<a href=\"" + StringEscapeUtils.escapeHtml4(url) + "\">" + //$NON-NLS-1$ //$NON-NLS-2$
                    "<img src=\"https://api.flattr.com/button/flattr-badge-large.png\"/></a>"; //$NON-NLS-1$
        }
    } catch (IOException e) {
        log.warn("error while rendering Flattr macro", e); //$NON-NLS-1$
    }
    return null;
}

From source file:com.jvoid.core.controller.HomeController.java

@RequestMapping(value = "/login", method = RequestMethod.POST)
public @ResponseBody String loginToJvoid(
        @RequestParam(required = false, value = "params") JSONObject jsonParams) {
    System.out.println("Login:jsonParams=>" + jsonParams.toString());

    RestTemplate restTemplate = new RestTemplate();
    HttpHeaders headers = new HttpHeaders();
    headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
    UriComponentsBuilder builder = UriComponentsBuilder
            .fromHttpUrl(ServerUris.CUSTOMER_SERVER_URI + URIConstants.GET_CUSTOMER_BY_EMAIL)
            .queryParam("params", jsonParams);
    HttpEntity<?> entity = new HttpEntity<>(headers);
    HttpEntity<String> returnString = restTemplate.exchange(builder.build().toUri(), HttpMethod.GET, entity,
            String.class);
    return returnString.getBody();
}

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

/**
 * Implementazione.//from  w  w w  . j  a  va2  s  . co  m
 */
@Override
public void doTag() throws IOException, JspException {
    URI uri;
    UriComponentsBuilder uriBuilder;
    WebApplicationManager applMgr;
    List<String> applList;
    ApplicationContext applCtx;
    PageContext pageCtx = (PageContext) getJspContext();

    applCtx = WebApplicationContextUtils.getRequiredWebApplicationContext(pageCtx.getServletContext());

    applMgr = applCtx.getBean(WebApplicationManager.BEAN_NAME, WebApplicationManager.class);
    applList = applMgr.listRunningApplications();

    for (String ctxPath : applList) {
        uriBuilder = UriComponentsBuilder.fromHttpUrl(applMgr.getBaseUrl());
        uriBuilder.path(ctxPath).path(HeadTag.HEAD_PATH);
        uriBuilder.queryParam(AbstractServerResource.QUERY_LOCALE, pageCtx.getRequest().getLocale().toString());
        uri = uriBuilder.build().toUri();

        try {
            head(uri, pageCtx.getOut());
        } catch (Exception ex) {
            myLogger.error(String.format("Failed to get %1$s.", uri), ex);
        }
    }
}

From source file:org.jasig.cas.web.flow.FrontChannelLogoutAction.java

@Override
protected Event doInternalExecute(final HttpServletRequest request, final HttpServletResponse response,
        final RequestContext context) throws Exception {

    final List<LogoutRequest> logoutRequests = WebUtils.getLogoutRequests(context);
    final Integer startIndex = getLogoutIndex(context);
    if (logoutRequests != null && startIndex != null) {
        for (int i = startIndex; i < logoutRequests.size(); i++) {
            final LogoutRequest logoutRequest = logoutRequests.get(i);
            if (logoutRequest.getStatus() == LogoutRequestStatus.NOT_ATTEMPTED) {
                // assume it has been successful
                logoutRequest.setStatus(LogoutRequestStatus.SUCCESS);

                // save updated index
                putLogoutIndex(context, i + 1);

                // redirect to application with SAML logout message
                final UriComponentsBuilder builder = UriComponentsBuilder
                        .fromHttpUrl(logoutRequest.getService().getId());
                builder.queryParam("SAMLRequest", URLEncoder
                        .encode(logoutManager.createFrontChannelLogoutMessage(logoutRequest), "UTF-8"));
                return result(REDIRECT_APP_EVENT, "logoutUrl", builder.build().toUriString());
            }//from  w w w  . ja v  a  2s  .  com
        }
    }

    // no new service with front-channel logout -> finish logout
    return new Event(this, FINISH_EVENT);
}

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

@Test
public void requiresAuthenticationAndCreatesValidOAuthTokenRequest() throws Exception {
    String redirect = mockMvc.perform(get("/sign/pivotal")).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");
}

From source file:com.tce.oauth2.spring.client.controller.OAuthController.java

@RequestMapping("/oauth2callback")
public String callback(@RequestParam("code") String authorizationCode, HttpServletRequest request) {

    // call OAuth Server with response code to get the access token
    UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(OAUTH_URL + "/oauth/token")
            .queryParam("grant_type", "authorization_code").queryParam("code", authorizationCode)
            .queryParam("redirect_uri", OAUTH_REDIRECT_URI);
    ResponseEntity<OAuthToken> response = restTemplate.exchange(builder.build().encode().toUri(),
            HttpMethod.POST, new HttpEntity<>(createHeaders(OAUTH_CLIENT_ID, OAUTH_CLIENT_SECRET)),
            OAuthToken.class);
    if (response.getStatusCode().is4xxClientError()) {
        return "redirect:/login";
    }/*from   w ww .  j a  v  a 2s.  c om*/

    // get the access token
    OAuthToken oauthToken = response.getBody();
    // set access token to the session
    request.getSession().setAttribute("access_token", oauthToken.getAccessToken());
    // get the user information
    return "redirect:/userinfo";
}

From source file:org.obiba.mica.user.UserProfileService.java

public String getUserProfileTranslations(String locale) {

    String serviceUrl = UriComponentsBuilder.fromHttpUrl(getAgateUrl()).path(DEFAULT_REST_PREFIX)
            .path("/users/i18n/" + locale + ".json").build().toUriString();

    return executeQuery(serviceUrl, String.class);
}