org.eclipse.jetty.websocket.api.UpgradeResponse Java Examples

The following examples show how to use org.eclipse.jetty.websocket.api.UpgradeResponse. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JettyWebSocketSessionTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@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);
}
 
Example #2
Source File: RestrictedGuacamoleWebSocketCreator.java    From guacamole-client with Apache License 2.0 6 votes vote down vote up
@Override
public Object createWebSocket(UpgradeRequest request, UpgradeResponse response) {

    // Validate and use "guacamole" subprotocol
    for (String subprotocol : request.getSubProtocols()) {

        if ("guacamole".equals(subprotocol)) {
            response.setAcceptedSubProtocol(subprotocol);
            return new RestrictedGuacamoleWebSocketTunnelListener(tunnelRequestService);
        }

    }

    // Invalid protocol
    return null;

}
 
Example #3
Source File: RestrictedGuacamoleWebSocketCreator.java    From guacamole-client with Apache License 2.0 6 votes vote down vote up
@Override
public Object createWebSocket(UpgradeRequest request, UpgradeResponse response) {

    // Validate and use "guacamole" subprotocol
    for (String subprotocol : request.getSubProtocols()) {

        if ("guacamole".equals(subprotocol)) {
            response.setAcceptedSubProtocol(subprotocol);
            return new RestrictedGuacamoleWebSocketTunnelListener(tunnelRequestService);
        }

    }

    // Invalid protocol
    return null;

}
 
Example #4
Source File: JettyWebSocketSessionTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
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);
}
 
Example #5
Source File: JettyWebSocketSessionTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
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);
}
 
Example #6
Source File: JettyWebSocketSessionTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
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);
}
 
Example #7
Source File: JettyWebSocketSessionTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@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);
}
 
Example #8
Source File: JettyWebSocketSessionTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@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);
}
 
Example #9
Source File: JettyWebSocketSessionTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@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);
}
 
Example #10
Source File: JettyWebSocketSessionTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@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);
}
 
Example #11
Source File: JettyWebSocketSessionTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@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);
}
 
Example #12
Source File: JettyWebSocketHandlerAdapterTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Before
public void setup() {
	this.session = mock(Session.class);
	given(this.session.getUpgradeRequest()).willReturn(Mockito.mock(UpgradeRequest.class));
	given(this.session.getUpgradeResponse()).willReturn(Mockito.mock(UpgradeResponse.class));

	this.webSocketHandler = mock(WebSocketHandler.class);
	this.webSocketSession = new JettyWebSocketSession(null, null);
	this.adapter = new JettyWebSocketHandlerAdapter(this.webSocketHandler, this.webSocketSession);
}
 
Example #13
Source File: JettyWebSocketHandlerAdapterTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Before
public void setup() {
	this.session = mock(Session.class);
	given(this.session.getUpgradeRequest()).willReturn(Mockito.mock(UpgradeRequest.class));
	given(this.session.getUpgradeResponse()).willReturn(Mockito.mock(UpgradeResponse.class));

	this.webSocketHandler = mock(WebSocketHandler.class);
	this.webSocketSession = new JettyWebSocketSession(null, null);
	this.adapter = new JettyWebSocketHandlerAdapter(this.webSocketHandler, this.webSocketSession);
}
 
Example #14
Source File: JettyWebSocketHandlerAdapterTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
	this.session = mock(Session.class);
	given(this.session.getUpgradeRequest()).willReturn(Mockito.mock(UpgradeRequest.class));
	given(this.session.getUpgradeResponse()).willReturn(Mockito.mock(UpgradeResponse.class));

	this.webSocketHandler = mock(WebSocketHandler.class);
	this.webSocketSession = new JettyWebSocketSession(null, null);
	this.adapter = new JettyWebSocketHandlerAdapter(this.webSocketHandler, this.webSocketSession);
}
 
Example #15
Source File: JettyWebSocketClient.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
public void onHandshakeResponse(UpgradeResponse response) {
}
 
Example #16
Source File: JettyWebSocketClient.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
public void onHandshakeResponse(UpgradeResponse response) {
}
 
Example #17
Source File: MockSession.java    From buck with Apache License 2.0 4 votes vote down vote up
@Override
public UpgradeResponse getUpgradeResponse() {
  return null;
}