Search in sources :

Example 31 with Request

use of com.swiftmq.tools.requestreply.Request in project swiftmq-ce by iitsoftware.

the class AuthStage method init.

protected void init() {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString() + "/init...");
    visitor.setRequestHandler(com.swiftmq.impl.routing.single.smqpr.SMQRFactory.START_STAGE_REQ, new RequestHandler() {

        public void visited(Request request) {
            try {
                if (ctx.traceSpace.enabled)
                    ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), AuthStage.this.toString() + "/visited, request=" + request + " ...");
                String password = routingConnection.getPassword();
                if (password == null)
                    throw new Exception("Authentication request by remote router but no password is defined!");
                ChallengeResponseFactory crf = (ChallengeResponseFactory) Class.forName(connectReply.getCrFactory()).newInstance();
                AuthRequest ar = new AuthRequest(crf.createResponse(connectReply.getChallenge(), password));
                if (ctx.traceSpace.enabled)
                    ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), AuthStage.this.toString() + "/visited, request=" + request + ", sending request: " + ar);
                routingConnection.getOutboundQueue().enqueue(ar);
                startValidTimer();
            } catch (Exception e) {
                if (ctx.traceSpace.enabled)
                    ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), AuthStage.this.toString() + "/visited, request=" + request + ", exception=" + e + ", disconnect");
                ctx.logSwiftlet.logError(ctx.routingSwiftlet.getName(), AuthStage.this.toString() + "/exception: " + e.getMessage());
                ctx.networkSwiftlet.getConnectionManager().removeConnection(routingConnection.getConnection());
            }
        }
    });
    visitor.setRequestHandler(com.swiftmq.impl.routing.single.smqpr.v400.SMQRFactory.AUTH_REPREQ, new RequestHandler() {

        public void visited(Request request) {
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), AuthStage.this.toString() + "/visited, request=" + request + "...");
            AuthReplyRequest reply = (AuthReplyRequest) request;
            if (reply.isOk()) {
                if (ctx.traceSpace.enabled)
                    ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), AuthStage.this.toString() + "/visited, request=" + request + ", launching recovery stage");
                // Launch recovery stage
                getStageQueue().setStage(new XARecoveryStage(ctx, routingConnection));
            } else {
                if (ctx.traceSpace.enabled)
                    ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), AuthStage.this.toString() + "/visited, request=" + request + ", disconnect");
                ctx.logSwiftlet.logError(ctx.routingSwiftlet.getName(), AuthStage.this.toString() + "/exception: " + reply.getException());
                ctx.networkSwiftlet.getConnectionManager().removeConnection(routingConnection.getConnection());
            }
        }
    });
    visitor.setRequestHandler(com.swiftmq.impl.routing.single.smqpr.v400.SMQRFactory.AUTH_REQ, new RequestHandler() {

        public void visited(Request request) {
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), AuthStage.this.toString() + "/visited, request=" + request);
            AuthRequest pr = (AuthRequest) request;
            AuthReplyRequest reply = new AuthReplyRequest();
            if (ctx.challengeResponseFactory.verifyResponse(connectReply.getChallenge(), pr.getResponse(), routingConnection.getPassword())) {
                reply.setOk(true);
                if (ctx.traceSpace.enabled)
                    ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), AuthStage.this.toString() + "/visited, request=" + request + ", response ok, launching recovery stage");
                // Launch recovery stage
                getStageQueue().setStage(new XARecoveryStage(ctx, routingConnection));
            } else {
                if (ctx.traceSpace.enabled)
                    ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), AuthStage.this.toString() + "/visited, request=" + request + ", invalid password, diconnect");
                ctx.logSwiftlet.logError(ctx.routingSwiftlet.getName(), AuthStage.this.toString() + "/connection rejected, invalid password!");
                reply.setOk(false);
                reply.setException(new Exception("Invalid password!"));
                ctx.timerSwiftlet.addInstantTimerListener(((Long) ctx.root.getProperty("reject-disconnect-delay").getValue()).longValue(), new TimerListener() {

                    public void performTimeAction() {
                        if (ctx.traceSpace.enabled)
                            ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), AuthStage.this.toString() + "/disconnect timeout");
                        ctx.networkSwiftlet.getConnectionManager().removeConnection(routingConnection.getConnection());
                    }
                });
            }
            routingConnection.getOutboundQueue().enqueue(reply);
        }
    });
    if (!listener)
        getStageQueue().enqueue(new StartStageRequest());
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString() + "/init done");
}
Also used : AuthRequest(com.swiftmq.impl.routing.single.smqpr.v400.AuthRequest) RequestHandler(com.swiftmq.impl.routing.single.smqpr.RequestHandler) ChallengeResponseFactory(com.swiftmq.auth.ChallengeResponseFactory) StartStageRequest(com.swiftmq.impl.routing.single.smqpr.StartStageRequest) StartStageRequest(com.swiftmq.impl.routing.single.smqpr.StartStageRequest) Request(com.swiftmq.tools.requestreply.Request) ConnectReplyRequest(com.swiftmq.impl.routing.single.smqpr.v400.ConnectReplyRequest) AuthReplyRequest(com.swiftmq.impl.routing.single.smqpr.v400.AuthReplyRequest) AuthRequest(com.swiftmq.impl.routing.single.smqpr.v400.AuthRequest) TimerListener(com.swiftmq.swiftlet.timer.event.TimerListener) AuthReplyRequest(com.swiftmq.impl.routing.single.smqpr.v400.AuthReplyRequest)

