0

Insprired by this thread I'm trying to do this:

@ServerEndpoint(... configurator = GetHttpSessionConfigurator.class)

without the @ServerEndpoint annotation but with this code:

ServerEndpointConfig endpointConfig = ServerEndpointConfig.Builder.create(MyHandler.class, uri).build();
javax.websocket.server.ServerContainer.addEndpoint(endpointConfig);

Since I couldn't find any "setConfigurator" methods, I checked the sources of ServerEndpointConfig and I found that the Configuration (..tor) is loaded by

 ServiceLoader.load(Configurator.class)

so, I created a meta-inf\services\javax.websocket.server.ServerEndpointConfig$Configurator file and added a single line to point to my GetHttpSessionConfigurator (as defined in 1) class. The file is loaded (I checked that with Process Monitor) but Tomcat's DefaultServerEndpointConfig is used.

Does anyone has an idea what's wrong with this setup?

Community
  • 1
  • 1
Peter Clause
  • 1,132
  • 9
  • 22

1 Answers1

0

Before your .build() you can put in a .configurator(new YourEndPointConfigurator())

So for your code you can do something like:

ServerEndpointConfig endpointConfig = ServerEndpointConfig.Builder
  .create(MyHandler.class, uri)
  .configurator(new ChatServerEndPointConfigurator(new GetHttpSessionConfigurator())
  .build();

More information can be found in ServerEndpointConfig.Builder docs.

errordeveloper
  • 6,716
  • 6
  • 41
  • 54
JoeyHolloway
  • 458
  • 7
  • 19