Search in sources :

Example 1 with UpgradeResponse

use of org.eclipse.jetty.websocket.api.UpgradeResponse in project spring-framework by spring-projects.

the class JettyWebSocketSessionTests method getAcceptedProtocol.

@Test
@SuppressWarnings("resource")
public void getAcceptedProtocol() {
    String protocol = "foo";
    UpgradeRequest request = Mockito.mock(UpgradeRequest.class);
    given(request.getUserPrincipal()).willReturn(null);
    UpgradeResponse response = Mockito.mock(UpgradeResponse.class);
    given(response.getAcceptedSubProtocol()).willReturn(protocol);
    Session nativeSession = Mockito.mock(Session.class);
    given(nativeSession.getUpgradeRequest()).willReturn(request);
    given(nativeSession.getUpgradeResponse()).willReturn(response);
    JettyWebSocketSession session = new JettyWebSocketSession(attributes);
    session.initializeNativeSession(nativeSession);
    reset(nativeSession);
    assertSame(protocol, session.getAcceptedProtocol());
    verifyNoMoreInteractions(nativeSession);
}
Also used : UpgradeResponse(org.eclipse.jetty.websocket.api.UpgradeResponse) UpgradeRequest(org.eclipse.jetty.websocket.api.UpgradeRequest) Session(org.eclipse.jetty.websocket.api.Session) Test(org.junit.Test)

Example 2 with UpgradeResponse

use of org.eclipse.jetty.websocket.api.UpgradeResponse in project spring-framework by spring-projects.

the class JettyWebSocketClient method createJettyHandler.

private Object createJettyHandler(URI url, WebSocketHandler handler, MonoProcessor<Void> completion) {
    return new JettyWebSocketHandlerAdapter(handler, session -> {
        UpgradeResponse response = session.getUpgradeResponse();
        HttpHeaders responseHeaders = new HttpHeaders();
        response.getHeaders().forEach(responseHeaders::put);
        HandshakeInfo info = afterHandshake(url, responseHeaders);
        return new JettyWebSocketSession(session, info, this.bufferFactory, completion);
    });
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) UpgradeResponse(org.eclipse.jetty.websocket.api.UpgradeResponse) JettyWebSocketSession(org.springframework.web.reactive.socket.adapter.JettyWebSocketSession) JettyWebSocketHandlerAdapter(org.springframework.web.reactive.socket.adapter.JettyWebSocketHandlerAdapter) HandshakeInfo(org.springframework.web.reactive.socket.HandshakeInfo)

Example 3 with UpgradeResponse

use of org.eclipse.jetty.websocket.api.UpgradeResponse in project spring-framework by spring-projects.

the class JettyWebSocketSessionTests method getPrincipalNotAvailable.

@Test
@SuppressWarnings("resource")
public void getPrincipalNotAvailable() {
    UpgradeRequest request = Mockito.mock(UpgradeRequest.class);
    given(request.getUserPrincipal()).willReturn(null);
    UpgradeResponse response = Mockito.mock(UpgradeResponse.class);
    given(response.getAcceptedSubProtocol()).willReturn(null);
    Session nativeSession = Mockito.mock(Session.class);
    given(nativeSession.getUpgradeRequest()).willReturn(request);
    given(nativeSession.getUpgradeResponse()).willReturn(response);
    JettyWebSocketSession session = new JettyWebSocketSession(attributes);
    session.initializeNativeSession(nativeSession);
    reset(nativeSession);
    assertNull(session.getPrincipal());
    verifyNoMoreInteractions(nativeSession);
}
Also used : UpgradeResponse(org.eclipse.jetty.websocket.api.UpgradeResponse) UpgradeRequest(org.eclipse.jetty.websocket.api.UpgradeRequest) Session(org.eclipse.jetty.websocket.api.Session) Test(org.junit.Test)

Example 4 with UpgradeResponse

use of org.eclipse.jetty.websocket.api.UpgradeResponse in project spring-framework by spring-projects.

the class JettyWebSocketSessionTests method getPrincipalFromNativeSession.

@Test
@SuppressWarnings("resource")
public void getPrincipalFromNativeSession() {
    TestPrincipal user = new TestPrincipal("joe");
    UpgradeRequest request = Mockito.mock(UpgradeRequest.class);
    given(request.getUserPrincipal()).willReturn(user);
    UpgradeResponse response = Mockito.mock(UpgradeResponse.class);
    given(response.getAcceptedSubProtocol()).willReturn(null);
    Session nativeSession = Mockito.mock(Session.class);
    given(nativeSession.getUpgradeRequest()).willReturn(request);
    given(nativeSession.getUpgradeResponse()).willReturn(response);
    JettyWebSocketSession session = new JettyWebSocketSession(attributes);
    session.initializeNativeSession(nativeSession);
    reset(nativeSession);
    assertSame(user, session.getPrincipal());
    verifyNoMoreInteractions(nativeSession);
}
Also used : UpgradeResponse(org.eclipse.jetty.websocket.api.UpgradeResponse) TestPrincipal(org.springframework.web.socket.handler.TestPrincipal) UpgradeRequest(org.eclipse.jetty.websocket.api.UpgradeRequest) Session(org.eclipse.jetty.websocket.api.Session) Test(org.junit.Test)

Aggregations

UpgradeResponse (org.eclipse.jetty.websocket.api.UpgradeResponse)4 Session (org.eclipse.jetty.websocket.api.Session)3 UpgradeRequest (org.eclipse.jetty.websocket.api.UpgradeRequest)3 Test (org.junit.Test)3 HttpHeaders (org.springframework.http.HttpHeaders)1 HandshakeInfo (org.springframework.web.reactive.socket.HandshakeInfo)1 JettyWebSocketHandlerAdapter (org.springframework.web.reactive.socket.adapter.JettyWebSocketHandlerAdapter)1 JettyWebSocketSession (org.springframework.web.reactive.socket.adapter.JettyWebSocketSession)1 TestPrincipal (org.springframework.web.socket.handler.TestPrincipal)1