Example usage for org.springframework.http.server.reactive ServerHttpRequest getURI

List of usage examples for org.springframework.http.server.reactive ServerHttpRequest getURI

Introduction

In this page you can find the example usage for org.springframework.http.server.reactive ServerHttpRequest getURI.

Prototype

URI getURI();

Source Link

Document

Return the URI of the request (including a query string if any, but only if it is well-formed for a URI representation).

Usage

From source file:org.springframework.cloud.gateway.filter.factory.PrefixPathGatewayFilterFactory.java

@Override
public GatewayFilter apply(Config config) {
    return (exchange, chain) -> {

        boolean alreadyPrefixed = exchange.getAttributeOrDefault(GATEWAY_ALREADY_PREFIXED_ATTR, false);
        if (alreadyPrefixed) {
            return chain.filter(exchange);
        }//from w w  w  .  j  a  v  a 2  s. c  om
        exchange.getAttributes().put(GATEWAY_ALREADY_PREFIXED_ATTR, true);

        ServerHttpRequest req = exchange.getRequest();
        addOriginalRequestUrl(exchange, req.getURI());
        String newPath = config.prefix + req.getURI().getRawPath();

        ServerHttpRequest request = req.mutate().path(newPath).build();

        exchange.getAttributes().put(GATEWAY_REQUEST_URL_ATTR, request.getURI());

        if (log.isTraceEnabled()) {
            log.trace("Prefixed URI with: " + config.prefix + " -> " + request.getURI());
        }

        return chain.filter(exchange.mutate().request(request).build());
    };
}

From source file:org.springframework.security.web.server.savedrequest.WebSessionServerRequestCache.java

private static String pathInApplication(ServerHttpRequest request) {
    String path = request.getPath().pathWithinApplication().value();
    String query = request.getURI().getRawQuery();
    return path + (query != null ? "?" + query : "");
}

From source file:org.springframework.web.reactive.DispatcherHandler.java

@Override
public Mono<Void> handle(ServerWebExchange exchange) {
    if (logger.isDebugEnabled()) {
        ServerHttpRequest request = exchange.getRequest();
        logger.debug("Processing " + request.getMethodValue() + " request for [" + request.getURI() + "]");
    }//  w  w  w. j a  v a 2 s .co m
    if (this.handlerMappings == null) {
        return Mono.error(HANDLER_NOT_FOUND_EXCEPTION);
    }
    return Flux.fromIterable(this.handlerMappings).concatMap(mapping -> mapping.getHandler(exchange)).next()
            .switchIfEmpty(Mono.error(HANDLER_NOT_FOUND_EXCEPTION))
            .flatMap(handler -> invokeHandler(exchange, handler))
            .flatMap(result -> handleResult(exchange, result));
}

From source file:org.springframework.web.reactive.socket.server.support.HandshakeWebSocketService.java

@Override
public Mono<Void> handleRequest(ServerWebExchange exchange, WebSocketHandler handler) {
    ServerHttpRequest request = exchange.getRequest();
    HttpMethod method = request.getMethod();
    HttpHeaders headers = request.getHeaders();

    if (logger.isDebugEnabled()) {
        logger.debug("Handling " + request.getURI() + " with headers: " + headers);
    }/* w  w  w . java2  s  .c  o m*/

    if (HttpMethod.GET != method) {
        return Mono.error(
                new MethodNotAllowedException(request.getMethodValue(), Collections.singleton(HttpMethod.GET)));
    }

    if (!"WebSocket".equalsIgnoreCase(headers.getUpgrade())) {
        return handleBadRequest("Invalid 'Upgrade' header: " + headers);
    }

    List<String> connectionValue = headers.getConnection();
    if (!connectionValue.contains("Upgrade") && !connectionValue.contains("upgrade")) {
        return handleBadRequest("Invalid 'Connection' header: " + headers);
    }

    String key = headers.getFirst(SEC_WEBSOCKET_KEY);
    if (key == null) {
        return handleBadRequest("Missing \"Sec-WebSocket-Key\" header");
    }

    String protocol = selectProtocol(headers, handler);
    return this.upgradeStrategy.upgrade(exchange, handler, protocol);
}

From source file:org.springframework.web.server.adapter.HttpWebHandlerAdapter.java

private Mono<Void> handleFailure(ServerHttpRequest request, ServerHttpResponse response, Throwable ex) {
    if (isDisconnectedClientError(ex)) {
        if (disconnectedClientLogger.isTraceEnabled()) {
            disconnectedClientLogger.trace("Looks like the client has gone away", ex);
        } else if (disconnectedClientLogger.isDebugEnabled()) {
            disconnectedClientLogger.debug("Looks like the client has gone away: " + ex
                    + " (For a full stack trace, set the log category '" + DISCONNECTED_CLIENT_LOG_CATEGORY
                    + "' to TRACE level.)");
        }//  www.j av a  2  s  .c o  m
        return Mono.empty();
    }
    if (response.setStatusCode(HttpStatus.INTERNAL_SERVER_ERROR)) {
        logger.error("Failed to handle request [" + request.getMethod() + " " + request.getURI() + "]", ex);
        return Mono.empty();
    }
    // After the response is committed, propagate errors to the server..
    HttpStatus status = response.getStatusCode();
    logger.error("Unhandled failure: " + ex.getMessage() + ", response already set (status=" + status + ")");
    return Mono.error(ex);
}

From source file:org.springframework.web.server.handler.ResponseStatusExceptionHandler.java

private String buildMessage(ServerHttpRequest request, Throwable ex) {
    return "Failed to handle request [" + request.getMethod() + " " + request.getURI() + "]: "
            + ex.getMessage();/* ww  w. ja v a2  s  . c  o  m*/
}