Java 类javax.websocket.ClientEndpointConfig.Configurator 实例源码

项目:Mastering-Java-EE-Development-with-WildFly    文件:SessionSecureTestCase.java   
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();
}
项目:lams    文件:WebsocketClient.java   
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);
}
   }
项目:spring4-understanding    文件:EndpointConnectionManager.java   
public void setConfigurator(Configurator configurator) {
    this.configBuilder.configurator(configurator);
}