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:it.scoppelletti.wui.AboutAction.java

@Override
public String execute() {
    String uri;//from  ww w  .  j  a  v a  2s  . c o m
    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;
}

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

@Test
public void obtainTokenFromOuth2LoginEndpoint() throws Exception {
    obtainAuthorizationCode();/*from w  ww . j av  a  2  s  . c  o  m*/
    UriComponentsBuilder builder = UriComponentsBuilder
            .fromHttpUrl(authServerBaseUrl + oauth2TokenEndpointPath);
    // Here we don't authenticate the user, we authenticate the client and we pass the authcode proving that the user has accepted and loged in        
    builder.queryParam("client_id", getClientId());
    builder.queryParam("grant_type", "authorization_code");
    builder.queryParam("code", authorizationCode);
    builder.queryParam("redirect_uri", "http://anywhere");

    // Add Basic Authorization headers for CLIENT authentication (user was authenticated in previous request (authorization code)
    HttpHeaders headers = new HttpHeaders();
    Encoder encoder = Base64.getEncoder();
    headers.add("Authorization",
            "Basic " + encoder.encodeToString((getClientId() + ":" + getClientSecret()).getBytes()));

    HttpEntity<String> entity = new HttpEntity<>("", headers);
    ResponseEntity<OAuth2AccessToken> result2 = restTemplate.exchange(builder.build().encode().toUri(),
            HttpMethod.POST, entity, OAuth2AccessToken.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.OK, result2.getStatusCode());

    // Obtain and keep the token
    accessToken = result2.getBody().getValue();
    assertNotNull(accessToken);

    refreshToken = result2.getBody().getRefreshToken().getValue();
    assertNotNull(refreshToken);
}

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

/**
 * Elenco delle attivit&agrave;.//w  w  w .  ja  v a 2  s  .co 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;
}

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

/**
 * Elenco delle categorie.//from   w  w w . j  a v  a 2  s.  c om
 * 
 * @param  applList Applicazioni.
 * @return          Collezione.
 */
private List<String> listCategories(List<String> applList) {
    String uri;
    UriComponentsBuilder uriBuilder;
    ActivityCategoryListResource catgRes;
    List<String> categoryList, list;
    Map<String, String> map;

    map = new HashMap<String, String>();
    for (String ctxPath : applList) {
        uriBuilder = UriComponentsBuilder.fromHttpUrl(myApplMgr.getBaseUrl());
        uriBuilder.path(ctxPath).path(ActivityCategoryListResource.PATH);
        uriBuilder.queryParam(AbstractServerResource.QUERY_LOCALE, getLocale().toString());

        uri = uriBuilder.build().toUriString();
        catgRes = ClientResource.create(uri, ActivityCategoryListResource.class);
        try {
            list = catgRes.listCategories();
        } 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;
        }

        for (String catg : list) {
            addCategory(map, Strings.trim(catg));
        }
    }

    categoryList = new ArrayList<String>(map.values());
    Collections.sort(categoryList);

    return categoryList;
}

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

protected void addV3Signature(UriComponentsBuilder builder, SharedPreferences pref, String nonce)
        throws UnsupportedEncodingException, NoSuchAlgorithmException {
    builder.queryParam("signature", hexDigest(
            concat(":", getString(pref, Token), getString(pref, DeviceId), nonce, getString(pref, Secret))));
}

From source file:com.orange.ngsi2.client.Ngsi2Client.java

private void addPaginationParams(UriComponentsBuilder builder, int offset, int limit) {
    if (offset > 0) {
        builder.queryParam("offset", offset);
    }/*from   w  w  w.j  a  v  a 2s .c o  m*/
    if (limit > 0) {
        builder.queryParam("limit", limit);
    }
}

From source file:com.orange.ngsi2.client.Ngsi2Client.java

private void addParam(UriComponentsBuilder builder, String key, String value) {
    if (!nullOrEmpty(value)) {
        builder.queryParam(key, value);
    }/*from  w w w .j av  a 2s.c om*/
}

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

/**
 * Implementazione.//from w ww.  j a v  a  2  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:com.playhaven.android.req.PlayHavenRequest.java

@SuppressWarnings("deprecation")
protected UriComponentsBuilder createUrl(Context context) throws PlayHavenException {
    try {//from  w  ww . j av  a 2 s  .  c o m
        SharedPreferences pref = PlayHaven.getPreferences(context);

        UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(getString(pref, APIServer));
        builder.path(context.getResources().getString(getApiPath(context)));
        builder.queryParam("app", getString(pref, AppPkg));
        builder.queryParam("opt_out", getString(pref, OptOut, "0"));
        builder.queryParam("app_version", getString(pref, AppVersion));
        builder.queryParam("os", getInt(pref, OSVersion, 0));
        WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        Display display = wm.getDefaultDisplay();
        builder.queryParam("orientation", display.getRotation());
        builder.queryParam("hardware", getString(pref, DeviceModel));
        PlayHaven.ConnectionType connectionType = getConnectionType(context);
        builder.queryParam("connection", connectionType.ordinal());
        builder.queryParam("idiom",
                context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK);

        /**
         * For height/width we will use getSize(Point) not getRealSize(Point) as this will allow us to automatically
         * account for rotation and screen decorations like the status bar. We only want to know available space.
         *
         * @playhaven.apihack for SDK_INT < 13, have to use getHeight and getWidth!
         */
        Point size = new Point();
        if (Build.VERSION.SDK_INT >= 13) {
            display.getSize(size);
        } else {
            size.x = display.getWidth();
            size.y = display.getHeight();
        }
        builder.queryParam("width", size.x);
        builder.queryParam("height", size.y);

        /**
         * SDK Version needs to be reported as a dotted numeric value
         * So, if it is a -SNAPSHOT build, we will replace -SNAPSHOT with the date of the build
         * IE: 2.0.0.20130201
         * as opposed to an actual released build, which would be like 2.0.0
         */
        String sdkVersion = getString(pref, SDKVersion);
        String[] date = Version.PLUGIN_BUILD_TIME.split("[\\s]");
        sdkVersion = sdkVersion.replace("-SNAPSHOT", "." + date[0].replaceAll("-", ""));
        builder.queryParam("sdk_version", sdkVersion);

        builder.queryParam("plugin", getString(pref, PluginIdentifer));

        Locale locale = context.getResources().getConfiguration().locale;
        builder.queryParam("languages", String.format("%s,%s", locale.toString(), locale.getLanguage()));
        builder.queryParam("token", getString(pref, Token));

        builder.queryParam("device", getString(pref, DeviceId));
        DisplayMetrics metrics = new DisplayMetrics();
        display.getMetrics(metrics);
        builder.queryParam("dpi", metrics.densityDpi);

        String uuid = UUID.randomUUID().toString();
        String nonce = base64Digest(uuid);
        builder.queryParam("nonce", nonce);

        ktsid = KontagentUtil.getSenderId(context);
        if (ktsid != null)
            builder.queryParam("sid", ktsid);

        addSignature(builder, pref, nonce);

        // Setup for signature verification
        String secret = getString(pref, Secret);
        SecretKeySpec key = new SecretKeySpec(secret.getBytes(UTF8), HMAC);
        sigMac = Mac.getInstance(HMAC);
        sigMac.init(key);
        sigMac.update(nonce.getBytes(UTF8));

        return builder;
    } catch (Exception e) {
        throw new PlayHavenException(e);
    }
}