Search in sources :

Example 6 with ServerChannel

use of org.cometd.bayeux.server.ServerChannel in project ddf by codice.

the class SearchControllerTest method testExecuteQueryCacheDisabled.

/**
     * Verify that the CatalogFramework does not use the cache (i.e. the CatalogFramework
     * is called WITHOUT the query request property mode=cache).
     */
@Test
public void testExecuteQueryCacheDisabled() throws Exception {
    // Setup
    final String ID = "id";
    Set<String> srcIds = new HashSet<>(1);
    srcIds.add(ID);
    SearchRequest request = new SearchRequest(srcIds, getQueryRequest("title LIKE 'Meta*'"), ID);
    BayeuxServer bayeuxServer = mock(BayeuxServer.class);
    ServerChannel channel = mock(ServerChannel.class);
    when(bayeuxServer.getChannel(any(String.class))).thenReturn(channel);
    ArgumentCaptor<QueryRequest> queryRequestCaptor = ArgumentCaptor.forClass(QueryRequest.class);
    // Enable Cache
    searchController.setCacheDisabled(true);
    searchController.setBayeuxServer(bayeuxServer);
    // Perform Test
    searchController.executeQuery(request, mockServerSession, null);
    // Verify
    verify(framework).query(queryRequestCaptor.capture());
    assertThat(queryRequestCaptor.getValue().getProperties().size(), is(0));
}
Also used : SearchRequest(org.codice.ddf.ui.searchui.query.model.SearchRequest) QueryRequest(ddf.catalog.operation.QueryRequest) BayeuxServer(org.cometd.bayeux.server.BayeuxServer) Matchers.anyString(org.mockito.Matchers.anyString) ServerChannel(org.cometd.bayeux.server.ServerChannel) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 7 with ServerChannel

use of org.cometd.bayeux.server.ServerChannel in project ddf by codice.

the class CometdEndpoint method init.

@Override
public void init(ServletConfig config) throws ServletException {
    super.init(config);
    bayeuxServer = (BayeuxServer) config.getServletContext().getAttribute(BayeuxServer.ATTRIBUTE);
    if (bayeuxServer != null) {
        ServerAnnotationProcessor cometdAnnotationProcessor = new ServerAnnotationProcessor(bayeuxServer);
        //TODO: don't do this, we need some sort of policy
        bayeuxServer.setSecurityPolicy(new DefaultSecurityPolicy() {

            @Override
            public boolean canCreate(BayeuxServer server, ServerSession session, String channelId, ServerMessage message) {
                return true;
            }

            @Override
            public boolean canHandshake(BayeuxServer server, ServerSession session, ServerMessage message) {
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug("canHandshake ServerSession: {}   canHandshake ServerMessage: {}", session, message);
                }
                notificationController.registerUserSession(session, message);
                activityController.registerUserSession(session, message);
                return true;
            }

            @Override
            public boolean canPublish(BayeuxServer server, ServerSession session, ServerChannel channel, ServerMessage message) {
                return true;
            }

            @Override
            public boolean canSubscribe(BayeuxServer server, ServerSession session, ServerChannel channel, ServerMessage message) {
                return true;
            }
        });
        searchController.setBayeuxServer(bayeuxServer);
        searchService = new SearchService(filterBuilder, searchController);
        UserService userService = new UserService(persistentStore);
        WorkspaceService workspaceService = new WorkspaceService(persistentStore);
        cometdAnnotationProcessor.process(userService);
        cometdAnnotationProcessor.process(workspaceService);
        cometdAnnotationProcessor.process(searchService);
        cometdAnnotationProcessor.process(notificationController);
        cometdAnnotationProcessor.process(activityController);
    }
}
Also used : DefaultSecurityPolicy(org.cometd.server.DefaultSecurityPolicy) ServerSession(org.cometd.bayeux.server.ServerSession) ServerAnnotationProcessor(org.cometd.annotation.ServerAnnotationProcessor) UserService(org.codice.ddf.ui.searchui.query.service.UserService) BayeuxServer(org.cometd.bayeux.server.BayeuxServer) WorkspaceService(org.codice.ddf.ui.searchui.query.service.WorkspaceService) SearchService(org.codice.ddf.ui.searchui.query.service.SearchService) ServerMessage(org.cometd.bayeux.server.ServerMessage) ServerChannel(org.cometd.bayeux.server.ServerChannel)

Aggregations

ServerChannel (org.cometd.bayeux.server.ServerChannel)7 BayeuxServer (org.cometd.bayeux.server.BayeuxServer)6 SearchRequest (org.codice.ddf.ui.searchui.query.model.SearchRequest)5 Matchers.anyString (org.mockito.Matchers.anyString)5 HashSet (java.util.HashSet)4 Test (org.junit.Test)4 QueryRequest (ddf.catalog.operation.QueryRequest)3 ServerMessage (org.cometd.bayeux.server.ServerMessage)3 ServerSession (org.cometd.bayeux.server.ServerSession)3 CatalogFramework (ddf.catalog.CatalogFramework)2 ActionRegistryImpl (org.codice.ddf.ui.searchui.query.actions.ActionRegistryImpl)2 Mutable (org.cometd.bayeux.server.ServerMessage.Mutable)2 FilterAdapter (ddf.catalog.filter.FilterAdapter)1 FilterBuilder (ddf.catalog.filter.FilterBuilder)1 GeotoolsFilterAdapterImpl (ddf.catalog.filter.proxy.adapter.GeotoolsFilterAdapterImpl)1 QueryResponse (ddf.catalog.operation.QueryResponse)1 ArrayList (java.util.ArrayList)1 ServletContext (javax.servlet.ServletContext)1 PersistentStore (org.codice.ddf.persistence.PersistentStore)1 SearchService (org.codice.ddf.ui.searchui.query.service.SearchService)1