Search in sources :

Example 1 with ProtocolHeader

use of com.swiftmq.amqp.ProtocolHeader in project swiftmq-ce by iitsoftware.

the class VersionedConnection method dataAvailable.

public void dataAvailable(LengthCaptureDataInput in) {
    if (delegate != null)
        delegate.dataAvailable(in);
    else {
        try {
            boolean valid = true;
            ProtocolHeader header = new ProtocolHeader();
            header.readContent(in);
            if (ctx.protSpace.enabled)
                ctx.protSpace.trace("amqp", toString() + "/RCV: " + header);
            if (header.equals(AMQPHandlerFactory.AMQP_INIT)) {
                protHandler.setProtHeaderExpected(false);
                protHandler.setMode091(true);
                HandlerFactory factory = getFactory(header, amqpHandlerList);
                if (factory != null) {
                    delegate = factory.createHandler(this);
                    try {
                        usage.getProperty("amqp-version").setValue(delegate.getVersion());
                    } catch (Exception e) {
                    }
                } else {
                    sendAndClose(connection, header, ((Pair) amqpHandlerList.get(amqpHandlerList.size() - 1)).header);
                    valid = false;
                }
            } else {
                if (requiresSasl) {
                    if (saslFinished) {
                        HandlerFactory factory = getFactory(header, amqpHandlerList);
                        if (factory != null) {
                            // start AMQP
                            protHandler.setProtHeaderExpected(false);
                            delegate = factory.createHandler(this);
                            try {
                                usage.getProperty("amqp-version").setValue(delegate.getVersion());
                            } catch (Exception e) {
                            }
                        } else {
                            // send AMQP_INIT, close
                            sendAndClose(connection, header, ((Pair) amqpHandlerList.get(amqpHandlerList.size() - 1)).header);
                            valid = false;
                        }
                    } else {
                        HandlerFactory factory = getFactory(header, saslHandlerList);
                        if (factory != null) {
                            // start SASL
                            protHandler.setProtHeaderExpected(false);
                            delegate = factory.createHandler(this);
                        } else {
                            // send SASL_INIT, close
                            sendAndClose(connection, header, ((Pair) saslHandlerList.get(saslHandlerList.size() - 1)).header);
                            valid = false;
                        }
                    }
                } else {
                    if (activeLogin == null)
                        activeLogin = ctx.authSwiftlet.createActiveLogin("anonymous", "AMQP");
                    HandlerFactory factory = getFactory(header, amqpHandlerList);
                    if (factory != null) {
                        // start AMQP
                        protHandler.setProtHeaderExpected(false);
                        delegate = factory.createHandler(this);
                    } else {
                        // send AMQP_INIT, close
                        sendAndClose(connection, header, ((Pair) amqpHandlerList.get(amqpHandlerList.size() - 1)).header);
                        valid = false;
                    }
                }
            }
        } catch (Exception e) {
            ctx.networkSwiftlet.getConnectionManager().removeConnection(connection);
        }
    }
}
Also used : AMQPHandlerFactory(com.swiftmq.impl.amqp.amqp.v00_09_01.AMQPHandlerFactory) ProtocolHeader(com.swiftmq.amqp.ProtocolHeader) IOException(java.io.IOException)

Example 2 with ProtocolHeader

use of com.swiftmq.amqp.ProtocolHeader in project swiftmq-client by iitsoftware.

the class ConnectionDispatcher method dataAvailable.

public void dataAvailable(LengthCaptureDataInput in) {
    try {
        if (connectionDisabled) {
            if (fTracer.isEnabled())
                fTracer.trace(toString(), "Connection is disabled, ignore inbound traffic");
            return;
        }
        lastActivity = System.currentTimeMillis();
        if (awaitProtocolHeader) {
            ProtocolHeader header = new ProtocolHeader();
            header.readContent(in);
            awaitProtocolHeader = false;
            protocolHandler.setProtHeaderExpected(false);
            if (fTracer.isEnabled())
                fTracer.trace("amqp", "RCV: " + header);
            dispatch(new POProtocolResponse(header));
        } else {
            if (saslActive) {
                SaslFrameIF frame = FrameReader.createSaslFrame(in);
                int size = frame.getPredictedSize();
                if (size > maxLocalFrameSize) {
                    if (fTracer.isEnabled())
                        fTracer.trace(toString(), ", dataAvailable, Frame size (" + size + ") > max frame size (" + maxLocalFrameSize + ")");
                    connectionDisabled = true;
                    new Disconnecter(ConnectionError.FRAMING_ERROR.getValue(), "Frame size (" + size + ") > max frame size (" + maxLocalFrameSize + ")").start();
                } else {
                    if (fTracer.isEnabled())
                        fTracer.trace("amqp", "RCV[" + ((AMQPFrame) frame).getChannel() + "] (size=" + size + "): " + frame);
                    frame.accept(dispatchVisitor);
                }
            } else {
                FrameIF frame = FrameReader.createFrame(in);
                int size = frame.getPredictedSize();
                if (size > maxLocalFrameSize) {
                    if (fTracer.isEnabled())
                        fTracer.trace(toString(), ", dataAvailable, Frame size (" + size + ") > max frame size (" + maxLocalFrameSize + ")");
                    connectionDisabled = true;
                    new Disconnecter(ConnectionError.FRAMING_ERROR.getValue(), "Frame size (" + size + ") > max frame size (" + maxLocalFrameSize + ")").start();
                } else {
                    if (fTracer.isEnabled())
                        fTracer.trace("amqp", "RCV[" + ((AMQPFrame) frame).getChannel() + "] (size=" + size + "): " + frame + (((AMQPFrame) frame).getPayload() != null ? " | payload size=" + ((AMQPFrame) frame).getPayload().length : ""));
                    frame.accept(dispatchVisitor);
                }
            }
        }
    } catch (Exception e) {
        new Disconnecter(ConnectionError.FRAMING_ERROR.getValue(), e.toString()).start();
    }
}
Also used : AMQPFrame(com.swiftmq.amqp.v100.transport.AMQPFrame) ProtocolHeader(com.swiftmq.amqp.ProtocolHeader) SaslException(javax.security.sasl.SaslException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException)

Aggregations

ProtocolHeader (com.swiftmq.amqp.ProtocolHeader)2 IOException (java.io.IOException)2 AMQPFrame (com.swiftmq.amqp.v100.transport.AMQPFrame)1 AMQPHandlerFactory (com.swiftmq.impl.amqp.amqp.v00_09_01.AMQPHandlerFactory)1 UnknownHostException (java.net.UnknownHostException)1 SaslException (javax.security.sasl.SaslException)1