use of javax.websocket.ClientEndpointConfig in project jetty.project by eclipse.
the class ClientContainer method connect.
private Session connect(EndpointInstance instance, URI path) throws IOException {
Objects.requireNonNull(instance, "EndpointInstance cannot be null");
Objects.requireNonNull(path, "Path cannot be null");
ClientEndpointConfig config = (ClientEndpointConfig) instance.getConfig();
ClientUpgradeRequest req = new ClientUpgradeRequest();
UpgradeListener upgradeListener = null;
for (Extension ext : config.getExtensions()) {
req.addExtensions(new JsrExtensionConfig(ext));
}
if (config.getPreferredSubprotocols().size() > 0) {
req.setSubProtocols(config.getPreferredSubprotocols());
}
if (config.getConfigurator() != null) {
upgradeListener = new JsrUpgradeListener(config.getConfigurator());
}
Future<org.eclipse.jetty.websocket.api.Session> futSess = client.connect(instance, path, req, upgradeListener);
try {
return (JsrSession) futSess.get();
} catch (InterruptedException e) {
throw new IOException("Connect failure", e);
} catch (ExecutionException e) {
// Unwrap Actual Cause
Throwable cause = e.getCause();
if (cause instanceof IOException) {
// Just rethrow
throw (IOException) cause;
} else {
throw new IOException("Connect failure", cause);
}
}
}
use of javax.websocket.ClientEndpointConfig in project jetty.project by eclipse.
the class AnnotatedEndpointConfigTest method testConfigurator.
@Test
public void testConfigurator() throws Exception {
ClientEndpointConfig ceconfig = (ClientEndpointConfig) config;
Assert.assertThat("Client Configurator", ceconfig.getConfigurator(), instanceOf(AnnotatedEndpointConfigurator.class));
}
use of javax.websocket.ClientEndpointConfig in project jetty.project by eclipse.
the class AnnotatedEndpointConfigTest method startEnv.
@BeforeClass
public static void startEnv() throws Exception {
// Server
server = new Server();
ServerConnector connector = new ServerConnector(server);
server.addConnector(connector);
handler = new EchoHandler();
ContextHandler context = new ContextHandler();
context.setContextPath("/");
context.setHandler(handler);
server.setHandler(context);
// Start Server
server.start();
String host = connector.getHost();
if (host == null) {
host = "localhost";
}
int port = connector.getLocalPort();
serverUri = new URI(String.format("ws://%s:%d/", host, port));
// Connect client
WebSocketContainer container = ContainerProvider.getWebSocketContainer();
socket = new AnnotatedEndpointClient();
session = container.connectToServer(socket, serverUri);
Assert.assertThat("Session", session, notNullValue());
config = socket.config;
Assert.assertThat("EndpointConfig", config, notNullValue());
Assert.assertThat("EndpointConfig", config, instanceOf(ClientEndpointConfig.class));
ceconfig = (ClientEndpointConfig) config;
Assert.assertThat("EndpointConfig", ceconfig, notNullValue());
}
use of javax.websocket.ClientEndpointConfig in project jetty.project by eclipse.
the class EncoderTest method testSingleQuotes.
@Test
public void testSingleQuotes() throws Exception {
EchoServer eserver = new EchoServer(server);
try {
eserver.start();
QuotesSocket quoter = new QuotesSocket();
ClientEndpointConfig.Builder builder = ClientEndpointConfig.Builder.create();
List<Class<? extends Encoder>> encoders = new ArrayList<>();
encoders.add(QuotesEncoder.class);
builder.encoders(encoders);
ClientEndpointConfig cec = builder.build();
client.connectToServer(quoter, cec, server.getWsUri());
Quotes ben = getQuotes("quotes-ben.txt");
quoter.write(ben);
quoter.messageQueue.awaitEventCount(1, 1000, TimeUnit.MILLISECONDS);
String result = quoter.messageQueue.poll();
assertReceivedQuotes(result, ben);
} finally {
eserver.stop();
}
}
use of javax.websocket.ClientEndpointConfig in project jetty.project by eclipse.
the class ClientAnnotatedEndpointScanner_GoodSignaturesTest method testScan_Basic.
@Test
public void testScan_Basic() throws Exception {
AnnotatedClientEndpointMetadata metadata = new AnnotatedClientEndpointMetadata(container, testcase.pojo);
AnnotatedEndpointScanner<ClientEndpoint, ClientEndpointConfig> scanner = new AnnotatedEndpointScanner<>(metadata);
scanner.scan();
Assert.assertThat("Metadata", metadata, notNullValue());
JsrCallable cm = (JsrCallable) testcase.metadataField.get(metadata);
Assert.assertThat(testcase.metadataField.toString(), cm, notNullValue());
int len = testcase.expectedParameters.length;
for (int i = 0; i < len; i++) {
Class<?> expectedParam = testcase.expectedParameters[i];
Class<?> actualParam = cm.getParamTypes()[i];
Assert.assertTrue("Parameter[" + i + "] - expected:[" + expectedParam + "], actual:[" + actualParam + "]", actualParam.equals(expectedParam));
}
}
Aggregations