tyrus
  1. tyrus
  2. TYRUS-245

ServerEndpointConfig#getConfiigurator returns Configurator not used when getNegotiatedExtensions has been called.

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Works as designed
    • Affects Version/s: 1.2.1
    • Fix Version/s: 1.3
    • Component/s: server
    • Labels:
      None

      Description

      In the following code, configurator.resulted() is null in WSCExtensionsServer#onMessage(), but it has been set in configurator

      public class AppConfig implements ServerApplicationConfig {
      
      	@Override
      	public Set<ServerEndpointConfig> getEndpointConfigs(
      			Set<Class<? extends Endpoint>> endpointClasses) {
      		Set<ServerEndpointConfig> set = new HashSet<ServerEndpointConfig>();
      		set.add(new ExtensionsServerEndpointConfig());
      		return set;
      	}
      
      	@Override
      	public Set<Class<?>> getAnnotatedEndpointClasses(Set<Class<?>> scanned) {
      		Set<Class<?>> set = new HashSet<Class<?>>();
      		return set;
      	}
      }
      
      public class ExtensionsConfigurator extends Configurator {
      	List<Extension> resulted;
      
      	@Override
      	public List<Extension> getNegotiatedExtensions(List<Extension> installed,
      			List<Extension> requested) {
      		List<Extension> resulted = super.getNegotiatedExtensions(installed,
      				requested);
      		this.resulted = resulted;
      		return resulted;
      	}
      }
      
      public class ExtensionsServerEndpointConfig implements ServerEndpointConfig {
      
      	@Override
      	public Map<String, Object> getUserProperties() {
      		return Collections.emptyMap();
      	}
      
      	@Override
      	public Class<?> getEndpointClass() {
      		return WSCExtensionsServer.class;
      	}
      
      	@Override
      	public String getPath() {
      		return "/extensions";
      	}
      
      	@Override
      	public List<String> getSubprotocols() {
      		return Collections.emptyList();
      	}
      
      	@Override
      	public List<Extension> getExtensions() {		
      		return Collections.emptyList();
      	}
      
      	@Override
      	public Configurator getConfigurator() {
      		return new ExtensionsConfigurator();
      	}
      
      	@Override
      	public List<Class<? extends Encoder>> getEncoders() {
      		return Collections.emptyList();
      	}
      
      	@Override
      	public List<Class<? extends Decoder>> getDecoders() {
      		return Collections.emptyList();
      	}
      
      }
      
      public class WSCExtensionsServer extends Endpoint implements
      		MessageHandler.Whole<String> {
      
      	private Session session;
      	private ServerEndpointConfig config;
      	private ExtensionsConfigurator configurator;
      
      	@Override
      	public void onMessage(String msg) {
      		try {
      			session.getBasicRemote().sendText(
      					String.valueOf(configurator.resulted == null));
      		} catch (IOException e1) {
      			e1.printStackTrace();
      		}
      	}
      
      	@Override
      	public void onOpen(Session session, EndpointConfig config) {
      		this.session = session;
      		this.config = (ServerEndpointConfig) config;
      		session.addMessageHandler(this);
      		configurator = (ExtensionsConfigurator) this.config.getConfigurator();
      	}
      
      	@Override
      	public void onError(Session session, Throwable thr) {
      		thr.printStackTrace(); // Write to error log, too
      		String message = IOUtil.printStackTrace(thr);
      		try {
      			session.getBasicRemote().sendText(message);
      		} catch (IOException e) {
      			e.printStackTrace();
      		}
      	}
      }
      
      

        Activity

        Hide
        stepan.kopriva added a comment -

        In ExtensionsServerEndpointConfigclass, the method

        @Override
        public Configurator getConfigurator()

        { return new ExtensionsConfigurator(); }

        returns new Configurator instance each time it is called. This is why your sample is not working.

        Show
        stepan.kopriva added a comment - In ExtensionsServerEndpointConfigclass, the method @Override public Configurator getConfigurator() { return new ExtensionsConfigurator(); } returns new Configurator instance each time it is called. This is why your sample is not working.

          People

          • Assignee:
            stepan.kopriva
            Reporter:
            jan.supol
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: