org.glassfish.tyrus.core.TyrusWebSocketEngine Java Examples

The following examples show how to use org.glassfish.tyrus.core.TyrusWebSocketEngine. 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: AbstractTyrusRequestUpgradeStrategy.java    From java-technology-stack with MIT License 6 votes vote down vote up
private Object createEndpoint(ServerEndpointRegistration registration, ComponentProviderService provider,
		WebSocketContainer container, TyrusWebSocketEngine engine) throws DeploymentException {

	DirectFieldAccessor accessor = new DirectFieldAccessor(engine);
	Object sessionListener = accessor.getPropertyValue("sessionListener");
	Object clusterContext = accessor.getPropertyValue("clusterContext");
	try {
		if (constructorWithBooleanArgument) {
			// Tyrus 1.11+
			return constructor.newInstance(registration.getEndpoint(), registration, provider, container,
					"/", registration.getConfigurator(), sessionListener, clusterContext, null, Boolean.TRUE);
		}
		else {
			return constructor.newInstance(registration.getEndpoint(), registration, provider, container,
					"/", registration.getConfigurator(), sessionListener, clusterContext, null);
		}
	}
	catch (Exception ex) {
		throw new HandshakeFailureException("Failed to register " + registration, ex);
	}
}
 
Example #2
Source File: AbstractTyrusRequestUpgradeStrategy.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Override
public Object createdEndpoint(ServerEndpointRegistration registration, ComponentProviderService provider,
		WebSocketContainer container, TyrusWebSocketEngine engine) throws DeploymentException {

	DirectFieldAccessor accessor = new DirectFieldAccessor(engine);
	Object sessionListener = accessor.getPropertyValue("sessionListener");
	Object clusterContext = accessor.getPropertyValue("clusterContext");
	try {
		if (constructorWithBooleanArgument) {
			// Tyrus 1.11+
			return constructor.newInstance(registration.getEndpoint(), registration, provider, container,
					"/", registration.getConfigurator(), sessionListener, clusterContext, null, Boolean.TRUE);
		}
		else {
			return constructor.newInstance(registration.getEndpoint(), registration, provider, container,
					"/", registration.getConfigurator(), sessionListener, clusterContext, null);
		}
	}
	catch (Exception ex) {
		throw new HandshakeFailureException("Failed to register " + registration, ex);
	}
}
 
Example #3
Source File: AbstractTyrusRequestUpgradeStrategy.java    From spring-analysis-note with MIT License 6 votes vote down vote up
private Object createEndpoint(ServerEndpointRegistration registration, ComponentProviderService provider,
		WebSocketContainer container, TyrusWebSocketEngine engine) throws DeploymentException {

	DirectFieldAccessor accessor = new DirectFieldAccessor(engine);
	Object sessionListener = accessor.getPropertyValue("sessionListener");
	Object clusterContext = accessor.getPropertyValue("clusterContext");
	try {
		if (constructorWithBooleanArgument) {
			// Tyrus 1.11+
			return constructor.newInstance(registration.getEndpoint(), registration, provider, container,
					"/", registration.getConfigurator(), sessionListener, clusterContext, null, Boolean.TRUE);
		}
		else {
			return constructor.newInstance(registration.getEndpoint(), registration, provider, container,
					"/", registration.getConfigurator(), sessionListener, clusterContext, null);
		}
	}
	catch (Exception ex) {
		throw new HandshakeFailureException("Failed to register " + registration, ex);
	}
}
 
Example #4
Source File: AbstractTyrusRequestUpgradeStrategy.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private void unregisterTyrusEndpoint(TyrusWebSocketEngine engine, @Nullable Object tyrusEndpoint) {
	if (tyrusEndpoint != null) {
		try {
			unregister(engine, tyrusEndpoint);
		}
		catch (Throwable ex) {
			// ignore
		}
	}
}
 
Example #5
Source File: AbstractTyrusRequestUpgradeStrategy.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private void register(TyrusWebSocketEngine engine, Object endpoint) {
	try {
		registerMethod.invoke(engine, endpoint);
	}
	catch (Exception ex) {
		throw new HandshakeFailureException("Failed to register " + endpoint, ex);
	}
}
 
