本文整理汇总了Java中javax.websocket.ContainerProvider类的典型用法代码示例。如果您正苦于以下问题:Java ContainerProvider类的具体用法?Java ContainerProvider怎么用?Java ContainerProvider使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ContainerProvider类属于javax.websocket包,在下文中一共展示了ContainerProvider类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: WebsocketClient
import javax.websocket.ContainerProvider; //导入依赖的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: webSocketsStatusTest
import javax.websocket.ContainerProvider; //导入依赖的package包/类
/**
* Ensures that CDI event is relayed over the webSocket status endpoint.
*
* @throws Exception when the test has failed
*/
@Test
public void webSocketsStatusTest() throws Exception {
//given
UUID uuid = UUID.randomUUID();
WebSocketContainer container = ContainerProvider.getWebSocketContainer();
URI uri = UriBuilder.fromUri(deploymentUrl).scheme("ws").path("status").path(uuid.toString()).build();
container.connectToServer(endpoint, uri);
//when
Thread.sleep(200);
testEvent.fire(new StatusMessageEvent(uuid, StatusEventType.GITHUB_CREATE,
singletonMap(EXTRA_DATA_KEY, "http://github.com/dummy-project-location")));
endpoint.getLatch().await(1, TimeUnit.SECONDS);
//then
assertNotNull("a status message should have been send", endpoint.getMessage());
assertTrue(endpoint.getMessage().contains(EXTRA_DATA_KEY));
}
示例3: testClientDropsConnection
import javax.websocket.ContainerProvider; //导入依赖的package包/类
@Test
public void testClientDropsConnection() throws Exception {
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctx = tomcat.addContext("", null);
ctx.addApplicationListener(Bug58624Config.class.getName());
Tomcat.addServlet(ctx, "default", new DefaultServlet());
ctx.addServletMapping("/", "default");
WebSocketContainer wsContainer =
ContainerProvider.getWebSocketContainer();
tomcat.start();
SimpleClient client = new SimpleClient();
URI uri = new URI("ws://localhost:" + getPort() + Bug58624Config.PATH);
Session session = wsContainer.connectToServer(client, uri);
// Break point A required on following line
session.close();
}
示例4: echoTester
import javax.websocket.ContainerProvider; //导入依赖的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();
}
示例5: roundtrip_works
import javax.websocket.ContainerProvider; //导入依赖的package包/类
@Test
public void roundtrip_works() throws Exception {
when(managedBean.getValue()).thenReturn("mocked");
final URI uri = URI.create("ws://localhost:" + restServer.getPort() + "/websockets/echo");
final CountDownLatch latch = new CountDownLatch(1);
final WebSocketContainer container = ContainerProvider.getWebSocketContainer();
final Client client = new Client(() -> latch.countDown());
try (final Session session = container.connectToServer(client, uri)) {
session.getBasicRemote().sendText("Hello");
assertTrue(latch.await(5, SECONDS));
} finally {
((LifeCycle) container).stop();
}
assertEquals("mocked:Hello", client.message);
}
示例6: testConnectToServerEndpointInvalidScheme
import javax.websocket.ContainerProvider; //导入依赖的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));
}
示例7: main
import javax.websocket.ContainerProvider; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
WebSocketContainer wsc = ContainerProvider.getWebSocketContainer();
int testCaseCount = getTestCaseCount(wsc);
System.out.println("There are " + testCaseCount + " test cases");
for (int testCase = 1; testCase <= testCaseCount; testCase++) {
if (testCase % 50 == 0) {
System.out.println(testCase);
} else {
System.out.print('.');
}
try {
executeTestCase(wsc, testCase);
} catch (Throwable t) {
ExceptionUtils.handleThrowable(t);
t.printStackTrace();
}
}
System.out.println("Testing complete");
updateReports(wsc);
}
示例8: newJoineeGetsWelcomeMsg
import javax.websocket.ContainerProvider; //导入依赖的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();
}
示例9: main
import javax.websocket.ContainerProvider; //导入依赖的package包/类
public static void main(final String[] args) {
URI uri = URI.create("ws://localhost:8080/ws/");
try {
WebSocketContainer container = ContainerProvider.getWebSocketContainer();
try {
Session session = container.connectToServer(EventSocket.class, uri);
session.getBasicRemote().sendText("Hello");
session.close();
} finally {
if (container instanceof LifeCycle) {
((LifeCycle) container).stop();
}
}
} catch (Throwable t) {
t.printStackTrace(System.err);
}
}
示例10: sendMessage
import javax.websocket.ContainerProvider; //导入依赖的package包/类
/**
* Sends message to the WebSocket server.
*
* @param endpoint The server endpoint
* @param msg The message
* @return a return message
*/
private String sendMessage(String endpoint, String msg) {
LOGGER.config(() -> "Sending message: " + msg);
String returnValue = "-1";
try {
WebSocketContainer container = ContainerProvider.getWebSocketContainer();
String uri = serviceUrl + endpoint;
Session session = container.connectToServer(this, URI.create(uri));
session.getBasicRemote().sendText(msg != null ? msg : "");
returnValue = session.getId();
session.close();
} catch (DeploymentException | IOException ex) {
LOGGER.warning(ex.getMessage());
}
return returnValue;
}
示例11: connectToServer
import javax.websocket.ContainerProvider; //导入依赖的package包/类
/**
* Connects the current agent to a server.
*
* @param serverAddress
* - address of the agent we want to connect to.
* @param webSocketPort
* - the port number, on which the Server is listening
* @param agentId
* - An identifier of the current agent
* @throws URISyntaxException
* - thrown to indicate that a string could not be parsed as a URI reference
* @throws IOException
* - thrown when I/O exception of some sort has occurred
* @throws DeploymentException
* - failure to publish an endpoint on its server, or a failure to connect a client to its server
*/
public void connectToServer(String serverAddress, int webSocketPort, String agentId)
throws DeploymentException,
IOException,
URISyntaxException {
WebSocketContainer container = ContainerProvider.getWebSocketContainer();
container.setDefaultMaxTextMessageBufferSize(Integer.MAX_VALUE);
String uriAddress = String.format(SERVER_URI, serverAddress, webSocketPort);
this.session = container.connectToServer(AgentEndpoint.class, new URI(uriAddress));
List<DeviceInformation> connectedDevicesInformation = deviceManager.getDevicesInformation();
DeviceInformation[] devicesInformationArray = connectedDevicesInformation.toArray(new DeviceInformation[0]);
RequestMessage registerAgentRequest = new RequestMessage(MessageAction.REGISTER_AGENT,
agentId,
devicesInformationArray);
String registerAgentJsonRequest = jsonUtil.serialize(registerAgentRequest);
sendText(registerAgentJsonRequest, session);
LOGGER.debug("Connected to server address: " + uriAddress);
agentManager.registerServer();
LOGGER.info("The Server(" + serverAddress + ":" + webSocketPort
+ ") is registered for the device changed event notifications.");
}
示例12: webSocketsStatusTest
import javax.websocket.ContainerProvider; //导入依赖的package包/类
/**
* Ensures that CDI event is relayed over the webSocket status endpoint.
*
* @throws Exception when the test has failed
*/
@Test
public void webSocketsStatusTest() throws Exception {
//given
UUID uuid = UUID.randomUUID();
WebSocketContainer container = ContainerProvider.getWebSocketContainer();
URI uri = UriBuilder.fromUri(deploymentUrl).scheme("ws").path("status").path(uuid.toString()).build();
container.connectToServer(endpoint, uri);
//when
Thread.sleep(200);
testEvent.fire(new StatusMessageEvent(uuid, StatusMessage.GITHUB_CREATE,
singletonMap(EXTRA_DATA_KEY, "http://github.com/dummy-project-location")));
endpoint.getLatch().await(1, TimeUnit.SECONDS);
//then
assertNotNull("a status message should have been send", endpoint.getMessage());
assertTrue(endpoint.getMessage().contains(EXTRA_DATA_KEY));
}
开发者ID:fabric8-launcher,项目名称:launchpad-missioncontrol,代码行数:24,代码来源:MissionControlStatusEndpointIT.java
示例13: connect
import javax.websocket.ContainerProvider; //导入依赖的package包/类
/**
* Connect.
*
* @throws Exception the exception
*/
public void connect() throws Exception {
try {
uri = URI.create(url);
container = ContainerProvider.getWebSocketContainer();
try {
iote2eResultBytes = new ConcurrentLinkedQueue<byte[]>();
iote2eRequestSendThread = new Iote2eRequestSendThread();
iote2eReceiveReceiveThread = new Iote2eRequestReceiveThread();
iote2eRequestSendThread.start();
iote2eReceiveReceiveThread.start();
ClientSocketAvro iotClientSocketAvro = new ClientSocketAvro(iote2eReceiveReceiveThread,iote2eResultBytes);
session = container.connectToServer(iotClientSocketAvro, uri);
session.getBasicRemote().sendText( Iote2eUtils.getGsonInstance().toJson(loginVo));
logger.info("loginVo sent for {}", loginVo.getLoginName());
} finally {
}
} catch (Throwable t) {
t.printStackTrace(System.err);
}
}
示例14: connect
import javax.websocket.ContainerProvider; //导入依赖的package包/类
/**
* Connect.
*
* @throws Exception the exception
*/
public void connect() throws Exception {
if( url == null || url.length() == 0 )
throw new Exception("URL must be set before calling connect()");
loginVo = new LoginVo().setLoginName(TEST_SOURCE_LOGIN.toString());
try {
uri = URI.create(url);
container = ContainerProvider.getWebSocketContainer();
try {
ClientSocketBdbb clientSocketBdbb = new ClientSocketBdbb( );
session = container.connectToServer(clientSocketBdbb, uri);
session.getBasicRemote().sendText( Iote2eUtils.getGsonInstance().toJson(loginVo));
logger.info("loginVo sent for {}", loginVo.getLoginName());
} finally {
}
} catch (Throwable t) {
t.printStackTrace(System.err);
}
}
示例15: connect
import javax.websocket.ContainerProvider; //导入依赖的package包/类
/**
* Connect.
*
* @throws Exception the exception
*/
public void connect() throws Exception {
if( url == null || url.length() == 0 )
throw new Exception("URL must be set before calling connect()");
loginVo = new LoginVo().setLoginName(TEST_SOURCE_LOGIN.toString());
try {
uri = URI.create(url);
container = ContainerProvider.getWebSocketContainer();
try {
ClientSocketOmh clientSocketOmh = new ClientSocketOmh( );
session = container.connectToServer(clientSocketOmh, uri);
session.getBasicRemote().sendText( Iote2eUtils.getGsonInstance().toJson(loginVo));
logger.info("loginVo sent for {}", loginVo.getLoginName());
} finally {
}
} catch (Throwable t) {
t.printStackTrace(System.err);
}
}