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

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

Introduction

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

Prototype

@Override
public UriComponentsBuilder queryParam(String name, @Nullable Collection<?> values) 

Source Link

Document

Append the given query parameter to the existing query parameters.

Usage

From source file:com.codeabovelab.dm.cluman.cluster.registry.DockerRegistryAuthAdapter.java

private URI getPath(AuthInfo authInfo) throws URISyntaxException {
    UriComponentsBuilder builder = newInstance().uri(new URI(authInfo.getRealm())).queryParam("service",
            authInfo.getService());/*w  ww .  j a  v a 2  s  . c  o  m*/
    String scope = authInfo.getScope();
    if (StringUtils.hasText(scope)) {
        builder.queryParam("scope", scope);
    }
    return builder.build().toUri();
}

From source file:io.bosh.client.jobs.SpringJobs.java

private void buildChangeJobStateUri(String deployment, String job, Integer index, String newState,
        boolean skipDrain, UriComponentsBuilder builder) {
    builder.pathSegment("deployments", deployment, "jobs", job);
    if (index != null) {
        builder.pathSegment(String.valueOf(index));
    }//w  w w . j  a va  2 s  . com
    builder.queryParam("state", newState);
    if (skipDrain) {
        builder.queryParam("skip_drain", "true");
    }
}

From source file:org.appverse.web.framework.backend.test.util.oauth2.tests.predefined.implicit.Oauth2ImplicitFlowPredefinedTests.java

@Test
public void obtainTokenFromOuth2LoginEndpoint() throws Exception {
    UriComponentsBuilder builder = UriComponentsBuilder
            .fromHttpUrl(authServerBaseUrl + oauth2AuthorizeEndpointPath);
    builder.queryParam("username", getUsername());
    builder.queryParam("password", getPassword());
    builder.queryParam("client_id", getClientId());
    builder.queryParam("response_type", "token");
    builder.queryParam("redirect_uri", "http://anywhere");

    HttpEntity<String> entity = new HttpEntity<>("");
    ResponseEntity<String> result2 = restTemplate.exchange(builder.build().encode().toUri(), HttpMethod.POST,
            entity, String.class);

    // This means the user was correctly authenticated, then a redirection was performed to /oauth/authorize to obtain the token.
    // Then the token was sucessfully obtained (authenticating the client properly) and a last redirection was performed to the 
    // redirect_uri with the token after #
    assertEquals(HttpStatus.FOUND, result2.getStatusCode());

    // Obtain the token from redirection URL after #
    URI location = result2.getHeaders().getLocation();
    accessToken = extractToken(location.getFragment().toString());
    assertNotNull(accessToken);/* w ww . j  a  v  a  2 s  .c  o  m*/

    if (!isJwtTokenStore) {
        // Temporarily we can't not apply the default token enhacer adding the authorities if we use a JwtTokenStore
        // TODO: Put again the login endpoint separated for CSRF and return the authorities there

        // Obtain the user credentials from redirection URL after #
        String extractUserAuthorities = extractUserAuthorities(location.getFragment().toString());
        assertNotNull(extractUserAuthorities);
    }
}

From source file:org.appverse.web.framework.backend.test.util.oauth2.tests.predefined.implicit.Oauth2ImplicitFlowPredefinedTests.java

@Test
public void oauth2FlowTest() throws Exception {
    // Obtains the token
    obtainTokenFromOuth2LoginEndpoint();

    // Call remotelog        
    ResponseEntity<String> result = callRemoteLogWithAccessToken();
    assertEquals(HttpStatus.OK, result.getStatusCode());

    if (!isJwtTokenStore) {
        // The following code is executed only if the token store is not a JwtTokenStore. The reason is that using this kind of store
        // the tokens can't be revoked (they just expire) and so this part of the test would fail.
        // A JwtTokenStore is not a proper store as the tokens are not stored anywhere (as they contain all the required info about the user
        // themselves. That's why the token revocation is not possible.
        // We call logout endpoint (we need to use the access token for this)
        UriComponentsBuilder builder = UriComponentsBuilder
                .fromHttpUrl(authServerBaseUrl + baseApiPath + oauth2LogoutEndpointPath);
        builder.queryParam("access_token", accessToken);

        ResponseEntity<String> result2 = restTemplate.exchange(builder.build().encode().toUri(),
                HttpMethod.POST, null, String.class);
        assertEquals(HttpStatus.OK, result2.getStatusCode());

        // We try to call the protected API again (after having logged out which removes the token) - We expect not to be able to call the service.
        // This will throw a exception. In this case here in the test we receive an exception but really what happened was 'access denied'
        // A production client will receive the proper http error
        result = callRemoteLogWithAccessToken();
        assertEquals(HttpStatus.UNAUTHORIZED, result.getStatusCode());
    }// w  w w .jav a2  s  .  c o  m
}

