[TYRUS-245] ServerEndpointConfig#getConfiigurator returns Configurator not used when getNegotiatedExtensions has been called. Created: 28/Aug/13  Updated: 29/Aug/13  Resolved: 29/Aug/13

Status: Resolved
Project: tyrus
Component/s: server
Affects Version/s: 1.2.1
Fix Version/s: 1.3

Type: Bug Priority: Major
Reporter: jan.supol Assignee: stepan.kopriva
Resolution: Works as designed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


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



 Comments   
Comment by stepan.kopriva [ 29/Aug/13 ]

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.

Generated at Tue Jun 30 20:49:15 UTC 2015 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.