org.glassfish.tyrus.core.TyrusUpgradeResponse Java Examples

The following examples show how to use org.glassfish.tyrus.core.TyrusUpgradeResponse. 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: WebLogicRequestUpgradeStrategy.java    From spring-analysis-note with MIT License 8 votes vote down vote up
@Override
protected void handleSuccess(HttpServletRequest request, HttpServletResponse response,
		UpgradeInfo upgradeInfo, TyrusUpgradeResponse upgradeResponse) throws IOException, ServletException {

	response.setStatus(upgradeResponse.getStatus());
	upgradeResponse.getHeaders().forEach((key, value) -> response.addHeader(key, Utils.getHeaderFromList(value)));

	AsyncContext asyncContext = request.startAsync();
	asyncContext.setTimeout(-1L);

	Object nativeRequest = getNativeRequest(request);
	BeanWrapper beanWrapper = new BeanWrapperImpl(nativeRequest);
	Object httpSocket = beanWrapper.getPropertyValue("connection.connectionHandler.rawConnection");
	Object webSocket = webSocketHelper.newInstance(request, httpSocket);
	webSocketHelper.upgrade(webSocket, httpSocket, request.getServletContext());

	response.flushBuffer();

	boolean isProtected = request.getUserPrincipal() != null;
	Writer servletWriter = servletWriterHelper.newInstance(webSocket, isProtected);
	Connection connection = upgradeInfo.createConnection(servletWriter, noOpCloseListener);
	new BeanWrapperImpl(webSocket).setPropertyValue("connection", connection);
	new BeanWrapperImpl(servletWriter).setPropertyValue("connection", connection);
	webSocketHelper.registerForReadEvent(webSocket);
}
 
Example #2
Source File: WebLogicRequestUpgradeStrategy.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Override
protected void handleSuccess(HttpServletRequest request, HttpServletResponse response,
		UpgradeInfo upgradeInfo, TyrusUpgradeResponse upgradeResponse) throws IOException, ServletException {

	response.setStatus(upgradeResponse.getStatus());
	upgradeResponse.getHeaders().forEach((key, value) -> response.addHeader(key, Utils.getHeaderFromList(value)));

	AsyncContext asyncContext = request.startAsync();
	asyncContext.setTimeout(-1L);

	Object nativeRequest = getNativeRequest(request);
	BeanWrapper beanWrapper = new BeanWrapperImpl(nativeRequest);
	Object httpSocket = beanWrapper.getPropertyValue("connection.connectionHandler.rawConnection");
	Object webSocket = webSocketHelper.newInstance(request, httpSocket);
	webSocketHelper.upgrade(webSocket, httpSocket, request.getServletContext());

	response.flushBuffer();

	boolean isProtected = request.getUserPrincipal() != null;
	Writer servletWriter = servletWriterHelper.newInstance(webSocket, isProtected);
	Connection connection = upgradeInfo.createConnection(servletWriter, noOpCloseListener);
	new BeanWrapperImpl(webSocket).setPropertyValue("connection", connection);
	new BeanWrapperImpl(servletWriter).setPropertyValue("connection", connection);
	webSocketHelper.registerForReadEvent(webSocket);
}
 
Example #3
Source File: GlassFishRequestUpgradeStrategy.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
protected void handleSuccess(HttpServletRequest request, HttpServletResponse response,
		UpgradeInfo upgradeInfo, TyrusUpgradeResponse upgradeResponse) throws IOException, ServletException {

	TyrusHttpUpgradeHandler handler = request.upgrade(TyrusHttpUpgradeHandler.class);
	Writer servletWriter = newServletWriter(handler);
	handler.preInit(upgradeInfo, servletWriter, request.getUserPrincipal() != null);

	response.setStatus(upgradeResponse.getStatus());
	upgradeResponse.getHeaders().forEach((key, value) -> response.addHeader(key, Utils.getHeaderFromList(value)));
	response.flushBuffer();
}
 