From source file:com.art4ul.jcoon.context.RestClientContext.java

@Override
public URI buildUri() {
    if (baseUrl == null) {
        throw new InitializationException("@BaseUrl is not set.");
    }//from   w w  w  .  j  av  a2 s . c  o m
    UriComponentsBuilder componentsBuilder = UriComponentsBuilder.fromUriString(baseUrl + urlPath);

    if (httpParams != null) {
        //if (httpMethod == HttpMethod.GET) {
        for (String key : httpParams.keySet()) {
            componentsBuilder.queryParam(key, httpParams.get(key));
        }
        //}
    }
    return componentsBuilder.buildAndExpand(uriVariable).toUri();
}

From source file:com.playhaven.android.req.SubcontentRequest.java

@Override
protected UriComponentsBuilder createUrl(Context context) throws PlayHavenException {
    UriComponentsBuilder builder = super.createUrl(context);
    try {//from w  w  w .  j  a  v  a  2  s  .  com
        JSONObject addlParams = new JSONObject(mDispatchContext).getJSONObject("additional_parameters");
        Iterator<?> paramKeys = addlParams.keys();
        String key = null;
        while (paramKeys.hasNext()) {
            key = (String) paramKeys.next();
            builder.queryParam(key, addlParams.getString(key));
        }
    } catch (JSONException e) {
        // Hopefully the broken element won't be critical. 
        PlayHaven.e(e);
    }
    return builder;
}

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

@Override
public String execute() {
    String uri;//from  ww  w. jav a 2s .  co m
    UriComponentsBuilder uriBuilder;

    uri = getViewState().get(PromptDialogAction.VIEWSTATE_ACTIONURL);
    if (Strings.isNullOrEmpty(uri)) {
        throw new PropertyNotSetException(toString(), PromptDialogAction.VIEWSTATE_ACTIONURL);
    }

    uriBuilder = UriComponentsBuilder.fromHttpUrl(uri);
    uriBuilder.queryParam("closingDialogId", getViewState().get(ActionBase.VIEWSTATE_VIEWID));
    for (Map.Entry<String, String> param : getCallerState().entrySet()) {
        uriBuilder.queryParam(PromptDialogAction.VIEWSTATE_PREFIX.concat(param.getKey()), param.getValue());
    }

    myActionUrl = uriBuilder.build().toUriString();
    myLogger.info("User accepted action {}.", myActionUrl);

    return Action.SUCCESS;
}

From source file:org.appverse.web.framework.backend.test.util.oauth2.tests.predefined.authorizationcode.Oauth2AuthorizationCodeFlowPredefinedTests.java

@Test
public void obtainAuthorizationCode() throws Exception {
    UriComponentsBuilder builder = UriComponentsBuilder
            .fromHttpUrl(authServerBaseUrl + oauth2AuthorizeEndpointPath);
    builder.queryParam("username", getUsername());
    builder.queryParam("password", getPassword());
    builder.queryParam("client_id", getClientId());
    builder.queryParam("response_type", "code");
    builder.queryParam("redirect_uri", "http://anywhere");
    // builder.queryParam("realm","oauth2-resource");

    // optional builder.queryParam("scope", "");
    // recommended (optional) builder.queryParam("state", "");

    //HttpEntity<String> entity = new HttpEntity("",headers);
    HttpEntity<String> entity = new HttpEntity("");
    ResponseEntity<String> result2 = restTemplate.exchange(builder.build().encode().toUri(), HttpMethod.POST,
            entity, String.class);

    // check this! assertEquals(HttpStatus.FOUND, result2.getStatusCode());        

    // Obtain the token from redirection URL after #
    URI location = result2.getHeaders().getLocation();
    authorizationCode = extractAuthorizationCode(location.toString());
    assertNotNull(authorizationCode);/*from   w w  w.j  a  v  a2  s  . co  m*/
}

From source file:org.appverse.web.framework.backend.test.util.oauth2.tests.predefined.authorizationcode.Oauth2AuthorizationCodeFlowPredefinedTests.java

protected ResponseEntity<String> callRemoteLogWithAccessToken() {
    RemoteLogRequestVO remoteLogRequest = new RemoteLogRequestVO();
    remoteLogRequest.setLogLevel("DEBUG");
    remoteLogRequest.setMessage("This is my log message!");

    HttpEntity<RemoteLogRequestVO> entity = new HttpEntity<RemoteLogRequestVO>(remoteLogRequest);
    UriComponentsBuilder builder = UriComponentsBuilder
            .fromHttpUrl(resourceServerBaseUrl + baseApiPath + remoteLogEndpointPath);
    builder.queryParam("access_token", accessToken);

    ResponseEntity<String> result = restTemplate.exchange(builder.build().encode().toUri(), HttpMethod.POST,
            entity, String.class);
    return result;
}