org.apache.tomcat.websocket.pojo.PojoEndpointServer Java Examples

The following examples show how to use org.apache.tomcat.websocket.pojo.PojoEndpointServer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WsServerContainer.java    From Tomcat7.0.67 with Apache License 2.0 4 votes vote down vote up
/**
 * 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
 */
@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();

    // Add method mapping to user properties
    PojoMethodMapping methodMapping = new PojoMethodMapping(sec.getEndpointClass(),
            sec.getDecoders(), path);
    if (methodMapping.getOnClose() != null || methodMapping.getOnOpen() != null
            || methodMapping.getOnError() != null || methodMapping.hasMessageHandlers()) {
        sec.getUserProperties().put(
                PojoEndpointServer.POJO_METHOD_MAPPING_KEY,
                methodMapping);
    }

    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<TemplatePathMatch>(
                    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;
}
 
Example #2
Source File: WsServerContainer.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
/**
 * 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
 */
@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();

    // Add method mapping to user properties
    PojoMethodMapping methodMapping = new PojoMethodMapping(sec.getEndpointClass(),
            sec.getDecoders(), path);
    if (methodMapping.getOnClose() != null || methodMapping.getOnOpen() != null
            || methodMapping.getOnError() != null || methodMapping.hasMessageHandlers()) {
        sec.getUserProperties().put(
                PojoEndpointServer.POJO_METHOD_MAPPING_KEY,
                methodMapping);
    }

    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<TemplatePathMatch>(
                    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;
}