Search in sources :

Example 1 with Writer

use of org.glassfish.tyrus.spi.Writer in project spring-framework by spring-projects.

the class WebLogicRequestUpgradeStrategy method handleSuccess.

@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);
}
Also used : BeanWrapper(org.springframework.beans.BeanWrapper) BeanWrapperImpl(org.springframework.beans.BeanWrapperImpl) Connection(org.glassfish.tyrus.spi.Connection) AsyncContext(jakarta.servlet.AsyncContext) Writer(org.glassfish.tyrus.spi.Writer)

Example 2 with Writer

use of org.glassfish.tyrus.spi.Writer in project spring-framework by spring-projects.

the class GlassFishRequestUpgradeStrategy method handleSuccess.

@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();
}
Also used : TyrusHttpUpgradeHandler(org.glassfish.tyrus.servlet.TyrusHttpUpgradeHandler) Writer(org.glassfish.tyrus.spi.Writer)

Aggregations

Writer (org.glassfish.tyrus.spi.Writer)2 AsyncContext (jakarta.servlet.AsyncContext)1 TyrusHttpUpgradeHandler (org.glassfish.tyrus.servlet.TyrusHttpUpgradeHandler)1 Connection (org.glassfish.tyrus.spi.Connection)1 BeanWrapper (org.springframework.beans.BeanWrapper)1 BeanWrapperImpl (org.springframework.beans.BeanWrapperImpl)1