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

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

Introduction

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

Prototype

@Override
public UriComponentsBuilder pathSegment(String... pathSegments) throws IllegalArgumentException 

Source Link

Document

Append path segments to the existing path.

Usage

From source file:cherry.example.web.util.ViewNameUtil.java

public static String fromMethodCall(Object invocationInfo) {

    MethodInvocationInfo info = (MethodInvocationInfo) invocationInfo;
    Method method = info.getControllerMethod();
    Class<?> type = method.getDeclaringClass();

    UriComponentsBuilder ucb = UriComponentsBuilder.newInstance();
    String typePath = getMappedPath(type.getAnnotation(RequestMapping.class));
    if (StringUtils.isNotEmpty(typePath)) {
        ucb.path(typePath);//  ww w  .jav  a  2 s.  c om
    }

    String methodPath = getMappedPath(method.getAnnotation(RequestMapping.class));
    if (StringUtils.isNotEmpty(methodPath)) {
        ucb.pathSegment(methodPath);
    }

    String path = ucb.build().getPath();
    if (path.startsWith("/")) {
        return path.substring(1);
    }
    return path;
}

From source file:org.moserp.common.json_schema.factories.ValuePropertyJsonSchemaFactory.java

private String calculateValueListUri(PropertyFactoryContext context) {
    ValueListKey valueListValue = getAnnotation(context, ValueListKey.class);
    String valueListKey = valueListValue.value();
    final BaseUri baseUri = new BaseUri(
            "http://" + moduleRegistry.getModuleForResource("valueLists") + "/valueLists");
    UriComponentsBuilder builder = baseUri.getUriComponentsBuilder();
    return builder.pathSegment(valueListKey).pathSegment("values").build().toUriString();
}

From source file:com.wavemaker.tools.deployment.tomcat.TomcatManager.java

private String getUrl(String application, Command command) {
    if (!application.startsWith("/")) {
        application = "/" + application;
    }//  w  w w  .j  av  a  2s  .  c  om
    UriComponentsBuilder uri = newUriBuilder();
    uri.path(this.managerPath);
    uri.pathSegment(command.toString().toLowerCase());
    uri.queryParam("path", application);
    return uri.build().toUriString();
}

From source file:org.openmhealth.shim.misfit.MisfitShim.java

@Override
protected ResponseEntity<ShimDataResponse> getData(OAuth2RestOperations restTemplate,
        ShimDataRequest shimDataRequest) throws ShimException {

    final MisfitDataTypes misfitDataType;
    try {//from  w  ww .jav a 2  s.c  o  m
        misfitDataType = MisfitDataTypes.valueOf(shimDataRequest.getDataTypeKey().trim().toUpperCase());
    } catch (NullPointerException | IllegalArgumentException e) {
        throw new ShimException("Null or Invalid data type parameter: " + shimDataRequest.getDataTypeKey()
                + " in shimDataRequest, cannot retrieve data.");
    }

    // TODO don't truncate dates
    OffsetDateTime now = OffsetDateTime.now();

    OffsetDateTime startDateTime = shimDataRequest.getStartDateTime() == null ? now.minusDays(1)
            : shimDataRequest.getStartDateTime();

    OffsetDateTime endDateTime = shimDataRequest.getEndDateTime() == null ? now.plusDays(1)
            : shimDataRequest.getEndDateTime();

    if (Duration.between(startDateTime, endDateTime).toDays() > MAX_DURATION_IN_DAYS) {
        endDateTime = startDateTime.plusDays(MAX_DURATION_IN_DAYS - 1); // TODO when refactoring, break apart queries
    }

    UriComponentsBuilder uriBuilder = UriComponentsBuilder.fromUriString(DATA_URL);

    for (String pathSegment : Splitter.on("/").split(misfitDataType.getEndPoint())) {
        uriBuilder.pathSegment(pathSegment);
    }

    uriBuilder.queryParam("start_date", startDateTime.toLocalDate()) // TODO convert ODT to LocalDate properly
            .queryParam("end_date", endDateTime.toLocalDate()).queryParam("detail", true); // added to all endpoints to support summaries

    ResponseEntity<JsonNode> responseEntity;
    try {
        responseEntity = restTemplate.getForEntity(uriBuilder.build().encode().toUri(), JsonNode.class);
    } catch (HttpClientErrorException | HttpServerErrorException e) {
        // FIXME figure out how to handle this
        logger.error("A request for Misfit data failed.", e);
        throw e;
    }

    if (shimDataRequest.getNormalize()) {

        MisfitDataPointMapper<?> dataPointMapper;

        switch (misfitDataType) {
        case ACTIVITIES:
            dataPointMapper = physicalActivityMapper;
            break;
        case SLEEP:
            dataPointMapper = sleepDurationMapper;
            break;
        case STEPS:
            dataPointMapper = stepCountMapper;
            break;
        default:
            throw new UnsupportedOperationException();
        }

        return ok().body(ShimDataResponse.result(SHIM_KEY,
                dataPointMapper.asDataPoints(singletonList(responseEntity.getBody()))));
    } else {
        return ok().body(ShimDataResponse.result(SHIM_KEY, responseEntity.getBody()));
    }
}

