本文整理汇总了Java中org.eclipse.jetty.websocket.api.UpgradeResponse类的典型用法代码示例。如果您正苦于以下问题:Java UpgradeResponse类的具体用法?Java UpgradeResponse怎么用?Java UpgradeResponse使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UpgradeResponse类属于org.eclipse.jetty.websocket.api包,在下文中一共展示了UpgradeResponse类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getPrincipalFromNativeSession
import org.eclipse.jetty.websocket.api.UpgradeResponse; //导入依赖的package包/类
@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);
}
示例2: getPrincipalNotAvailable
import org.eclipse.jetty.websocket.api.UpgradeResponse; //导入依赖的package包/类
@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);
}
示例3: getAcceptedProtocol
import org.eclipse.jetty.websocket.api.UpgradeResponse; //导入依赖的package包/类
@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);
}
示例4: createWebSocket
import org.eclipse.jetty.websocket.api.UpgradeResponse; //导入依赖的package包/类
@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;
}
示例5: setup
import org.eclipse.jetty.websocket.api.UpgradeResponse; //导入依赖的package包/类
@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);
}
示例6: configure
import org.eclipse.jetty.websocket.api.UpgradeResponse; //导入依赖的package包/类
@Override
public void configure(WebSocketServletFactory factory) {
// Most implementations of this method simply invoke factory.register(DispatchSocket.class);
// however, that requires DispatchSocket to have a no-arg constructor. That does not work for
// us because we would like all WebSockets created by this factory to have a reference to this
// parent class. This is why we override the default WebSocketCreator for the factory.
WebSocketCreator wrapperCreator = new WebSocketCreator() {
@Override
public Object createWebSocket(UpgradeRequest req, UpgradeResponse resp) {
return new MyWebSocket();
}
};
factory.setCreator(wrapperCreator);
}
示例7: createWebSocket
import org.eclipse.jetty.websocket.api.UpgradeResponse; //导入依赖的package包/类
@Override
public Object createWebSocket(UpgradeRequest req, UpgradeResponse resp) {
System.out.println(".. "+req.getRequestURI().getPath());
String path = req.getRequestURI().getPath(),
name = path.substring(path.lastIndexOf('/')+1);
try {
Class<?> clazz = Class.forName("jforex.jetty."+name.substring(0, 1).toUpperCase() + name.substring(1)+"Strategy");
Object strat = null;
for (Entry<Long, IStrategy> e : WebServer.pids.entrySet()){
if (clazz.equals(e.getValue().getClass())){
strat = e.getValue();
}
}
// if not started, start it now
if (strat ==null){
Constructor<?> ctor = clazz.getConstructor();
strat = ctor.newInstance();
long pid = ClientFactory.getDefaultInstance().startStrategy((IStrategy) strat);
WebServer.pids.put(pid, (IStrategy) strat);
}
return strat;
} catch (ClassNotFoundException | SecurityException | IllegalArgumentException | NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException e1) {
e1.printStackTrace();
}
return null;
}
示例8: configure
import org.eclipse.jetty.websocket.api.UpgradeResponse; //导入依赖的package包/类
@Override
public void configure(WebSocketServletFactory factory) {
factory.getPolicy().setIdleTimeout(10000);
factory.setCreator(new WebSocketCreator() {
@Override
public Object createWebSocket(UpgradeRequest req, UpgradeResponse resp) {
return new DrogonLoggerSocket( getWebLoggerModule( ) );
}
});
}
示例9: getUpgradeResponse
import org.eclipse.jetty.websocket.api.UpgradeResponse; //导入依赖的package包/类
@Override
public UpgradeResponse getUpgradeResponse() {
return null;
}