use of javax.websocket.ClientEndpointConfig in project undertow by undertow-io.
the class TestMessagesReceivedInOrder method testMessagesReceivedInOrder.
@Test
public void testMessagesReceivedInOrder() throws Exception {
stacks.clear();
EchoSocket.receivedEchos = new FutureResult<>();
final ClientEndpointConfig clientEndpointConfig = ClientEndpointConfig.Builder.create().build();
final CountDownLatch done = new CountDownLatch(1);
final AtomicReference<String> error = new AtomicReference<>();
ContainerProvider.getWebSocketContainer().connectToServer(new Endpoint() {
@Override
public void onOpen(final Session session, EndpointConfig endpointConfig) {
try {
RemoteEndpoint.Basic rem = session.getBasicRemote();
List<String> messages = new ArrayList<>();
for (int i = 0; i < MESSAGES; i++) {
byte[] data = new byte[2048];
(new Random()).nextBytes(data);
String crc = md5(data);
rem.sendBinary(ByteBuffer.wrap(data));
messages.add(crc);
}
List<String> received = EchoSocket.receivedEchos.getIoFuture().get();
StringBuilder sb = new StringBuilder();
boolean fail = false;
for (int i = 0; i < messages.size(); i++) {
if (received.size() <= i) {
fail = true;
sb.append(i + ": should be " + messages.get(i) + " but is empty.");
} else {
if (!messages.get(i).equals(received.get(i))) {
fail = true;
sb.append(i + ": should be " + messages.get(i) + " but is " + received.get(i) + " (but found at " + received.indexOf(messages.get(i)) + ").");
}
}
}
if (fail) {
error.set(sb.toString());
}
done.countDown();
} catch (Throwable t) {
System.out.println(t);
}
}
}, clientEndpointConfig, new URI(DefaultServer.getDefaultServerURL() + "/webSocket"));
done.await(30, TimeUnit.SECONDS);
if (error.get() != null) {
Assert.fail(error.get());
}
}
use of javax.websocket.ClientEndpointConfig in project undertow by undertow-io.
the class BinaryEndpointTest method testBytesOnMessage.
@org.junit.Test
public void testBytesOnMessage() throws Exception {
SSLContext context = DefaultServer.getClientSSLContext();
ProgramaticClientEndpoint endpoint = new ProgramaticClientEndpoint();
ClientEndpointConfig clientEndpointConfig = ClientEndpointConfig.Builder.create().build();
clientEndpointConfig.getUserProperties().put(DefaultWebSocketClientSslProvider.SSL_CONTEXT, context);
ContainerProvider.getWebSocketContainer().connectToServer(endpoint, clientEndpointConfig, new URI("wss://" + DefaultServer.getHostAddress("default") + ":" + DefaultServer.getHostSSLPort("default") + "/partial"));
Assert.assertArrayEquals(bytes, endpoint.getResponses().poll(15, TimeUnit.SECONDS));
endpoint.session.close();
endpoint.closeLatch.await(10, TimeUnit.SECONDS);
}
use of javax.websocket.ClientEndpointConfig in project spring-framework by spring-projects.
the class StandardWebSocketClient method executeInternal.
private Mono<Void> executeInternal(URI url, HttpHeaders requestHeaders, WebSocketHandler handler) {
MonoProcessor<Void> completionMono = MonoProcessor.create();
return Mono.fromCallable(() -> {
String[] subProtocols = beforeHandshake(url, requestHeaders, handler);
DefaultConfigurator configurator = new DefaultConfigurator(requestHeaders);
Endpoint endpoint = createEndpoint(url, handler, completionMono, configurator);
ClientEndpointConfig config = createEndpointConfig(configurator, subProtocols);
return this.webSocketContainer.connectToServer(endpoint, config, url);
}).subscribeOn(// connectToServer is blocking
Schedulers.elastic()).then(completionMono);
}
use of javax.websocket.ClientEndpointConfig in project tomcat by apache.
the class TestShutdown method testShutdownBufferedMessages.
@Test
public void testShutdownBufferedMessages() throws Exception {
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctx = tomcat.addContext("", null);
ctx.addApplicationListener(EchoBufferedConfig.class.getName());
Tomcat.addServlet(ctx, "default", new DefaultServlet());
ctx.addServletMappingDecoded("/", "default");
tomcat.start();
WebSocketContainer wsContainer = ContainerProvider.getWebSocketContainer();
ClientEndpointConfig clientEndpointConfig = ClientEndpointConfig.Builder.create().build();
Session wsSession = wsContainer.connectToServer(TesterProgrammaticEndpoint.class, clientEndpointConfig, new URI("ws://localhost:" + getPort() + "/test"));
CountDownLatch latch = new CountDownLatch(1);
BasicText handler = new BasicText(latch);
wsSession.addMessageHandler(handler);
wsSession.getBasicRemote().sendText("Hello");
int count = 0;
while (count < 10 && EchoBufferedEndpoint.messageCount.get() == 0) {
Thread.sleep(200);
count++;
}
Assert.assertNotEquals("Message not received by server", EchoBufferedEndpoint.messageCount.get(), 0);
tomcat.stop();
Assert.assertTrue("Latch expired waiting for message", latch.await(10, TimeUnit.SECONDS));
}
use of javax.websocket.ClientEndpointConfig in project jetty.project by eclipse.
the class ClientContainer method getClientEndpointMetadata.
public EndpointMetadata getClientEndpointMetadata(Class<?> endpoint, EndpointConfig config) {
synchronized (endpointClientMetadataCache) {
EndpointMetadata metadata = endpointClientMetadataCache.get(endpoint);
if (metadata != null) {
return metadata;
}
ClientEndpoint anno = endpoint.getAnnotation(ClientEndpoint.class);
if (anno != null) {
// Annotated takes precedence here
AnnotatedClientEndpointMetadata annoMetadata = new AnnotatedClientEndpointMetadata(this, endpoint);
AnnotatedEndpointScanner<ClientEndpoint, ClientEndpointConfig> scanner = new AnnotatedEndpointScanner<>(annoMetadata);
scanner.scan();
metadata = annoMetadata;
} else if (Endpoint.class.isAssignableFrom(endpoint)) {
// extends Endpoint
@SuppressWarnings("unchecked") Class<? extends Endpoint> eendpoint = (Class<? extends Endpoint>) endpoint;
metadata = new SimpleEndpointMetadata(eendpoint, config);
} else {
StringBuilder err = new StringBuilder();
err.append("Not a recognized websocket [");
err.append(endpoint.getName());
err.append("] does not extend @").append(ClientEndpoint.class.getName());
err.append(" or extend from ").append(Endpoint.class.getName());
throw new InvalidWebSocketException(err.toString());
}
endpointClientMetadataCache.put(endpoint, metadata);
return metadata;
}
}
Aggregations