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);
}
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);
});
}
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);
}
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);
}
Aggregations