Search in sources :

Example 1 with ServerMessage

use of org.cometd.bayeux.server.ServerMessage in project camel by apache.

the class CometdConsumerTest method testSessionHeadersAdded.

@Test
public void testSessionHeadersAdded() throws Exception {
    // setup
    when(endpoint.isSessionHeadersEnabled()).thenReturn(true);
    testObj.start();
    ServerMessage cometdMessage = mock(ServerMessage.class);
    Exchange exchange = mock(Exchange.class);
    when(endpoint.createExchange()).thenReturn(exchange);
    ArgumentCaptor<Message> transferredMessage = ArgumentCaptor.forClass(Message.class);
    // act
    testObj.getConsumerService().push(remote, cometdMessage);
    // verify
    verify(exchange).setIn(transferredMessage.capture());
    Message message = transferredMessage.getValue();
    assertEquals(MEMEBER_USER_NAME, message.getHeader(USER_NAME));
}
Also used : Exchange(org.apache.camel.Exchange) ServerMessage(org.cometd.bayeux.server.ServerMessage) Message(org.apache.camel.Message) ServerMessage(org.cometd.bayeux.server.ServerMessage) Test(org.junit.Test)

Example 2 with ServerMessage

use of org.cometd.bayeux.server.ServerMessage in project camel by apache.

the class CometdBinding method createCamelMessage.

public Message createCamelMessage(ServerSession remote, ServerMessage cometdMessage, Object data) {
    if (cometdMessage != null) {
        data = cometdMessage.getData();
    }
    Message message = new DefaultMessage();
    message.setBody(data);
    Map headers = getHeadersFromMessage(cometdMessage);
    if (headers != null) {
        message.setHeaders(headers);
    }
    message.setHeader(COMETD_CLIENT_ID_HEADER_NAME, remote.getId());
    if (cometdMessage != null && cometdMessage.get(COMETD_SUBSCRIPTION_HEADER_NAME) != null) {
        message.setHeader(COMETD_SUBSCRIPTION_HEADER_NAME, cometdMessage.get(COMETD_SUBSCRIPTION_HEADER_NAME));
    }
    if (enableSessionHeader) {
        addSessionAttributesToMessageHeaders(remote, message);
    }
    return message;
}
Also used : DefaultMessage(org.apache.camel.impl.DefaultMessage) ServerMessage(org.cometd.bayeux.server.ServerMessage) Message(org.apache.camel.Message) DefaultMessage(org.apache.camel.impl.DefaultMessage) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with ServerMessage

use of org.cometd.bayeux.server.ServerMessage 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

ServerMessage (org.cometd.bayeux.server.ServerMessage)3 Message (org.apache.camel.Message)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Exchange (org.apache.camel.Exchange)1 DefaultMessage (org.apache.camel.impl.DefaultMessage)1 SearchService (org.codice.ddf.ui.searchui.query.service.SearchService)1 UserService (org.codice.ddf.ui.searchui.query.service.UserService)1 WorkspaceService (org.codice.ddf.ui.searchui.query.service.WorkspaceService)1 ServerAnnotationProcessor (org.cometd.annotation.ServerAnnotationProcessor)1 BayeuxServer (org.cometd.bayeux.server.BayeuxServer)1 ServerChannel (org.cometd.bayeux.server.ServerChannel)1 ServerSession (org.cometd.bayeux.server.ServerSession)1 DefaultSecurityPolicy (org.cometd.server.DefaultSecurityPolicy)1 Test (org.junit.Test)1