Example 32 with Request

use of com.swiftmq.tools.requestreply.Request in project swiftmq-ce by iitsoftware.

the class ConnectStage method init.

protected void init() {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString() + "/init...");
    visitor.setRequestHandler(com.swiftmq.impl.routing.single.smqpr.SMQRFactory.START_STAGE_REQ, new RequestHandler() {

        public void visited(Request request) {
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), ConnectStage.this.toString() + "/visited, request=" + request + "...");
            ConnectRequest cr = new ConnectRequest(ctx.routerName);
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), ConnectStage.this.toString() + "/visited, request=" + request + ", sending request= " + cr);
            routingConnection.getOutboundQueue().enqueue(cr);
            startValidTimer();
        }
    });
    visitor.setRequestHandler(com.swiftmq.impl.routing.single.smqpr.v400.SMQRFactory.CONNECT_REPREQ, new RequestHandler() {

        public void visited(Request request) {
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), ConnectStage.this.toString() + "/visited, request=" + request + "...");
            ConnectReplyRequest reply = (ConnectReplyRequest) request;
            if (reply.isOk()) {
                routingConnection.setRouterName(reply.getRouterName());
                ctx.connectionManager.enqueue(new POAddObject(new ConnectorCallback(reply), null, routingConnection));
            } else {
                if (ctx.traceSpace.enabled)
                    ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), ConnectStage.this.toString() + "/visited, request=" + request + ", disconnect");
                ctx.networkSwiftlet.getConnectionManager().removeConnection(routingConnection.getConnection());
            }
        }
    });
    visitor.setRequestHandler(com.swiftmq.impl.routing.single.smqpr.v400.SMQRFactory.CONNECT_REQ, new RequestHandler() {

        public void visited(Request request) {
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), ConnectStage.this.toString() + "/visited, request=" + request);
            ConnectRequest pr = (ConnectRequest) request;
            routingConnection.setRouterName(pr.getRouterName());
            ctx.connectionManager.enqueue(new POAddObject(new ListenerCallback(pr), null, routingConnection));
        }
    });
    if (!listener)
        getStageQueue().enqueue(new StartStageRequest());
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString() + "/init done");
}
Also used : ConnectRequest(com.swiftmq.impl.routing.single.smqpr.v400.ConnectRequest) ConnectReplyRequest(com.swiftmq.impl.routing.single.smqpr.v400.ConnectReplyRequest) RequestHandler(com.swiftmq.impl.routing.single.smqpr.RequestHandler) StartStageRequest(com.swiftmq.impl.routing.single.smqpr.StartStageRequest) StartStageRequest(com.swiftmq.impl.routing.single.smqpr.StartStageRequest) ConnectRequest(com.swiftmq.impl.routing.single.smqpr.v400.ConnectRequest) Request(com.swiftmq.tools.requestreply.Request) ConnectReplyRequest(com.swiftmq.impl.routing.single.smqpr.v400.ConnectReplyRequest) POAddObject(com.swiftmq.impl.routing.single.manager.po.POAddObject)