Example #6
Source File: AbstractTyrusRequestUpgradeStrategy.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private void unregister(TyrusWebSocketEngine engine, Object endpoint) {
	try {
		unRegisterMethod.invoke(engine, endpoint);
	}
	catch (Exception ex) {
		throw new HandshakeFailureException("Failed to unregister " + endpoint, ex);
	}
}
 
Example #7
Source File: AbstractTyrusRequestUpgradeStrategy.java    From java-technology-stack with MIT License 5 votes vote down vote up
private Object createTyrusEndpoint(Endpoint endpoint, String endpointPath, @Nullable String protocol,
		List<Extension> extensions, WebSocketContainer container, TyrusWebSocketEngine engine)
		throws DeploymentException {

	ServerEndpointRegistration endpointConfig = new ServerEndpointRegistration(endpointPath, endpoint);
	endpointConfig.setSubprotocols(Collections.singletonList(protocol));
	endpointConfig.setExtensions(extensions);
	return createEndpoint(endpointConfig, this.componentProvider, container, engine);
}
 
Example #8
Source File: AbstractTyrusRequestUpgradeStrategy.java    From java-technology-stack with MIT License 5 votes vote down vote up
private void unregisterTyrusEndpoint(TyrusWebSocketEngine engine, @Nullable Object tyrusEndpoint) {
	if (tyrusEndpoint != null) {
		try {
			unregister(engine, tyrusEndpoint);
		}
		catch (Throwable ex) {
			// ignore
		}
	}
}
 
Example #9
Source File: AbstractTyrusRequestUpgradeStrategy.java    From java-technology-stack with MIT License 5 votes vote down vote up
private void register(TyrusWebSocketEngine engine, Object endpoint) {
	try {
		registerMethod.invoke(engine, endpoint);
	}
	catch (Exception ex) {
		throw new HandshakeFailureException("Failed to register " + endpoint, ex);
	}
}
 
Example #10
Source File: AbstractTyrusRequestUpgradeStrategy.java    From java-technology-stack with MIT License 5 votes vote down vote up
private void unregister(TyrusWebSocketEngine engine, Object endpoint) {
	try {
		unRegisterMethod.invoke(engine, endpoint);
	}
	catch (Exception ex) {
		throw new HandshakeFailureException("Failed to unregister " + endpoint, ex);
	}
}
 
Example #11
Source File: AbstractTyrusRequestUpgradeStrategy.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public void register(TyrusWebSocketEngine engine, Object endpoint) {
	try {
		registerMethod.invoke(engine, endpoint);
	}
	catch (Exception ex) {
		throw new HandshakeFailureException("Failed to register " + endpoint, ex);
	}
}
 
Example #12
Source File: AbstractTyrusRequestUpgradeStrategy.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
private Object createTyrusEndpoint(Endpoint endpoint, String endpointPath, String protocol,
		List<Extension> extensions, WebSocketContainer container, TyrusWebSocketEngine engine)
		throws DeploymentException {

	ServerEndpointRegistration endpointConfig = new ServerEndpointRegistration(endpointPath, endpoint);
	endpointConfig.setSubprotocols(Collections.singletonList(protocol));
	endpointConfig.setExtensions(extensions);
	return getEndpointHelper().createdEndpoint(endpointConfig, this.componentProvider, container, engine);
}
 
Example #13
Source File: AbstractTyrusRequestUpgradeStrategy.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
private void unregisterTyrusEndpoint(TyrusWebSocketEngine engine, Object tyrusEndpoint) {
	if (tyrusEndpoint != null) {
		try {
			getEndpointHelper().unregister(engine, tyrusEndpoint);
		}
		catch (Throwable ex) {
			// ignore
		}
	}
}
 
Example #14
Source File: AbstractTyrusRequestUpgradeStrategy.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public Object createdEndpoint(ServerEndpointRegistration registration, ComponentProviderService provider,
		WebSocketContainer container, TyrusWebSocketEngine engine) throws DeploymentException {

	TyrusEndpointWrapper endpointWrapper = new TyrusEndpointWrapper(registration.getEndpoint(),
			registration, provider, container, "/", registration.getConfigurator());

	return new TyrusEndpoint(endpointWrapper);
}
 
