Search in sources :

Example 1 with ConfigurableServerChannel

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

the class SearchService method processQuery.

/**
     * Service method called by Cometd when something arrives on the service channel
     *
     * @param remote
     *            - Client session
     * @param message
     *            - JSON message
     */
@Listener("/service/query")
public void processQuery(final ServerSession remote, Message message) {
    ServerMessage.Mutable reply = new ServerMessageImpl();
    Map<String, Object> queryMessage = message.getDataAsMap();
    if (queryMessage != null && queryMessage.containsKey(Search.ID)) {
        bayeux.createChannelIfAbsent("/" + queryMessage.get(Search.ID), new ConfigurableServerChannel.Initializer() {

            public void configureChannel(ConfigurableServerChannel channel) {
                channel.setPersistent(true);
            }
        });
        BayeuxContext context = bayeux.getContext();
        Subject subject = null;
        if (context != null) {
            subject = (Subject) context.getRequestAttribute(SecurityConstants.SECURITY_SUBJECT);
        }
        // kick off the query
        executeQuery(queryMessage, subject);
        reply.put(Search.SUCCESSFUL, true);
        remote.deliver(serverSession, reply);
    } else {
        reply.put(Search.SUCCESSFUL, false);
        reply.put("status", "ERROR: unable to return results, no id in query request");
        remote.deliver(serverSession, reply);
    }
}
Also used : ServerMessageImpl(org.cometd.server.ServerMessageImpl) ServerMessage(org.cometd.bayeux.server.ServerMessage) ConfigurableServerChannel(org.cometd.bayeux.server.ConfigurableServerChannel) BayeuxContext(org.cometd.bayeux.server.BayeuxContext) Subject(ddf.security.Subject) Listener(org.cometd.annotation.Listener)

Aggregations

Subject (ddf.security.Subject)1 Listener (org.cometd.annotation.Listener)1 BayeuxContext (org.cometd.bayeux.server.BayeuxContext)1 ConfigurableServerChannel (org.cometd.bayeux.server.ConfigurableServerChannel)1 ServerMessage (org.cometd.bayeux.server.ServerMessage)1 ServerMessageImpl (org.cometd.server.ServerMessageImpl)1