@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, annotation.decoders());
Class<? extends ClientEndpointConfig.Configurator> configuratorClazz =
pojo.getClass().getAnnotation(
ClientEndpoint.class).configurator();
ClientEndpointConfig.Configurator configurator = null;
if (!ClientEndpointConfig.Configurator.class.equals(
configuratorClazz)) {
try {
configurator = configuratorClazz.newInstance();
} catch (InstantiationException | 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())).
build();
return connectToServer(ep, config, path);
}