tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Christopher Dodunski" <ChrisFromSquir...@christopher.net.nz>
Subject Re: Using custom Configurator with WebSockets
Date Fri, 26 Apr 2019 10:07:38 GMT
So I've converted the server endpoint from annotation-based to
programmatic, to get around the constraint of the @ServerEndpoint
annotation having to decorate a concrete class.  The elements of this
annotation now occupy an implementation of ServerApplicationConfig:


public class HarbourServerApplicationConfig implements
ServerApplicationConfig {

    ...

    @Override
    public Set<ServerEndpointConfig> getEndpointConfigs(Set<Class<?
extends Endpoint>> endpointClasses) {
        Set<ServerEndpointConfig> result = new HashSet<>();
        ServerEndpointConfig configuration =
ServerEndpointConfig.Builder.create(HarbourServerEndpoint.class,
"/websocket/{port-name}/{username}")
                .configurator(configurator)
                .encoders(encoders)
                .decoders(decoders)
                .build();
        result.add(configuration);

        return result;
    }
}


All works fine when the Builder.create() parameter is a concrete endpoint
class, but not if an interface (the goal is having Tomcat accept as
endpoint instances IoC proxy objects cast back to their interface).

The error message suggests that Tomcat is treating this class as concrete.


26-Apr-2019 20:00:40.605 SEVERE [ajp-nio-127.0.0.1-8009-exec-197]
org.apache.catalina.core.ContainerBase.addChildInternal
ContainerBase.addChild: start:
 org.apache.catalina.LifecycleException: Failed to start component
[StandardEngine[Catalina].StandardHost[localhost].StandardContext[/harbour]]
        at
org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167)
        at
org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:754)
        at
org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:730)
        at
org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)
        at
org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:985)
...
Caused by: java.lang.NullPointerException
        at
org.apache.tomcat.websocket.pojo.PojoMethodMapping.<init>(PojoMethodMapping.java:85)
        at
org.apache.tomcat.websocket.server.WsServerContainer.addEndpoint(WsServerContainer.java:147)
        at org.apache.tomcat.websocket.server.WsSci.onStartup(WsSci.java:116)
        at
org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5245)
        at
org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
        ... 46 more


Lastly, below is the interface itself (my programmatic endpoint implements
this).


public interface HarbourServerEndpoint {

    void onOpen(Session session, EndpointConfig config);

    void onMessageMessage(Session session, Message message);

    void onClose(Session session, CloseReason reason);

    void onError(Session session, Throwable throwable);
}


Unfortunately online examples of programmatic endpoints are sparse, and
the few to be found very basic.  So am quite reliant on those familiar
with the WebSocket library, and Tomcat's application of it.

Kind regards,

Chris.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message