Example usage for org.springframework.http.server ServerHttpRequest getLocalAddress

List of usage examples for org.springframework.http.server ServerHttpRequest getLocalAddress

Introduction

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

Prototype

InetSocketAddress getLocalAddress();

Source Link

Document

Return the address on which the request was received.

Usage

From source file:org.springframework.web.socket.server.standard.AbstractStandardUpgradeStrategy.java

@Override
public void upgrade(ServerHttpRequest request, ServerHttpResponse response, @Nullable String selectedProtocol,
        List<WebSocketExtension> selectedExtensions, @Nullable Principal user, WebSocketHandler wsHandler,
        Map<String, Object> attrs) throws HandshakeFailureException {

    HttpHeaders headers = request.getHeaders();
    InetSocketAddress localAddr = null;
    try {//from www  .ja  v a2s .co m
        localAddr = request.getLocalAddress();
    } catch (Exception ex) {
        // Ignore
    }
    InetSocketAddress remoteAddr = null;
    try {
        remoteAddr = request.getRemoteAddress();
    } catch (Exception ex) {
        // Ignore
    }

    StandardWebSocketSession session = new StandardWebSocketSession(headers, attrs, localAddr, remoteAddr,
            user);
    StandardWebSocketHandlerAdapter endpoint = new StandardWebSocketHandlerAdapter(wsHandler, session);

    List<Extension> extensions = new ArrayList<>();
    for (WebSocketExtension extension : selectedExtensions) {
        extensions.add(new WebSocketToStandardExtensionAdapter(extension));
    }

    upgradeInternal(request, response, selectedProtocol, extensions, endpoint);
}