@Override public void register(ServerEndpointConfig serverConfig, String contextPath) throws DeploymentException { TyrusEndpointWrapper ew; Class<?> endpointClass = serverConfig.getEndpointClass(); boolean isEndpointClass = false; do { endpointClass = endpointClass.getSuperclass(); if (endpointClass.equals(Endpoint.class)) { isEndpointClass = true; } } while (!endpointClass.equals(Object.class)); if (isEndpointClass) { // we are pretty sure that endpoint class is javax.websocket.Endpoint descendant. //noinspection unchecked ew = new TyrusEndpointWrapper( (Class<? extends Endpoint>) serverConfig.getEndpointClass(), serverConfig, componentProviderService, webSocketContainer, contextPath, serverConfig.getConfigurator()); } else { final ErrorCollector collector = new ErrorCollector(); final AnnotatedEndpoint endpoint = AnnotatedEndpoint.fromClass( serverConfig.getEndpointClass(), componentProviderService, true, collector); final EndpointConfig config = endpoint.getEndpointConfig(); ew = new TyrusEndpointWrapper( endpoint, config, componentProviderService, webSocketContainer, contextPath, config instanceof ServerEndpointConfig ? ((ServerEndpointConfig) config).getConfigurator() : null); if (!collector.isEmpty()) { throw collector.composeComprehensiveException(); } } register(new TyrusEndpoint(ew)); }
/** * Published the provided endpoint implementation at the specified path with the specified * configuration. {@link #WsServerContainer(ServletContext)} must be called before calling this * method. * * @param sec The configuration to use when creating endpoint instances * @throws DeploymentException if the endpoint can not be published as requested */ @Override public void addEndpoint(ServerEndpointConfig sec) throws DeploymentException { if (enforceNoAddAfterHandshake && !addAllowed) { throw new DeploymentException(sm.getString("serverContainer.addNotAllowed")); } if (servletContext == null) { throw new DeploymentException(sm.getString("serverContainer.servletContextMissing")); } String path = sec.getPath(); UriTemplate uriTemplate = new UriTemplate(path); if (uriTemplate.hasParameters()) { Integer key = Integer.valueOf(uriTemplate.getSegmentCount()); SortedSet<TemplatePathMatch> templateMatches = configTemplateMatchMap.get(key); if (templateMatches == null) { // Ensure that if concurrent threads execute this block they // both end up using the same TreeSet instance templateMatches = new TreeSet<>(TemplatePathMatchComparator.getInstance()); configTemplateMatchMap.putIfAbsent(key, templateMatches); templateMatches = configTemplateMatchMap.get(key); } if (!templateMatches.add(new TemplatePathMatch(sec, uriTemplate))) { // Duplicate uriTemplate; throw new DeploymentException( sm.getString( "serverContainer.duplicatePaths", path, sec.getEndpointClass(), sec.getEndpointClass())); } } else { // Exact match ServerEndpointConfig old = configExactMatchMap.put(path, sec); if (old != null) { // Duplicate path mappings throw new DeploymentException( sm.getString( "serverContainer.duplicatePaths", path, old.getEndpointClass(), sec.getEndpointClass())); } } endpointsRegistered = true; }
@Override public Class<?> getEndpointClass() { return delegate.getEndpointClass(); }