Example #4
Source File: GlassFishRequestUpgradeStrategy.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
protected void handleSuccess(HttpServletRequest request, HttpServletResponse response,
		UpgradeInfo upgradeInfo, TyrusUpgradeResponse upgradeResponse) throws IOException, ServletException {

	TyrusHttpUpgradeHandler handler = request.upgrade(TyrusHttpUpgradeHandler.class);
	Writer servletWriter = newServletWriter(handler);
	handler.preInit(upgradeInfo, servletWriter, request.getUserPrincipal() != null);

	response.setStatus(upgradeResponse.getStatus());
	upgradeResponse.getHeaders().forEach((key, value) -> response.addHeader(key, Utils.getHeaderFromList(value)));
	response.flushBuffer();
}
 
Example #5
Source File: WebLogicRequestUpgradeStrategy.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
protected void handleSuccess(HttpServletRequest request, HttpServletResponse response,
		UpgradeInfo upgradeInfo, TyrusUpgradeResponse upgradeResponse) throws IOException, ServletException {

	response.setStatus(upgradeResponse.getStatus());
	for (Map.Entry<String, List<String>> entry : upgradeResponse.getHeaders().entrySet()) {
		response.addHeader(entry.getKey(), Utils.getHeaderFromList(entry.getValue()));
	}

	AsyncContext asyncContext = request.startAsync();
	asyncContext.setTimeout(-1L);

	Object nativeRequest = getNativeRequest(request);
	BeanWrapper beanWrapper = new BeanWrapperImpl(nativeRequest);
	Object httpSocket = beanWrapper.getPropertyValue("connection.connectionHandler.rawConnection");
	Object webSocket = webSocketHelper.newInstance(request, httpSocket);
	webSocketHelper.upgrade(webSocket, httpSocket, request.getServletContext());

	response.flushBuffer();

	boolean isProtected = request.getUserPrincipal() != null;
	Writer servletWriter = servletWriterHelper.newInstance(response, webSocket, isProtected);
	Connection connection = upgradeInfo.createConnection(servletWriter, noOpCloseListener);
	new BeanWrapperImpl(webSocket).setPropertyValue("connection", connection);
	new BeanWrapperImpl(servletWriter).setPropertyValue("connection", connection);
	webSocketHelper.registerForReadEvent(webSocket);
}
 
Example #6
Source File: GlassFishRequestUpgradeStrategy.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
protected void handleSuccess(HttpServletRequest request, HttpServletResponse response,
		UpgradeInfo upgradeInfo, TyrusUpgradeResponse upgradeResponse) throws IOException, ServletException {

	TyrusHttpUpgradeHandler handler = request.upgrade(TyrusHttpUpgradeHandler.class);
	Writer servletWriter = servletWriterHelper.newInstance(handler);
	handler.preInit(upgradeInfo, servletWriter, request.getUserPrincipal() != null);

	response.setStatus(upgradeResponse.getStatus());
	for (Map.Entry<String, List<String>> entry : upgradeResponse.getHeaders().entrySet()) {
		response.addHeader(entry.getKey(), Utils.getHeaderFromList(entry.getValue()));
	}
	response.flushBuffer();
}
 
Example #7
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 #8
Source File: AbstractTyrusRequestUpgradeStrategy.java    From spring-analysis-note with MIT License 4 votes vote down vote up
protected abstract void handleSuccess(HttpServletRequest request, HttpServletResponse response,
UpgradeInfo upgradeInfo, TyrusUpgradeResponse upgradeResponse) throws IOException, ServletException;
 
Example #9
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 #10
Source File: AbstractTyrusRequestUpgradeStrategy.java    From java-technology-stack with MIT License 4 votes vote down vote up
protected abstract void handleSuccess(HttpServletRequest request, HttpServletResponse response,
UpgradeInfo upgradeInfo, TyrusUpgradeResponse upgradeResponse) throws IOException, ServletException;
 
Example #11
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 #12
Source File: AbstractTyrusRequestUpgradeStrategy.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
protected abstract void handleSuccess(HttpServletRequest request, HttpServletResponse response,
UpgradeInfo upgradeInfo, TyrusUpgradeResponse upgradeResponse) throws IOException, ServletException;