Example 33 with Request

use of com.swiftmq.tools.requestreply.Request in project swiftmq-ce by iitsoftware.

the class ThrottleQueue method process.

protected void process(Object[] objects, int len) {
    for (int i = 0; i < len; i++) {
        Request r = (Request) objects[i];
        if (r.getDumpId() == SMQRFactory.THROTTLE_REQ) {
            sem.reset();
            sem.waitHere(((ThrottleRequest) r).getDelay());
        } else {
            outboundQueue.enqueue(r);
        }
        if (closed)
            return;
    }
}
Also used : Request(com.swiftmq.tools.requestreply.Request) ThrottleRequest(com.swiftmq.impl.routing.single.smqpr.v400.ThrottleRequest)

Example 34 with Request

use of com.swiftmq.tools.requestreply.Request in project swiftmq-ce by iitsoftware.

the class XADeliveryStage method init.

protected void init() {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString() + "/init...");
    visitor.setRequestHandler(com.swiftmq.impl.routing.single.smqpr.SMQRFactory.START_STAGE_REQ, new RequestHandler() {

        public void visited(Request request) {
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), XADeliveryStage.this.toString("OUTBOUND") + "/visited, request=" + request + "...");
            int txSize = ((Integer) routingConnection.getEntity().getProperty("inbound-transaction-size").getValue()).intValue();
            int windowSize = ((Integer) routingConnection.getEntity().getProperty("inbound-window-size").getValue()).intValue();
            AdjustRequest rc = new AdjustRequest(txSize, windowSize);
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), XADeliveryStage.this.toString("OUTBOUND") + "/visited, request=" + request + ", sending request=" + rc);
            routingConnection.getOutboundQueue().enqueue(rc);
        }
    });
    visitor.setRequestHandler(com.swiftmq.impl.routing.single.smqpr.SMQRFactory.SEND_ROUTE_REQ, new RequestHandler() {

        public void visited(Request request) {
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), XADeliveryStage.this.toString("OUTBOUND") + "/visited, request=" + request + "...");
            RouteRequest rc = new RouteRequest(((SendRouteRequest) request).getRoute());
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), XADeliveryStage.this.toString("OUTBOUND") + "/visited, request=" + request + ", sending request=" + rc);
            routingConnection.getOutboundQueue().enqueue(rc);
        }
    });
    visitor.setRequestHandler(com.swiftmq.impl.routing.single.smqpr.v400.SMQRFactory.ROUTE_REQ, new RequestHandler() {

        public void visited(Request request) {
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), XADeliveryStage.this.toString("INBOUND") + "/visited, request=" + request + "...");
            RouteRequest rc = (RouteRequest) request;
            try {
                ctx.routeExchanger.processRoute(routingConnection, rc.getRoute(ctx.routeExchanger.getRouteConverter()));
            } catch (Exception e) {
                if (ctx.traceSpace.enabled)
                    ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), XADeliveryStage.this.toString("INBOUND") + "/visited, request=" + request + " exception=" + e);
                ctx.logSwiftlet.logError(ctx.routingSwiftlet.getName(), XADeliveryStage.this.toString() + "/visited, request=" + request + " exception=" + e);
            }
        }
    });
    visitor.setRequestHandler(com.swiftmq.impl.routing.single.smqpr.v400.SMQRFactory.ADJUST_REQ, new RequestHandler() {

        public void visited(Request request) {
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), XADeliveryStage.this.toString() + "/visited, request=" + request + "...");
            AdjustRequest rc = (AdjustRequest) request;
            routingConnection.setTransactionSize(rc.getTransactionSize());
            routingConnection.setWindowSize(rc.getWindowSize());
            // It then sends a request by itself to ensure the XADeliveryStage is active at the connector side.
            if (listener)
                getStageQueue().enqueue(new StartStageRequest());
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), XADeliveryStage.this.toString() + "/visited, request=" + request + ", activating connection");
            routingConnection.getActivationListener().activated(routingConnection);
        }
    });
    visitor.setRequestHandler(com.swiftmq.impl.routing.single.smqpr.SMQRFactory.DELIVERY_REQ, new RequestHandler() {

        public void visited(Request request) {
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), XADeliveryStage.this.toString("OUTBOUND") + "/visited, request=" + request + "...");
            try {
                DeliveryRequest rc = (DeliveryRequest) request;
                QueuePullTransaction srcTx = rc.readTransaction;
                QueueReceiver receiver = (QueueReceiver) consumers.get(srcTx.getQueueName());
                if (receiver == null) {
                    receiver = ctx.queueManager.createQueueReceiver(srcTx.getQueueName(), null, null);
                    consumers.put(srcTx.getQueueName(), receiver);
                }
                QueuePullTransaction destTx = receiver.createTransaction(false);
                List al = new ArrayList(rc.len);
                for (int i = 0; i < rc.len; i++) {
                    destTx.moveToTransaction(rc.entries[i].getMessageIndex(), srcTx);
                    MessageImpl msg = rc.entries[i].getMessage();
                    if (msg.getSourceRouter() == null)
                        msg.setSourceRouter(ctx.routerName);
                    if (msg.getDestRouter() == null)
                        msg.setDestRouter(rc.destinationRouter);
                    al.add(rc.entries[i].getMessage());
                }
                StringBuffer b = new StringBuffer(txBase);
                b.append(txNo);
                XidImpl xid = new XidImpl(recoveryBranchQB, txNo, b.toString().getBytes());
                xid.setRouting(true);
                destTx.prepare(xid);
                outboundTransactions.put(xid, destTx);
                TransactionRequest txr = new TransactionRequest(txNo, xid, al);
                txNo++;
                if (txNo == Integer.MAX_VALUE)
                    txNo = 0;
                if (ctx.traceSpace.enabled)
                    ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), XADeliveryStage.this.toString("OUTBOUND") + "/visited, request=" + request + " sending request=" + txr);
                routingConnection.getOutboundQueue().enqueue(txr);
                if (outboundTransactions.size() <= routingConnection.getWindowSize())
                    rc.callback.delivered(rc);
                else
                    notificationList.put(xid, rc);
            } catch (Exception e) {
                e.printStackTrace();
                if (ctx.traceSpace.enabled)
                    ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), XADeliveryStage.this.toString("OUTBOUND") + "/visited, request=" + request + " exception=" + e);
                ctx.logSwiftlet.logError(ctx.routingSwiftlet.getName(), XADeliveryStage.this.toString() + "/visited, request=" + request + " exception=" + e + ", disconnecting");
                ctx.networkSwiftlet.getConnectionManager().removeConnection(routingConnection.getConnection());
            }
        }
    });
    visitor.setRequestHandler(com.swiftmq.impl.routing.single.smqpr.v400.SMQRFactory.COMMIT_REQ, new RequestHandler() {

        public void visited(Request request) {
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), XADeliveryStage.this.toString("OUTBOUND") + "/visited, request=" + request + "...");
            CommitRequest rc = (CommitRequest) request;
            XidImpl xid = rc.getXid();
            QueuePullTransaction t = (QueuePullTransaction) outboundTransactions.remove(xid);
            try {
                t.commit(xid);
                CommitReplyRequest crr = new CommitReplyRequest(xid);
                crr.setOk(true);
                routingConnection.getOutboundQueue().enqueue(crr);
                DeliveryRequest dr = (DeliveryRequest) notificationList.remove(xid);
                if (dr != null) {
                    dr.callback.delivered(dr);
                }
            } catch (Exception e) {
                e.printStackTrace();
                if (ctx.traceSpace.enabled)
                    ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), XADeliveryStage.this.toString("OUTBOUND") + "/visited, request=" + request + " exception=" + e);
                ctx.logSwiftlet.logError(ctx.routingSwiftlet.getName(), XADeliveryStage.this.toString() + "/visited, request=" + request + " exception=" + e + ", disconnecting");
                ctx.networkSwiftlet.getConnectionManager().removeConnection(routingConnection.getConnection());
            }
        }
    });
    visitor.setRequestHandler(com.swiftmq.impl.routing.single.smqpr.v400.SMQRFactory.TRANSACTION_REQ, new RequestHandler() {

        public void visited(Request request) {
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), XADeliveryStage.this.toString("INBOUND") + "/visited, request=" + request + "...");
            TransactionRequest rc = (TransactionRequest) request;
            try {
                processTransactionRequest(rc);
                CommitRequest cr = new CommitRequest(rc.getXid());
                if (throttleQueue != null)
                    throttleQueue.enqueue(cr);
                else
                    routingConnection.getOutboundQueue().enqueue(cr);
            } catch (Exception e) {
                if (ctx.traceSpace.enabled)
                    ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), XADeliveryStage.this.toString("INBOUND") + "/visited, request=" + request + " exception=" + e);
                ctx.logSwiftlet.logError(ctx.routingSwiftlet.getName(), XADeliveryStage.this.toString() + "/visited, request=" + request + " exception=" + e + ", disconnecting");
                ctx.networkSwiftlet.getConnectionManager().removeConnection(routingConnection.getConnection());
            }
        }
    });
    visitor.setRequestHandler(com.swiftmq.impl.routing.single.smqpr.v400.SMQRFactory.COMMIT_REPREQ, new RequestHandler() {

        public void visited(Request request) {
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), XADeliveryStage.this.toString("INBOUND") + "/visited, request=" + request + "...");
            CommitReplyRequest rc = (CommitReplyRequest) request;
            try {
                if (!rc.isOk())
                    throw new Exception("Reply states not ok: " + rc);
                long delay = commitLocalXid(rc.getXid());
                if (delay > 0 && throttleQueue != null)
                    throttleQueue.enqueue(new ThrottleRequest(delay));
            } catch (Exception e) {
                if (ctx.traceSpace.enabled)
                    ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), XADeliveryStage.this.toString("INBOUND") + "/visited, request=" + request + " exception=" + e);
                ctx.logSwiftlet.logError(ctx.routingSwiftlet.getName(), XADeliveryStage.this.toString() + "/visited, request=" + request + " exception=" + e + ", disconnecting");
                ctx.networkSwiftlet.getConnectionManager().removeConnection(routingConnection.getConnection());
            }
        }
    });
    if (!listener)
        getStageQueue().enqueue(new StartStageRequest());
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString() + "/init done");
}
Also used : XidImpl(com.swiftmq.jms.XidImpl) Request(com.swiftmq.tools.requestreply.Request) QueuePullTransaction(com.swiftmq.swiftlet.queue.QueuePullTransaction) JMSException(javax.jms.JMSException) XAContextException(com.swiftmq.swiftlet.xa.XAContextException) QueueReceiver(com.swiftmq.swiftlet.queue.QueueReceiver) MessageImpl(com.swiftmq.jms.MessageImpl)

