本文整理汇总了Java中javax.websocket.ClientEndpointConfig.Configurator类的典型用法代码示例。如果您正苦于以下问题:Java Configurator类的具体用法?Java Configurator怎么用?Java Configurator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Configurator类属于javax.websocket.ClientEndpointConfig包,在下文中一共展示了Configurator类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: WebsocketClient
import javax.websocket.ClientEndpointConfig.Configurator; //导入依赖的package包/类
public WebsocketClient(String uri, final String sessionID, MessageHandler.Whole<String> messageHandler)
throws IOException {
// add session ID so the request gets through LAMS security
Builder configBuilder = ClientEndpointConfig.Builder.create();
configBuilder.configurator(new Configurator() {
@Override
public void beforeRequest(Map<String, List<String>> headers) {
headers.put("Cookie", Arrays.asList("JSESSIONID=" + sessionID));
}
});
ClientEndpointConfig clientConfig = configBuilder.build();
this.websocketEndpoint = new WebsocketEndpoint(messageHandler);
WebSocketContainer container = ContainerProvider.getWebSocketContainer();
try {
container.connectToServer(websocketEndpoint, clientConfig, new URI(uri));
} catch (DeploymentException | URISyntaxException e) {
throw new IOException("Error while connecting to websocket server", e);
}
}
示例2: connect
import javax.websocket.ClientEndpointConfig.Configurator; //导入依赖的package包/类
private void connect() throws Exception {
while (sessionServer != null && !sessionServer.isOpen()) {
break;
}
SSLContext context = createSSLContext();
SecureSocketClient endpoint = new SecureSocketClient();
Configurator configurator = new Configurator() {
@Override
public void beforeRequest(Map<String, List<String>> headers) {
headers.put(SEC_WEB_SOCKET_PROTOCOL_STRING, singletonList("configured-proto"));
}
};
ClientEndpointConfig clientEndpointConfig = create().configurator(configurator)
.preferredSubprotocols(asList(new String[] { "foo", "bar", "configured-proto" })).build();
clientEndpointConfig.getUserProperties().put(SSL_CONTEXT, context);
final WebSocketContainer serverContainer = getWebSocketContainer();
URI uri = new URI("wss://127.0.0.1:8443/secure-test/session");
serverContainer.connectToServer(endpoint, clientEndpointConfig, uri);
awake();
}
开发者ID:PacktPublishing,项目名称:Mastering-Java-EE-Development-with-WildFly,代码行数:25,代码来源:SessionSecureTestCase.java
示例3: setConfigurator
import javax.websocket.ClientEndpointConfig.Configurator; //导入依赖的package包/类
public void setConfigurator(Configurator configurator) {
this.configBuilder.configurator(configurator);
}