Example #15
Source File: AbstractTyrusRequestUpgradeStrategy.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public void unregister(TyrusWebSocketEngine engine, Object endpoint) {
	try {
		unRegisterMethod.invoke(engine, endpoint);
	}
	catch (Exception ex) {
		throw new HandshakeFailureException("Failed to unregister " + endpoint, ex);
	}
}
 
Example #16
Source File: AbstractTyrusRequestUpgradeStrategy.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public void register(TyrusWebSocketEngine engine, Object endpoint) {
	try {
		registerMethod.invoke(engine, endpoint);
	}
	catch (Exception ex) {
		throw new HandshakeFailureException("Failed to register " + endpoint, ex);
	}
}
 
Example #17
Source File: AbstractTyrusRequestUpgradeStrategy.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private Object createTyrusEndpoint(Endpoint endpoint, String endpointPath, @Nullable String protocol,
		List<Extension> extensions, WebSocketContainer container, TyrusWebSocketEngine engine)
		throws DeploymentException {

	ServerEndpointRegistration endpointConfig = new ServerEndpointRegistration(endpointPath, endpoint);
	endpointConfig.setSubprotocols(Collections.singletonList(protocol));
	endpointConfig.setExtensions(extensions);
	return createEndpoint(endpointConfig, this.componentProvider, container, engine);
}
 
Example #18
Source File: AbstractTyrusRequestUpgradeStrategy.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
public void upgradeInternal(ServerHttpRequest request, ServerHttpResponse response,
		@Nullable String selectedProtocol, List<Extension> extensions, Endpoint endpoint)
		throws HandshakeFailureException {

	HttpServletRequest servletRequest = getHttpServletRequest(request);
	HttpServletResponse servletResponse = getHttpServletResponse(response);

	TyrusServerContainer serverContainer = (TyrusServerContainer) getContainer(servletRequest);
	TyrusWebSocketEngine engine = (TyrusWebSocketEngine) serverContainer.getWebSocketEngine();
	Object tyrusEndpoint = null;
	boolean success;

	try {
		// Shouldn't matter for processing but must be unique
		String path = "/" + random.nextLong();
		tyrusEndpoint = createTyrusEndpoint(endpoint, path, selectedProtocol, extensions, serverContainer, engine);
		register(engine, tyrusEndpoint);

		HttpHeaders headers = request.getHeaders();
		RequestContext requestContext = createRequestContext(servletRequest, path, headers);
		TyrusUpgradeResponse upgradeResponse = new TyrusUpgradeResponse();
		UpgradeInfo upgradeInfo = engine.upgrade(requestContext, upgradeResponse);
		success = SUCCESS.equals(upgradeInfo.getStatus());
		if (success) {
			if (logger.isTraceEnabled()) {
				logger.trace("Successful request upgrade: " + upgradeResponse.getHeaders());
			}
			handleSuccess(servletRequest, servletResponse, upgradeInfo, upgradeResponse);
		}
	}
	catch (Exception ex) {
		unregisterTyrusEndpoint(engine, tyrusEndpoint);
		throw new HandshakeFailureException("Error during handshake: " + request.getURI(), ex);
	}

	unregisterTyrusEndpoint(engine, tyrusEndpoint);
	if (!success) {
		throw new HandshakeFailureException("Unexpected handshake failure: " + request.getURI());
	}
}
 
Example #19
Source File: AbstractTyrusRequestUpgradeStrategy.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
public void unregister(TyrusWebSocketEngine engine, Object endpoint) {
	engine.unregister((TyrusEndpoint) endpoint);
}
 
Example #20
Source File: AbstractTyrusRequestUpgradeStrategy.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
Object createdEndpoint(ServerEndpointRegistration registration, ComponentProviderService provider,
WebSocketContainer container, TyrusWebSocketEngine engine) throws DeploymentException;
 
