use of org.apache.tomcat.websocket.pojo.PojoEndpointClient in project tomcat70 by apache.
the class WsWebSocketContainer method connectToServer.
@Override
public Session connectToServer(Object pojo, URI path) throws DeploymentException {
ClientEndpoint annotation = pojo.getClass().getAnnotation(ClientEndpoint.class);
if (annotation == null) {
throw new DeploymentException(sm.getString("wsWebSocketContainer.missingAnnotation", pojo.getClass().getName()));
}
Endpoint ep = new PojoEndpointClient(pojo, Arrays.asList(annotation.decoders()));
Class<? extends ClientEndpointConfig.Configurator> configuratorClazz = annotation.configurator();
ClientEndpointConfig.Configurator configurator = null;
if (!ClientEndpointConfig.Configurator.class.equals(configuratorClazz)) {
try {
configurator = configuratorClazz.newInstance();
} catch (InstantiationException e) {
throw new DeploymentException(sm.getString("wsWebSocketContainer.defaultConfiguratorFail"), e);
} catch (IllegalAccessException e) {
throw new DeploymentException(sm.getString("wsWebSocketContainer.defaultConfiguratorFail"), e);
}
}
ClientEndpointConfig.Builder builder = ClientEndpointConfig.Builder.create();
// Avoid NPE when using RI API JAR - see BZ 56343
if (configurator != null) {
builder.configurator(configurator);
}
ClientEndpointConfig config = builder.decoders(Arrays.asList(annotation.decoders())).encoders(Arrays.asList(annotation.encoders())).preferredSubprotocols(Arrays.asList(annotation.subprotocols())).build();
return connectToServer(ep, config, path);
}
use of org.apache.tomcat.websocket.pojo.PojoEndpointClient in project tomcat by apache.
the class TesterWsClientAutobahn method executeTestCase.
private static void executeTestCase(WebSocketContainer wsc, int testCase) throws Exception {
URI uri = new URI("ws://" + HOST + ":" + PORT + "/runCase?case=" + testCase + "&agent=" + USER_AGENT);
TestCaseClient testCaseClient = new TestCaseClient();
Extension permessageDeflate = new WsExtension("permessage-deflate");
// Advertise support for client_max_window_bits
// Client only supports some values so there will be some failures here
// Note Autobahn returns a 400 response if you provide a value for
// client_max_window_bits
permessageDeflate.getParameters().add(new WsExtensionParameter("client_max_window_bits", null));
List<Extension> extensions = new ArrayList<>(1);
extensions.add(permessageDeflate);
Endpoint ep = new PojoEndpointClient(testCaseClient, null, null);
ClientEndpointConfig.Builder builder = ClientEndpointConfig.Builder.create();
ClientEndpointConfig config = builder.extensions(extensions).build();
wsc.connectToServer(ep, config, uri);
testCaseClient.waitForClose();
}
Aggregations