Search in sources :

Example 91 with UriComponentsBuilder

use of org.springframework.web.util.UriComponentsBuilder in project nakadi by zalando.

the class SubscriptionsUriHelper method createSubscriptionListUri.

public static String createSubscriptionListUri(final Optional<String> owningApplication, final Set<String> eventTypes, final int offset, final int limit) {
    final UriComponentsBuilder urlBuilder = UriComponentsBuilder.fromPath("/subscriptions");
    if (!eventTypes.isEmpty()) {
        urlBuilder.queryParam("event_type", eventTypes.toArray());
    }
    owningApplication.ifPresent(owningApp -> urlBuilder.queryParam("owning_application", owningApp));
    return urlBuilder.queryParam("offset", offset).queryParam("limit", limit).build().toString();
}
Also used : UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder)

Example 92 with UriComponentsBuilder

use of org.springframework.web.util.UriComponentsBuilder in project taskana by Taskana.

the class AbstractRessourcesAssembler method getBuilderForOriginalUri.

protected UriComponentsBuilder getBuilderForOriginalUri() {
    HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
    UriComponentsBuilder baseUri = ServletUriComponentsBuilder.fromServletMapping(request).path(request.getRequestURI());
    for (Map.Entry<String, String[]> entry : request.getParameterMap().entrySet()) {
        for (String value : entry.getValue()) {
            baseUri.queryParam(entry.getKey(), value);
        }
    }
    UriComponentsBuilder original = baseUri;
    return original;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletRequestAttributes(org.springframework.web.context.request.ServletRequestAttributes) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) ServletUriComponentsBuilder(org.springframework.web.servlet.support.ServletUriComponentsBuilder) Map(java.util.Map)

Example 93 with UriComponentsBuilder

use of org.springframework.web.util.UriComponentsBuilder in project taskana by Taskana.

the class WorkbasketSummaryResourcesAssembler method getBuilderForOriginalUri.

private UriComponentsBuilder getBuilderForOriginalUri() {
    HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
    UriComponentsBuilder baseUri = ServletUriComponentsBuilder.fromServletMapping(request).path(request.getRequestURI());
    for (Map.Entry<String, String[]> entry : request.getParameterMap().entrySet()) {
        for (String value : entry.getValue()) {
            baseUri.queryParam(entry.getKey(), value);
        }
    }
    UriComponentsBuilder original = baseUri;
    return original;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletRequestAttributes(org.springframework.web.context.request.ServletRequestAttributes) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) ServletUriComponentsBuilder(org.springframework.web.servlet.support.ServletUriComponentsBuilder) Map(java.util.Map)

Example 94 with UriComponentsBuilder

use of org.springframework.web.util.UriComponentsBuilder in project spring-cloud-netflix by spring-cloud.

the class LocationRewriteFilter method run.

@Override
public Object run() {
    RequestContext ctx = RequestContext.getCurrentContext();
    Route route = routeLocator.getMatchingRoute(urlPathHelper.getPathWithinApplication(ctx.getRequest()));
    if (route != null) {
        Pair<String, String> lh = locationHeader(ctx);
        if (lh != null) {
            String location = lh.second();
            URI originalRequestUri = UriComponentsBuilder.fromHttpRequest(new ServletServerHttpRequest(ctx.getRequest())).build().toUri();
            UriComponentsBuilder redirectedUriBuilder = UriComponentsBuilder.fromUriString(location);
            UriComponents redirectedUriComps = redirectedUriBuilder.build();
            String newPath = getRestoredPath(this.zuulProperties, route, redirectedUriComps);
            String modifiedLocation = redirectedUriBuilder.scheme(originalRequestUri.getScheme()).host(originalRequestUri.getHost()).port(originalRequestUri.getPort()).replacePath(newPath).build().toUriString();
            lh.setSecond(modifiedLocation);
        }
    }
    return null;
}
Also used : ServletServerHttpRequest(org.springframework.http.server.ServletServerHttpRequest) UriComponents(org.springframework.web.util.UriComponents) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) RequestContext(com.netflix.zuul.context.RequestContext) URI(java.net.URI) Route(org.springframework.cloud.netflix.zuul.filters.Route)

Example 95 with UriComponentsBuilder

use of org.springframework.web.util.UriComponentsBuilder in project ma-core-public by infiniteautomation.

the class PasswordResetService method generateResetUrl.

public URI generateResetUrl(String token) throws UnknownHostException {
    UriComponentsBuilder builder;
    String baseUrl = SystemSettingsDao.getValue(SystemSettingsDao.PUBLICLY_RESOLVABLE_BASE_URL);
    if (baseUrl != null) {
        builder = UriComponentsBuilder.fromPath(baseUrl);
    } else {
        boolean sslOn = Common.envProps.getBoolean("ssl.on", false);
        int port = sslOn ? Common.envProps.getInt("ssl.port", 443) : Common.envProps.getInt("web.port", 8080);
        builder = UriComponentsBuilder.newInstance().scheme(sslOn ? "https" : "http").host(InetAddress.getLocalHost().getHostName()).port(port);
    }
    String resetPage = DefaultPagesDefinition.getPasswordResetUri();
    return builder.path(resetPage).queryParam(PASSWORD_RESET_PAGE_TOKEN_PARAMETER, token).build().toUri();
}
Also used : UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder)

Aggregations

UriComponentsBuilder (org.springframework.web.util.UriComponentsBuilder)131 Test (org.junit.Test)34 UriComponents (org.springframework.web.util.UriComponents)23 ServletUriComponentsBuilder (org.springframework.web.servlet.support.ServletUriComponentsBuilder)12 URI (java.net.URI)9 Test (org.junit.jupiter.api.Test)9 SearchRequest (org.nzbhydra.searching.searchrequests.SearchRequest)8 MvcUriComponentsBuilder (org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder)8 ArrayList (java.util.ArrayList)7 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)7 List (java.util.List)6 User (com.serotonin.m2m2.vo.User)5 RestProcessResult (com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult)5 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)5 HashMap (java.util.HashMap)5 HttpEntity (org.springframework.http.HttpEntity)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 HttpClientErrorException (org.springframework.web.client.HttpClientErrorException)5 IOException (java.io.IOException)4 Map (java.util.Map)4