org.springframework.web.socket.adapter.jetty.WebSocketToJettyExtensionConfigAdapter Java Examples

The following examples show how to use org.springframework.web.socket.adapter.jetty.WebSocketToJettyExtensionConfigAdapter. 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: JettyWebSocketClient.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public ListenableFuture<WebSocketSession> doHandshakeInternal(WebSocketHandler wsHandler,
		HttpHeaders headers, final URI uri, List<String> protocols,
		List<WebSocketExtension> extensions,  Map<String, Object> attributes) {

	final ClientUpgradeRequest request = new ClientUpgradeRequest();
	request.setSubProtocols(protocols);

	for (WebSocketExtension e : extensions) {
		request.addExtensions(new WebSocketToJettyExtensionConfigAdapter(e));
	}

	headers.forEach(request::setHeader);

	Principal user = getUser();
	final JettyWebSocketSession wsSession = new JettyWebSocketSession(attributes, user);
	final JettyWebSocketHandlerAdapter listener = new JettyWebSocketHandlerAdapter(wsHandler, wsSession);

	Callable<WebSocketSession> connectTask = () -> {
		Future<Session> future = this.client.connect(listener, uri, request);
		future.get();
		return wsSession;
	};

	if (this.taskExecutor != null) {
		return this.taskExecutor.submitListenable(connectTask);
	}
	else {
		ListenableFutureTask<WebSocketSession> task = new ListenableFutureTask<>(connectTask);
		task.run();
		return task;
	}
}
 
Example #2
Source File: JettyRequestUpgradeStrategy.java    From spring-analysis-note with MIT License 5 votes vote down vote up
public WebSocketHandlerContainer(
		JettyWebSocketHandlerAdapter handler, String protocol, List<WebSocketExtension> extensions) {

	this.handler = handler;
	this.selectedProtocol = protocol;
	if (CollectionUtils.isEmpty(extensions)) {
		this.extensionConfigs = new ArrayList<>(0);
	}
	else {
		this.extensionConfigs = new ArrayList<>(extensions.size());
		for (WebSocketExtension extension : extensions) {
			this.extensionConfigs.add(new WebSocketToJettyExtensionConfigAdapter(extension));
		}
	}
}
 
Example #3
Source File: JettyWebSocketClient.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public ListenableFuture<WebSocketSession> doHandshakeInternal(WebSocketHandler wsHandler,
		HttpHeaders headers, final URI uri, List<String> protocols,
		List<WebSocketExtension> extensions,  Map<String, Object> attributes) {

	final ClientUpgradeRequest request = new ClientUpgradeRequest();
	request.setSubProtocols(protocols);

	for (WebSocketExtension e : extensions) {
		request.addExtensions(new WebSocketToJettyExtensionConfigAdapter(e));
	}

	headers.forEach(request::setHeader);

	Principal user = getUser();
	final JettyWebSocketSession wsSession = new JettyWebSocketSession(attributes, user);
	final JettyWebSocketHandlerAdapter listener = new JettyWebSocketHandlerAdapter(wsHandler, wsSession);

	Callable<WebSocketSession> connectTask = () -> {
		Future<Session> future = this.client.connect(listener, uri, request);
		future.get();
		return wsSession;
	};

	if (this.taskExecutor != null) {
		return this.taskExecutor.submitListenable(connectTask);
	}
	else {
		ListenableFutureTask<WebSocketSession> task = new ListenableFutureTask<>(connectTask);
		task.run();
		return task;
	}
}
 
Example #4
Source File: JettyRequestUpgradeStrategy.java    From java-technology-stack with MIT License 5 votes vote down vote up
public WebSocketHandlerContainer(
		JettyWebSocketHandlerAdapter handler, String protocol, List<WebSocketExtension> extensions) {

	this.handler = handler;
	this.selectedProtocol = protocol;
	if (CollectionUtils.isEmpty(extensions)) {
		this.extensionConfigs = new ArrayList<>(0);
	}
	else {
		this.extensionConfigs = new ArrayList<>(extensions.size());
		for (WebSocketExtension extension : extensions) {
			this.extensionConfigs.add(new WebSocketToJettyExtensionConfigAdapter(extension));
		}
	}
}
 
Example #5
Source File: JettyWebSocketClient.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public ListenableFuture<WebSocketSession> doHandshakeInternal(WebSocketHandler wsHandler,
		HttpHeaders headers, final URI uri, List<String> protocols,
		List<WebSocketExtension> extensions,  Map<String, Object> attributes) {

	final ClientUpgradeRequest request = new ClientUpgradeRequest();
	request.setSubProtocols(protocols);

	for (WebSocketExtension e : extensions) {
		request.addExtensions(new WebSocketToJettyExtensionConfigAdapter(e));
	}

	for (String header : headers.keySet()) {
		request.setHeader(header, headers.get(header));
	}

	Principal user = getUser();
	final JettyWebSocketSession wsSession = new JettyWebSocketSession(attributes, user);
	final JettyWebSocketHandlerAdapter listener = new JettyWebSocketHandlerAdapter(wsHandler, wsSession);

	Callable<WebSocketSession> connectTask = new Callable<WebSocketSession>() {
		@Override
		public WebSocketSession call() throws Exception {
			Future<Session> future = client.connect(listener, uri, request);
			future.get();
			return wsSession;
		}
	};

	if (this.taskExecutor != null) {
		return this.taskExecutor.submitListenable(connectTask);
	}
	else {
		ListenableFutureTask<WebSocketSession> task = new ListenableFutureTask<WebSocketSession>(connectTask);
		task.run();
		return task;
	}
}
 
Example #6
Source File: JettyRequestUpgradeStrategy.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
public WebSocketHandlerContainer(JettyWebSocketHandlerAdapter handler, String protocol, List<WebSocketExtension> extensions) {
	this.handler = handler;
	this.selectedProtocol = protocol;
	if (CollectionUtils.isEmpty(extensions)) {
		this.extensionConfigs = null;
	}
	else {
		this.extensionConfigs = new ArrayList<ExtensionConfig>();
		for (WebSocketExtension e : extensions) {
			this.extensionConfigs.add(new WebSocketToJettyExtensionConfigAdapter(e));
		}
	}
}