use of org.springframework.web.util.UriComponents in project spring-integration by spring-projects.
the class AbstractWebServiceOutboundGateway method prepareUri.
private URI prepareUri(Message<?> requestMessage) throws URISyntaxException {
if (this.destinationProvider != null) {
return this.destinationProvider.getDestination();
}
Map<String, Object> uriVariables = ExpressionEvalMap.from(this.uriVariableExpressions).usingEvaluationContext(this.evaluationContext).withRoot(requestMessage).build();
UriComponents uriComponents = UriComponentsBuilder.fromUriString(this.uri).buildAndExpand(uriVariables);
return this.encodeUri ? uriComponents.toUri() : new URI(uriComponents.toUriString());
}
use of org.springframework.web.util.UriComponents in project easy-tests by malinink.
the class SwaggerRequestValidationService method buildRequest.
/**
* @param servletRequest the {@link HttpServletRequest}
* @return the build {@link Request} created out of given {@link HttpServletRequest}
* @throws IOException if the request body can't be read
*/
Request buildRequest(final HttpServletRequest servletRequest) throws IOException {
Objects.requireNonNull(servletRequest, "A request is required.");
final Request.Method method = Request.Method.valueOf(servletRequest.getMethod());
final String requestUri = getCompleteRequestUri(servletRequest);
final UriComponents uriComponents = UriComponentsBuilder.fromUriString(requestUri).build();
final String path = uriComponents.getPath();
final SimpleRequest.Builder builder = new SimpleRequest.Builder(method, path);
final String body = readReader(servletRequest.getReader());
// really empty.
if (servletRequest.getContentLength() >= 0 || (body != null && !body.isEmpty())) {
builder.withBody(body);
}
for (final Map.Entry<String, List<String>> entry : uriComponents.getQueryParams().entrySet()) {
builder.withQueryParam(entry.getKey(), entry.getValue());
}
for (final String headerName : Collections.list(servletRequest.getHeaderNames())) {
builder.withHeader(headerName, Collections.list(servletRequest.getHeaders(headerName)));
}
return builder.build();
}
use of org.springframework.web.util.UriComponents in project tutorials by eugenp.
the class SpringUriBuilderIntegrationTest method constructUriFromTemplate.
@Test
public void constructUriFromTemplate() {
UriComponents uriComponents = UriComponentsBuilder.newInstance().scheme("http").host("www.baeldung.com").path("/{article-name}").buildAndExpand("junit-5");
assertEquals("http://www.baeldung.com/junit-5", uriComponents.toUriString());
}
use of org.springframework.web.util.UriComponents in project tutorials by eugenp.
the class SpringUriBuilderIntegrationTest method constructUriWithQueryParameter.
@Test
public void constructUriWithQueryParameter() {
UriComponents uriComponents = UriComponentsBuilder.newInstance().scheme("http").host("www.google.com").path("/").query("q={keyword}").buildAndExpand("baeldung");
assertEquals("http://www.google.com/?q=baeldung", uriComponents.toUriString());
}
use of org.springframework.web.util.UriComponents 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;
}
Aggregations