Example 35 with Request

use of com.swiftmq.tools.requestreply.Request in project swiftmq-ce by iitsoftware.

the class AuthStage method init.

protected void init() {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString() + "/init...");
    visitor.setRequestHandler(com.swiftmq.impl.routing.single.smqpr.SMQRFactory.START_STAGE_REQ, new RequestHandler() {

        public void visited(Request request) {
            try {
                if (ctx.traceSpace.enabled)
                    ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), AuthStage.this.toString() + "/visited, request=" + request + " ...");
                String password = routingConnection.getPassword();
                if (password == null)
                    throw new Exception("Authentication request by remote router but no password is defined!");
                ChallengeResponseFactory crf = (ChallengeResponseFactory) Class.forName(connectReply.getCrFactory()).newInstance();
                AuthRequest ar = new AuthRequest(crf.createResponse(connectReply.getChallenge(), password));
                if (ctx.traceSpace.enabled)
                    ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), AuthStage.this.toString() + "/visited, request=" + request + ", sending request: " + ar);
                routingConnection.getOutboundQueue().enqueue(ar);
                startValidTimer();
            } catch (Exception e) {
                if (ctx.traceSpace.enabled)
                    ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), AuthStage.this.toString() + "/visited, request=" + request + ", exception=" + e + ", disconnect");
                ctx.logSwiftlet.logError(ctx.routingSwiftlet.getName(), AuthStage.this.toString() + "/exception: " + e.getMessage());
                ctx.networkSwiftlet.getConnectionManager().removeConnection(routingConnection.getConnection());
            }
        }
    });
    visitor.setRequestHandler(com.swiftmq.impl.routing.single.smqpr.v942.SMQRFactory.AUTH_REPREQ, new RequestHandler() {

        public void visited(Request request) {
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), AuthStage.this.toString() + "/visited, request=" + request + "...");
            AuthReplyRequest reply = (AuthReplyRequest) request;
            if (reply.isOk()) {
                if (connectReply.isRequestXA() || routingConnection.isXa()) {
                    if (ctx.traceSpace.enabled)
                        ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), AuthStage.this.toString() + "/visited, request=" + request + ", launching recovery stage");
                    // Launch recovery stage
                    getStageQueue().setStage(new XARecoveryStage(ctx, routingConnection));
                } else {
                    if (ctx.traceSpace.enabled)
                        ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), AuthStage.this.toString() + "/visited, request=" + request + ", launching non-xa delivery stage");
                    // Launch non-XA delivery stage
                    getStageQueue().setStage(new NonXADeliveryStage(ctx, routingConnection));
                }
            } else {
                if (ctx.traceSpace.enabled)
                    ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), AuthStage.this.toString() + "/visited, request=" + request + ", disconnect");
                ctx.logSwiftlet.logError(ctx.routingSwiftlet.getName(), AuthStage.this.toString() + "/exception: " + reply.getException());
                ctx.networkSwiftlet.getConnectionManager().removeConnection(routingConnection.getConnection());
            }
        }
    });
    visitor.setRequestHandler(com.swiftmq.impl.routing.single.smqpr.v942.SMQRFactory.AUTH_REQ, new RequestHandler() {

        public void visited(Request request) {
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), AuthStage.this.toString() + "/visited, request=" + request);
            AuthRequest pr = (AuthRequest) request;
            AuthReplyRequest reply = new AuthReplyRequest();
            if (ctx.challengeResponseFactory.verifyResponse(connectReply.getChallenge(), pr.getResponse(), routingConnection.getPassword())) {
                reply.setOk(true);
                if (connectReply.isRequestXA() || routingConnection.isXa()) {
                    if (ctx.traceSpace.enabled)
                        ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), AuthStage.this.toString() + "/visited, request=" + request + ", launching recovery stage");
                    // Launch recovery stage
                    getStageQueue().setStage(new XARecoveryStage(ctx, routingConnection));
                } else {
                    if (ctx.traceSpace.enabled)
                        ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), AuthStage.this.toString() + "/visited, request=" + request + ", launching non-xa delivery stage");
                    // Launch non-XA delivery stage
                    getStageQueue().setStage(new NonXADeliveryStage(ctx, routingConnection));
                }
            } else {
                if (ctx.traceSpace.enabled)
                    ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), AuthStage.this.toString() + "/visited, request=" + request + ", invalid password, diconnect");
                ctx.logSwiftlet.logError(ctx.routingSwiftlet.getName(), AuthStage.this.toString() + "/connection rejected, invalid password!");
                reply.setOk(false);
                reply.setException(new Exception("Invalid password!"));
                ctx.timerSwiftlet.addInstantTimerListener(((Long) ctx.root.getProperty("reject-disconnect-delay").getValue()).longValue(), new TimerListener() {

                    public void performTimeAction() {
                        if (ctx.traceSpace.enabled)
                            ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), AuthStage.this.toString() + "/disconnect timeout");
                        ctx.networkSwiftlet.getConnectionManager().removeConnection(routingConnection.getConnection());
                    }
                });
            }
            routingConnection.getOutboundQueue().enqueue(reply);
        }
    });
    if (!listener)
        getStageQueue().enqueue(new StartStageRequest());
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString() + "/init done");
}
Also used : AuthRequest(com.swiftmq.impl.routing.single.smqpr.v942.AuthRequest) RequestHandler(com.swiftmq.impl.routing.single.smqpr.RequestHandler) ChallengeResponseFactory(com.swiftmq.auth.ChallengeResponseFactory) StartStageRequest(com.swiftmq.impl.routing.single.smqpr.StartStageRequest) AuthRequest(com.swiftmq.impl.routing.single.smqpr.v942.AuthRequest) AuthReplyRequest(com.swiftmq.impl.routing.single.smqpr.v942.AuthReplyRequest) StartStageRequest(com.swiftmq.impl.routing.single.smqpr.StartStageRequest) Request(com.swiftmq.tools.requestreply.Request) ConnectReplyRequest(com.swiftmq.impl.routing.single.smqpr.v942.ConnectReplyRequest) TimerListener(com.swiftmq.swiftlet.timer.event.TimerListener) AuthReplyRequest(com.swiftmq.impl.routing.single.smqpr.v942.AuthReplyRequest)

