Search in sources :

Example 21 with AtmosphereResource

use of org.atmosphere.cpr.AtmosphereResource in project flow by vaadin.

the class PushHandlerTest method runTest.

private VaadinServletService runTest(VaadinServletService service, BiConsumer<PushHandler, AtmosphereResource> testExec) throws ServiceException {
    PushHandler handler = Mockito.spy(new PushHandler(service));
    AtmosphereResource resource = Mockito.mock(AtmosphereResource.class);
    AtmosphereRequest request = Mockito.mock(AtmosphereRequest.class);
    Mockito.when(resource.getRequest()).thenReturn(request);
    testExec.accept(handler, resource);
    return service;
}
Also used : AtmosphereRequest(org.atmosphere.cpr.AtmosphereRequest) AtmosphereResource(org.atmosphere.cpr.AtmosphereResource)

Example 22 with AtmosphereResource

use of org.atmosphere.cpr.AtmosphereResource in project flow by vaadin.

the class PushHandlerTest method onMessage_devMode_websocket_refreshConnection_callWithUIIsNotCalled.

@Test
public void onMessage_devMode_websocket_refreshConnection_callWithUIIsNotCalled() throws ServiceException {
    MockVaadinServletService service = Mockito.spy(MockVaadinServletService.class);
    MockDeploymentConfiguration deploymentConfiguration = (MockDeploymentConfiguration) service.getDeploymentConfiguration();
    deploymentConfiguration.setProductionMode(false);
    deploymentConfiguration.setDevModeLiveReloadEnabled(true);
    deploymentConfiguration.setDevModeGizmoEnabled(true);
    VaadinContext context = service.getContext();
    mockBrowserLiveReloadImpl(context);
    AtomicReference<AtmosphereResource> res = new AtomicReference<>();
    runTest(service, (handler, resource) -> {
        AtmosphereRequest request = resource.getRequest();
        try {
            Mockito.when(request.getReader()).thenReturn(new BufferedReader(new StringReader("")));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        Mockito.when(request.getParameter(ApplicationConstants.DEBUG_WINDOW_CONNECTION)).thenReturn("");
        Mockito.when(resource.transport()).thenReturn(TRANSPORT.WEBSOCKET);
        try {
            Mockito.when(request.getReader()).thenReturn(new BufferedReader(new StringReader("{}")));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        handler.onMessage(resource);
        res.set(resource);
    });
    Mockito.verify(service, Mockito.times(0)).requestStart(Mockito.any(), Mockito.any());
}
Also used : VaadinContext(com.vaadin.flow.server.VaadinContext) AtmosphereRequest(org.atmosphere.cpr.AtmosphereRequest) MockVaadinServletService(com.vaadin.flow.server.MockVaadinServletService) AtmosphereResource(org.atmosphere.cpr.AtmosphereResource) MockDeploymentConfiguration(com.vaadin.tests.util.MockDeploymentConfiguration) BufferedReader(java.io.BufferedReader) StringReader(java.io.StringReader) AtomicReference(java.util.concurrent.atomic.AtomicReference) IOException(java.io.IOException) Test(org.junit.Test)

Example 23 with AtmosphereResource

use of org.atmosphere.cpr.AtmosphereResource in project flow by vaadin.

the class DebugWindowConnectionTest method reload_resourceIsDisconnected_reloadCommandIsNotSent.

@Test
public void reload_resourceIsDisconnected_reloadCommandIsNotSent() {
    AtmosphereResource resource = Mockito.mock(AtmosphereResource.class);
    Broadcaster broadcaster = Mockito.mock(Broadcaster.class);
    Mockito.when(resource.getBroadcaster()).thenReturn(broadcaster);
    reload.onConnect(resource);
    Assert.assertTrue(reload.isLiveReload(resource));
    Mockito.reset(broadcaster);
    reload.onDisconnect(resource);
    Assert.assertFalse(reload.isLiveReload(resource));
    reload.reload();
    Mockito.verifyNoInteractions(broadcaster);
}
Also used : AtmosphereResource(org.atmosphere.cpr.AtmosphereResource) Broadcaster(org.atmosphere.cpr.Broadcaster) Test(org.junit.Test)

Example 24 with AtmosphereResource

use of org.atmosphere.cpr.AtmosphereResource in project flow by vaadin.

the class DebugWindowConnectionTest method reload_twoConnections_sendReloadCommand.

@Test
public void reload_twoConnections_sendReloadCommand() {
    AtmosphereResource resource1 = Mockito.mock(AtmosphereResource.class);
    AtmosphereResource resource2 = Mockito.mock(AtmosphereResource.class);
    Broadcaster broadcaster = Mockito.mock(Broadcaster.class);
    Mockito.when(resource1.getBroadcaster()).thenReturn(broadcaster);
    Mockito.when(resource2.getBroadcaster()).thenReturn(broadcaster);
    reload.onConnect(resource1);
    reload.onConnect(resource2);
    Assert.assertTrue(reload.isLiveReload(resource1));
    Assert.assertTrue(reload.isLiveReload(resource2));
    reload.reload();
    Mockito.verify(broadcaster).broadcast("{\"command\": \"reload\"}", resource1);
    Mockito.verify(broadcaster).broadcast("{\"command\": \"reload\"}", resource2);
}
Also used : AtmosphereResource(org.atmosphere.cpr.AtmosphereResource) Broadcaster(org.atmosphere.cpr.Broadcaster) Test(org.junit.Test)

Example 25 with AtmosphereResource

use of org.atmosphere.cpr.AtmosphereResource in project cxf by apache.

the class SseAtmosphereEventSinkContextProvider method createContext.

@Override
public SseEventSink createContext(Message message) {
    final HttpServletRequest request = (HttpServletRequest) message.get(AbstractHTTPDestination.HTTP_REQUEST);
    if (request == null) {
        throw new IllegalStateException("Unable to retrieve HTTP request from the context");
    }
    final AtmosphereResource resource = (AtmosphereResource) request.getAttribute(AtmosphereResource.class.getName());
    if (resource == null) {
        throw new IllegalStateException("AtmosphereResource is not present, " + "is AtmosphereServlet configured properly?");
    }
    final Broadcaster broadcaster = resource.getAtmosphereConfig().getBroadcasterFactory().lookup(resource.uuid(), true);
    resource.removeFromAllBroadcasters();
    resource.setBroadcaster(broadcaster);
    final MessageBodyWriter<OutboundSseEvent> writer = new OutboundSseEventBodyWriter(ServerProviderFactory.getInstance(message), message.getExchange());
    return new SseAtmosphereEventSinkImpl(writer, resource);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) OutboundSseEvent(javax.ws.rs.sse.OutboundSseEvent) AtmosphereResource(org.atmosphere.cpr.AtmosphereResource) OutboundSseEventBodyWriter(org.apache.cxf.jaxrs.sse.OutboundSseEventBodyWriter) Broadcaster(org.atmosphere.cpr.Broadcaster)

Aggregations

AtmosphereResource (org.atmosphere.cpr.AtmosphereResource)37 AtmosphereRequest (org.atmosphere.cpr.AtmosphereRequest)14 IOException (java.io.IOException)10 AtmosphereResourceImpl (org.atmosphere.cpr.AtmosphereResourceImpl)9 Broadcaster (org.atmosphere.cpr.Broadcaster)8 Test (org.junit.Test)7 UI (com.vaadin.flow.component.UI)5 SessionExpiredException (com.vaadin.flow.server.SessionExpiredException)4 VaadinServletRequest (com.vaadin.flow.server.VaadinServletRequest)4 VaadinSession (com.vaadin.flow.server.VaadinSession)4 InvalidUIDLSecurityKeyException (com.vaadin.flow.server.communication.ServerRpcHandler.InvalidUIDLSecurityKeyException)4 JsonException (elemental.json.JsonException)4 AsynchronousProcessor (org.atmosphere.cpr.AsynchronousProcessor)4 AtmosphereResourceEvent (org.atmosphere.cpr.AtmosphereResourceEvent)4 MockVaadinServletService (com.vaadin.flow.server.MockVaadinServletService)3 ServletException (jakarta.servlet.ServletException)3 HashSet (java.util.HashSet)3 Future (java.util.concurrent.Future)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 AtmosphereResourceEventImpl (org.atmosphere.cpr.AtmosphereResourceEventImpl)3