當前位置: 首頁>>代碼示例>>Java>>正文


Java ClientEndpointConfig類代碼示例

本文整理匯總了Java中javax.websocket.ClientEndpointConfig的典型用法代碼示例。如果您正苦於以下問題:Java ClientEndpointConfig類的具體用法?Java ClientEndpointConfig怎麽用?Java ClientEndpointConfig使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ClientEndpointConfig類屬於javax.websocket包,在下文中一共展示了ClientEndpointConfig類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: WebsocketClient

import javax.websocket.ClientEndpointConfig; //導入依賴的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);
}
   }
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:21,代碼來源:WebsocketClient.java

示例2: echoTester

import javax.websocket.ClientEndpointConfig; //導入依賴的package包/類
public void echoTester(String path) throws Exception {
    WebSocketContainer wsContainer =
            ContainerProvider.getWebSocketContainer();
    ClientEndpointConfig clientEndpointConfig =
            ClientEndpointConfig.Builder.create().build();
    Session wsSession = wsContainer.connectToServer(
            TesterProgrammaticEndpoint.class,
            clientEndpointConfig,
            new URI("ws://localhost:" + getPort() + path));
    CountDownLatch latch =
            new CountDownLatch(1);
    BasicText handler = new BasicText(latch);
    wsSession.addMessageHandler(handler);
    wsSession.getBasicRemote().sendText("Hello");

    boolean latchResult = handler.getLatch().await(10, TimeUnit.SECONDS);
    Assert.assertTrue(latchResult);

    Queue<String> messages = handler.getMessages();
    Assert.assertEquals(1, messages.size());
    for (String message : messages) {
        Assert.assertEquals("Hello", message);
    }
    wsSession.close();
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:26,代碼來源:TestWebSocketFrameClient.java

示例3: connect

import javax.websocket.ClientEndpointConfig; //導入依賴的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

示例4: streamLoggregatorLogs

import javax.websocket.ClientEndpointConfig; //導入依賴的package包/類
private StreamingLogToken streamLoggregatorLogs(String appName, ApplicationLogListener listener, boolean recent) {
    ClientEndpointConfig.Configurator configurator = new ClientEndpointConfig.Configurator() {
        @Override
        public void beforeRequest(Map<String, List<String>> headers) {
            String authorizationHeader = oauthClient.getAuthorizationHeader();
            if (authorizationHeader != null) {
                headers.put(AUTHORIZATION_HEADER_KEY, Arrays.asList(authorizationHeader));
            }
        }
    };

    String endpoint = getInfo().getLoggregatorEndpoint();
    String mode = recent ? "dump" : "tail";
    UUID appId = getAppId(appName);
    return loggregatorClient.connectToLoggregator(endpoint, mode, appId, listener, configurator);
}
 
開發者ID:SAP,項目名稱:cf-java-client-sap,代碼行數:17,代碼來源:CloudControllerClientImpl.java

示例5: testConnectToServerEndpointInvalidScheme

import javax.websocket.ClientEndpointConfig; //導入依賴的package包/類
@Test(expected=javax.websocket.DeploymentException.class)
public void testConnectToServerEndpointInvalidScheme() throws Exception {
    Tomcat tomcat = getTomcatInstance();
    // No file system docBase required
    Context ctx = tomcat.addContext("", null);
    ctx.addApplicationListener(TesterEchoServer.Config.class.getName());

    tomcat.start();

    WebSocketContainer wsContainer =
            ContainerProvider.getWebSocketContainer();
    wsContainer.connectToServer(TesterProgrammaticEndpoint.class,
            ClientEndpointConfig.Builder.create().build(),
            new URI("ftp://" + getHostName() + ":" + getPort() +
                    TesterEchoServer.Config.PATH_ASYNC));
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:17,代碼來源:TestWsWebSocketContainer.java

示例6: newJoineeGetsWelcomeMsg

import javax.websocket.ClientEndpointConfig; //導入依賴的package包/類
@Test
public void newJoineeGetsWelcomeMsg() throws DeploymentException, IOException, InterruptedException {
    controlLatch = new CountDownLatch(2);

    ChatClient newJoinee = new ChatClient();
    String newJoineeName = "abhishek";
    String endpointURL = BASE_SERVER_URL + newJoineeName + "/";
    WebSocketContainer container = ContainerProvider.getWebSocketContainer();
    container.connectToServer(newJoinee,
            ClientEndpointConfig.Builder.create().build(),
            URI.create(endpointURL));

    assertTrue(controlLatch.await(5, TimeUnit.SECONDS));
    String expectedWelcomeMessage = "Welcome " + newJoineeName;
    assertTrue(newJoinee.getResponse().contains(expectedWelcomeMessage));
    newJoinee.closeConnection();
}
 
開發者ID:abhirockzz,項目名稱:websocket-chat,代碼行數:18,代碼來源:ChatServerTest.java

示例7: initWebSocketSession

import javax.websocket.ClientEndpointConfig; //導入依賴的package包/類
private void initWebSocketSession(String url, int wsConnectionTimeout) throws Exception {
    CountDownLatch wsLatch = new CountDownLatch(1);
    ClientEndpointConfig cec = ClientEndpointConfig.Builder.create().build();
    ClientManager client = ClientManager.createClient();

    client.connectToServer(new Endpoint() {
        @Override
        public void onOpen(Session session, EndpointConfig endpointConfig) {
            wsSession = session;
            wsLatch.countDown();
        }
    }, cec, new URI(url));

    if (!wsLatch.await(wsConnectionTimeout, TimeUnit.SECONDS)) {
        throw new TimeoutException("Web socket connection timeout");
    }
}
 
開發者ID:FlowCI,項目名稱:flow-platform,代碼行數:18,代碼來源:LogEventHandler.java

示例8: openConnection

import javax.websocket.ClientEndpointConfig; //導入依賴的package包/類
@Override
protected void openConnection() {
	this.taskExecutor.execute(new Runnable() {
		@Override
		public void run() {
			try {
				logger.info("Connecting to WebSocket at " + getUri());
				Endpoint endpointToUse = (endpoint != null) ? endpoint : endpointProvider.getHandler();
				ClientEndpointConfig endpointConfig = configBuilder.build();
				session = getWebSocketContainer().connectToServer(endpointToUse, endpointConfig, getUri());
				logger.info("Successfully connected");
			}
			catch (Throwable ex) {
				logger.error("Failed to connect", ex);
			}
		}
	});
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:19,代碼來源:EndpointConnectionManager.java

示例9: createClearChannel

import javax.websocket.ClientEndpointConfig; //導入依賴的package包/類
private void createClearChannel() throws Exception {
  ClientEndpointConfig config = ClientEndpointConfig.Builder.create().build();
  config.getUserProperties().put(WsWebSocketContainer.SSL_CONTEXT_PROPERTY, sslContext);
  clearChannel = ContainerProvider.getWebSocketContainer().connectToServer(endpoint,
      config,
      new URI(createClearUriString()));

  assertTrue(clearChannel.isOpen());

  CountDownLatch cdl = new CountDownLatch(1);
  endpoint.setResponseLatch(cdl);

  cdl.await(1, TimeUnit.SECONDS);

  assertNotNull(endpoint.getSystemId());
  assertEquals(clearChannel, endpoint.getSession());
}
 
開發者ID:mrstampy,項目名稱:gameboot,代碼行數:18,代碼來源:OtpWebSocketTest.java

示例10: connect

import javax.websocket.ClientEndpointConfig; //導入依賴的package包/類
@Override
public void connect() throws DeploymentException, IOException {
    ConnectionDetails details = info.getConnectionDetails();
    Log.log(Level.FINE, drain, "Creating websocket to {0}", details.getTarget());

    URI uriServerEP = URI.create(details.getTarget());

    authConfigurator = new GameOnHeaderAuthConfigurator(details.getToken(), uriServerEP.getRawPath());
    final ClientEndpointConfig cec = ClientEndpointConfig.Builder.create()
            .decoders(Arrays.asList(RoutedMessageDecoder.class)).encoders(Arrays.asList(RoutedMessageEncoder.class))
            .configurator(authConfigurator)
            .build();

    WebSocketContainer c = ContainerProvider.getWebSocketContainer();
    this.session = c.connectToServer(this, cec, uriServerEP);
}
 
開發者ID:gameontext,項目名稱:gameon-mediator,代碼行數:17,代碼來源:WebSocketClientConnection.java

示例11: connect

import javax.websocket.ClientEndpointConfig; //導入依賴的package包/類
/**
 * Establishes the connection to the given WebSocket Server Address.
 */
public void connect() {

    readyState = ReadyState.CONNECTING;

    try {
        if (webSocketHandler == null) {
            webSocketHandler = new WebSocketHandlerAdapter();
        }

        container.connectToServer(new SimpleWebSocketClientEndpoint(), ClientEndpointConfig.Builder.create().build(), websocketURI);
    } catch (Exception e) {

        readyState = ReadyState.CLOSED;
        // throws DeploymentException, IOException
        throw new RuntimeException("could not establish connection");

    }
}
 
開發者ID:matzew,項目名稱:simple-websocket-client,代碼行數:22,代碼來源:SimpleWebSocketClient.java

示例12: testConnectToServerEndpointInvalidScheme

import javax.websocket.ClientEndpointConfig; //導入依賴的package包/類
@Test(expected=javax.websocket.DeploymentException.class)
public void testConnectToServerEndpointInvalidScheme() throws Exception {
    Tomcat tomcat = getTomcatInstance();
    // Must have a real docBase - just use temp
    Context ctx =
        tomcat.addContext("", System.getProperty("java.io.tmpdir"));
    ctx.addApplicationListener(new ApplicationListener(
            TesterEchoServer.Config.class.getName(), false));

    tomcat.start();

    WebSocketContainer wsContainer =
            ContainerProvider.getWebSocketContainer();
    wsContainer.connectToServer(TesterProgrammaticEndpoint.class,
            ClientEndpointConfig.Builder.create().build(),
            new URI("ftp://localhost:" + getPort() +
                    TesterEchoServer.Config.PATH_ASYNC));
}
 
開發者ID:deathspeeder,項目名稱:class-guard,代碼行數:19,代碼來源:TestWsWebSocketContainer.java

示例13: testConnectToServerEndpointNoHost

import javax.websocket.ClientEndpointConfig; //導入依賴的package包/類
@Test(expected=javax.websocket.DeploymentException.class)
public void testConnectToServerEndpointNoHost() throws Exception {
    Tomcat tomcat = getTomcatInstance();
    // Must have a real docBase - just use temp
    Context ctx =
        tomcat.addContext("", System.getProperty("java.io.tmpdir"));
    ctx.addApplicationListener(new ApplicationListener(
            TesterEchoServer.Config.class.getName(), false));

    tomcat.start();

    WebSocketContainer wsContainer =
            ContainerProvider.getWebSocketContainer();
    wsContainer.connectToServer(TesterProgrammaticEndpoint.class,
            ClientEndpointConfig.Builder.create().build(),
            new URI("ws://" + TesterEchoServer.Config.PATH_ASYNC));
}
 
開發者ID:deathspeeder,項目名稱:class-guard,代碼行數:18,代碼來源:TestWsWebSocketContainer.java

示例14: processRequest

import javax.websocket.ClientEndpointConfig; //導入依賴的package包/類
/**
 * Processes requests for both HTTP
 * <code>GET</code> and
 * <code>POST</code> methods.
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    try (PrintWriter out = response.getWriter()) {
        out.println("<html>");
        out.println("<head>");
        out.println("<title>Servlet TestServlet</title>");            
        out.println("</head>");
        out.println("<body>");
        out.println("<h1>Servlet TestServlet at " + request.getContextPath() + "</h1>");
        
        WebSocketContainer container = ContainerProvider.getWebSocketContainer();
        String uri = "ws://localhost:8080" + request.getContextPath() + "/websocket";
        out.println("Connecting to " + uri);
        container.connectToServer(MyClient.class, 
                ClientEndpointConfig.Builder.create().configurator(new MyConfigurator()).build(),
                URI.create(uri));
        out.println("<br><br>Look in server.log for message exchange between client/server and headers from configurator.");
        
        out.println("</body>");
        out.println("</html>");
    } catch (DeploymentException ex) {
        Logger.getLogger(TestClient.class.getName()).log(Level.SEVERE, null, ex);
    }
}
 
開發者ID:ftomassetti,項目名稱:JavaIncrementalParser,代碼行數:36,代碼來源:TestClient.java

示例15: testConnectToServerEndpointInvalidScheme

import javax.websocket.ClientEndpointConfig; //導入依賴的package包/類
@Test(expected=javax.websocket.DeploymentException.class)
public void testConnectToServerEndpointInvalidScheme() throws Exception {
    Tomcat tomcat = getTomcatInstance();
    // Must have a real docBase - just use temp
    Context ctx =
        tomcat.addContext("", System.getProperty("java.io.tmpdir"));
    ctx.addApplicationListener(TesterEchoServer.Config.class.getName());

    tomcat.start();

    WebSocketContainer wsContainer =
            ContainerProvider.getWebSocketContainer();
    wsContainer.connectToServer(TesterProgrammaticEndpoint.class,
            ClientEndpointConfig.Builder.create().build(),
            new URI("ftp://localhost:" + getPort() +
                    TesterEchoServer.Config.PATH_ASYNC));
}
 
開發者ID:sdw2330976,項目名稱:apache-tomcat-7.0.57,代碼行數:18,代碼來源:TestWsWebSocketContainer.java


注:本文中的javax.websocket.ClientEndpointConfig類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。