Aggregations

Request (com.swiftmq.tools.requestreply.Request)35 XidImpl (com.swiftmq.jms.XidImpl)16 JMSException (javax.jms.JMSException)16 ValidationException (com.swiftmq.tools.requestreply.ValidationException)14 XAException (javax.transaction.xa.XAException)14 Dumpable (com.swiftmq.tools.dump.Dumpable)8 RequestHandler (com.swiftmq.impl.routing.single.smqpr.RequestHandler)6 StartStageRequest (com.swiftmq.impl.routing.single.smqpr.StartStageRequest)6 List (java.util.List)6 XAContextException (com.swiftmq.swiftlet.xa.XAContextException)4 ChallengeResponseFactory (com.swiftmq.auth.ChallengeResponseFactory)2 POAddObject (com.swiftmq.impl.routing.single.manager.po.POAddObject)2 ConnectReplyRequest (com.swiftmq.impl.routing.single.smqpr.v400.ConnectReplyRequest)2 ConnectReplyRequest (com.swiftmq.impl.routing.single.smqpr.v942.ConnectReplyRequest)2 MessageImpl (com.swiftmq.jms.MessageImpl)2 QueuePullTransaction (com.swiftmq.swiftlet.queue.QueuePullTransaction)2 QueueReceiver (com.swiftmq.swiftlet.queue.QueueReceiver)2 TimerListener (com.swiftmq.swiftlet.timer.event.TimerListener)2 XAContext (com.swiftmq.swiftlet.xa.XAContext)2 XidFilter (com.swiftmq.swiftlet.xa.XidFilter)2