Search in sources :

Example 1 with Route

use of com.swiftmq.swiftlet.routing.Route in project swiftmq-ce by iitsoftware.

the class DispatcherImpl method visit.

// <-- EventObjectVisitor
// --> ProtocolVisitorAdapter
public void visit(ConnectRequest request) {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.mgmtSwiftlet.getName(), toString() + "/visit, request: " + request + " ...");
    connectRequest = request;
    ConnectReply reply = (ConnectReply) request.createReply();
    reply.setOk(true);
    reply.setRouterName(SwiftletManager.getInstance().getRouterName());
    reply.setLeaseTimeout(LEASE_EXPIRATION);
    reply.setAuthRequired(ctx.authEnabled);
    if (((Boolean) ctx.root.getProperty("admin-roles-enabled").getValue()).booleanValue()) {
        if (userName == null) {
            reply.setOk(false);
            reply.setException(new Exception("JMSXUserID not set in message!"));
            send(reply);
            return;
        }
        Entity roleEntity = ctx.root.getEntity("roles").getEntity(userName);
        if (roleEntity != null)
            authenticator = new AuthenticatorImpl(ctx, new Role(ctx, roleEntity));
        else {
            reply.setOk(false);
            reply.setException(new Exception("No role defined for user: " + userName));
            send(reply);
            return;
        }
    }
    if (ctx.authEnabled) {
        reply.setCrFactory(ctx.challengeResponseFactory.getClass().getName());
        challenge = ctx.challengeResponseFactory.createChallenge(ctx.password);
        reply.setChallenge(challenge);
    } else {
        authenticated = true;
        started = true;
        createUsageEntity();
    }
    send(reply);
    if (started) {
        if (connectRequest.isSubscribeRouterConfig()) {
            try {
                RouterConfigInstance routerConfigInstance = copy(RouterConfiguration.Singleton());
                roleStrip(routerConfigInstance);
                dos.rewind();
                Dumpalizer.dump(dos, routerConfigInstance);
                send(new RouterConfigRequest(connectRequest.getConnectId(), SwiftletManager.getInstance().getRouterName(), dos.getBuffer(), dos.getCount()));
            } catch (Exception e) {
                valid = false;
                authenticated = false;
                started = false;
            }
        }
        if (connectRequest.isSubscribeRouteInfos() && ctx.routingSwiftlet != null) {
            try {
                Route[] routes = ctx.routingSwiftlet.getRoutes();
                if (routes != null) {
                    for (int i = 0; i < routes.length; i++) {
                        if (routes[i].isActive()) {
                            send(new RouterAvailableRequest(routes[i].getDestination()));
                            announcedRouters.add(routes[i].getDestination());
                        }
                    }
                }
            } catch (Exception e) {
                valid = false;
                authenticated = false;
                started = false;
            }
        }
    }
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.mgmtSwiftlet.getName(), toString() + "/visit, request: " + request + " done");
}
Also used : Role(com.swiftmq.impl.mgmt.standard.auth.Role) AuthenticatorImpl(com.swiftmq.impl.mgmt.standard.auth.AuthenticatorImpl) Route(com.swiftmq.swiftlet.routing.Route)

Example 2 with Route

use of com.swiftmq.swiftlet.routing.Route in project swiftmq-ce by iitsoftware.

the class TopicManagerImpl method createStaticRemoteRouterSubs.

private void createStaticRemoteRouterSubs() throws SwiftletException {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(getName(), "createStaticRemoteRouterSubs...");
    EntityList srrList = (EntityList) root.getEntity("static-remote-router-subscriptions");
    if (srrList == null)
        return;
    Map entities = srrList.getEntities();
    if (entities != null && entities.size() > 0) {
        for (Iterator iter = entities.entrySet().iterator(); iter.hasNext(); ) {
            Entity entity = (Entity) ((Map.Entry) iter.next()).getValue();
            Route route = ctx.routingSwiftlet.getRoute(entity.getName());
            if (route == null)
                throw new SwiftletException("Unable to create static remote router subscriptions for router '" + entity.getName() + "', missing route. Please create a static route to '" + entity.getName() + "'");
            try {
                createStaticTopicSub(entity);
            } catch (Exception e) {
                throw new SwiftletException(e.getMessage());
            }
        }
    }
    srrList.setEntityAddListener(new EntityChangeAdapter(null) {

        public void onEntityAdd(Entity parent, Entity newEntity) throws EntityAddException {
            try {
                Route route = ctx.routingSwiftlet.getRoute(newEntity.getName());
                if (route == null)
                    throw new SwiftletException("Unable to create static remote router subscriptions for router '" + newEntity.getName() + "', missing route. Please create a static route to '" + newEntity.getName() + "'");
                createStaticTopicSub(newEntity);
                if (ctx.traceSpace.enabled)
                    ctx.traceSpace.trace(getName(), "onEntityAdd (static-remote-router-subscriptions): new router=" + newEntity.getName());
            } catch (Exception e) {
                throw new EntityAddException(e.getMessage());
            }
        }
    });
    srrList.setEntityRemoveListener(new EntityChangeAdapter(null) {

        public void onEntityRemove(Entity parent, Entity delEntity) throws EntityRemoveException {
            try {
                EntityList stsList = (EntityList) delEntity.getEntity("static-topic-subscriptions");
                Map entities = stsList.getEntities();
                if (entities != null && entities.size() > 0) {
                    for (Iterator iter = entities.entrySet().iterator(); iter.hasNext(); ) {
                        Entity entity = (Entity) ((Map.Entry) iter.next()).getValue();
                        removeStaticSubscription(delEntity.getName(), entity.getName());
                    }
                }
                if (ctx.traceSpace.enabled)
                    ctx.traceSpace.trace(getName(), "onEntityRemove (static-remote-router-subscriptions): del router=" + delEntity.getName());
            } catch (Exception e) {
                throw new EntityRemoveException(e.getMessage());
            }
        }
    });
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(getName(), "createStaticRemoteRouterSubs done.");
}
Also used : DurableStoreEntry(com.swiftmq.swiftlet.store.DurableStoreEntry) SwiftletException(com.swiftmq.swiftlet.SwiftletException) Route(com.swiftmq.swiftlet.routing.Route) InvalidDestinationException(javax.jms.InvalidDestinationException) IOException(java.io.IOException) JMSException(javax.jms.JMSException) SwiftletException(com.swiftmq.swiftlet.SwiftletException) AuthenticationException(com.swiftmq.swiftlet.auth.AuthenticationException) TopicException(com.swiftmq.swiftlet.topic.TopicException)

Aggregations

Route (com.swiftmq.swiftlet.routing.Route)2 AuthenticatorImpl (com.swiftmq.impl.mgmt.standard.auth.AuthenticatorImpl)1 Role (com.swiftmq.impl.mgmt.standard.auth.Role)1 SwiftletException (com.swiftmq.swiftlet.SwiftletException)1 AuthenticationException (com.swiftmq.swiftlet.auth.AuthenticationException)1 DurableStoreEntry (com.swiftmq.swiftlet.store.DurableStoreEntry)1 TopicException (com.swiftmq.swiftlet.topic.TopicException)1 IOException (java.io.IOException)1 InvalidDestinationException (javax.jms.InvalidDestinationException)1 JMSException (javax.jms.JMSException)1