Example #21
Source File: AbstractTyrusRequestUpgradeStrategy.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
public void upgradeInternal(ServerHttpRequest request, ServerHttpResponse response,
		String selectedProtocol, List<Extension> extensions, Endpoint endpoint)
		throws HandshakeFailureException {

	HttpServletRequest servletRequest = getHttpServletRequest(request);
	HttpServletResponse servletResponse = getHttpServletResponse(response);

	TyrusServerContainer serverContainer = (TyrusServerContainer) getContainer(servletRequest);
	TyrusWebSocketEngine engine = (TyrusWebSocketEngine) serverContainer.getWebSocketEngine();
	Object tyrusEndpoint = null;
	boolean success;

	try {
		// Shouldn't matter for processing but must be unique
		String path = "/" + random.nextLong();
		tyrusEndpoint = createTyrusEndpoint(endpoint, path, selectedProtocol, extensions, serverContainer, engine);
		getEndpointHelper().register(engine, tyrusEndpoint);

		HttpHeaders headers = request.getHeaders();
		RequestContext requestContext = createRequestContext(servletRequest, path, headers);
		TyrusUpgradeResponse upgradeResponse = new TyrusUpgradeResponse();
		UpgradeInfo upgradeInfo = engine.upgrade(requestContext, upgradeResponse);
		success = SUCCESS.equals(upgradeInfo.getStatus());
		if (success) {
			if (logger.isTraceEnabled()) {
				logger.trace("Successful request upgrade: " + upgradeResponse.getHeaders());
			}
			handleSuccess(servletRequest, servletResponse, upgradeInfo, upgradeResponse);
		}
	}
	catch (Exception ex) {
		unregisterTyrusEndpoint(engine, tyrusEndpoint);
		throw new HandshakeFailureException("Error during handshake: " + request.getURI(), ex);
	}

	unregisterTyrusEndpoint(engine, tyrusEndpoint);
	if (!success) {
		throw new HandshakeFailureException("Unexpected handshake failure: " + request.getURI());
	}
}
 
Example #22
Source File: AbstractTyrusRequestUpgradeStrategy.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
public void upgradeInternal(ServerHttpRequest request, ServerHttpResponse response,
		@Nullable String selectedProtocol, List<Extension> extensions, Endpoint endpoint)
		throws HandshakeFailureException {

	HttpServletRequest servletRequest = getHttpServletRequest(request);
	HttpServletResponse servletResponse = getHttpServletResponse(response);

	TyrusServerContainer serverContainer = (TyrusServerContainer) getContainer(servletRequest);
	TyrusWebSocketEngine engine = (TyrusWebSocketEngine) serverContainer.getWebSocketEngine();
	Object tyrusEndpoint = null;
	boolean success;

	try {
		// Shouldn't matter for processing but must be unique
		String path = "/" + random.nextLong();
		tyrusEndpoint = createTyrusEndpoint(endpoint, path, selectedProtocol, extensions, serverContainer, engine);
		register(engine, tyrusEndpoint);

		HttpHeaders headers = request.getHeaders();
		RequestContext requestContext = createRequestContext(servletRequest, path, headers);
		TyrusUpgradeResponse upgradeResponse = new TyrusUpgradeResponse();
		UpgradeInfo upgradeInfo = engine.upgrade(requestContext, upgradeResponse);
		success = SUCCESS.equals(upgradeInfo.getStatus());
		if (success) {
			if (logger.isTraceEnabled()) {
				logger.trace("Successful request upgrade: " + upgradeResponse.getHeaders());
			}
			handleSuccess(servletRequest, servletResponse, upgradeInfo, upgradeResponse);
		}
	}
	catch (Exception ex) {
		unregisterTyrusEndpoint(engine, tyrusEndpoint);
		throw new HandshakeFailureException("Error during handshake: " + request.getURI(), ex);
	}

	unregisterTyrusEndpoint(engine, tyrusEndpoint);
	if (!success) {
		throw new HandshakeFailureException("Unexpected handshake failure: " + request.getURI());
	}
}
 
Example #23
Source File: AbstractTyrusRequestUpgradeStrategy.java    From spring4-understanding with Apache License 2.0 votes vote down vote up
void unregister(TyrusWebSocketEngine engine, Object endpoint); 
Example #24
Source File: AbstractTyrusRequestUpgradeStrategy.java    From spring4-understanding with Apache License 2.0 votes vote down vote up
void register(TyrusWebSocketEngine engine, Object endpoint);