From source file:org.zalando.boot.etcd.EtcdClient.java

/**
 * Returns the node with the given key from etcd.
 * //ww w . j a  v  a  2s  .  c  o  m
 * @param key
 *            the node's key
 * @return the response from etcd with the node
 * @throws EtcdException
 *             in case etcd returned an error
 */
public EtcdResponse get(String key) throws EtcdException {
    UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(KEYSPACE);
    builder.pathSegment(key);

    return execute(builder, HttpMethod.GET, null, EtcdResponse.class);
}

From source file:org.zalando.boot.etcd.EtcdClient.java

/**
 * Deletes the node with the given key from etcd.
 * //ww  w. j av a  2s  .c om
 * @param key
 *            the node's key
 * @return the response from etcd with the node
 * @throws EtcdException
 *             in case etcd returned an error
 */
public EtcdResponse delete(final String key) throws EtcdException {
    UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(KEYSPACE);
    builder.pathSegment(key);

    return execute(builder, HttpMethod.DELETE, null, EtcdResponse.class);
}

From source file:org.zalando.boot.etcd.EtcdClient.java

public EtcdResponse deleteDir(String key) throws EtcdException {
    UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(KEYSPACE);
    builder.pathSegment(key);
    builder.queryParam("dir", "true");

    return execute(builder, HttpMethod.DELETE, null, EtcdResponse.class);
}

From source file:org.zalando.boot.etcd.EtcdClient.java

public EtcdResponse deleteDir(String key, boolean recursive) throws EtcdException {
    UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(KEYSPACE);
    builder.pathSegment(key);
    builder.queryParam("recursive", recursive);

    return execute(builder, HttpMethod.DELETE, null, EtcdResponse.class);
}

From source file:org.zalando.boot.etcd.EtcdClient.java

/**
 * Returns the node with the given key from etcd.
 * /*from  w ww.  j  ava 2  s .c o  m*/
 * @param key
 *            the node's key
 * @param recursive
 *            <code>true</code> if child nodes should be returned,
 *            <code>false</code> otherwise
 * @return the response from etcd with the node
 * @throws EtcdException
 *             in case etcd returned an error
 */
public EtcdResponse get(String key, boolean recursive) throws EtcdException {
    UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(KEYSPACE);
    builder.pathSegment(key);
    builder.queryParam("recursive", recursive);

    return execute(builder, HttpMethod.GET, null, EtcdResponse.class);
}

From source file:org.zalando.boot.etcd.EtcdClient.java

/**
 * Atomically deletes a key-value pair in etcd.
 * /*from   w ww  .j  a v  a  2s .co  m*/
 * @param key
 *            the key
 * @param prevIndex
 *            the modified index of the key
 * @return the response from etcd with the node
 * @throws EtcdException
 *             in case etcd returned an error
 */
public EtcdResponse compareAndDelete(final String key, int prevIndex) throws EtcdException {
    UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(KEYSPACE);
    builder.pathSegment(key);
    builder.queryParam("prevIndex", prevIndex);

    return execute(builder, HttpMethod.DELETE, null, EtcdResponse.class);
}