Search in sources :

Example 21 with ServerScopedRuntimeException

use of org.apache.qpid.server.util.ServerScopedRuntimeException in project qpid-broker-j by apache.

the class FrameHandler method parse.

@Override
public ProtocolHandler parse(QpidByteBuffer in) {
    try {
        LOGGER.debug("RECV {} bytes", in.remaining());
        Error frameParsingError = null;
        int size;
        int remaining;
        List<ChannelFrameBody> channelFrameBodies = new ArrayList<>();
        while ((remaining = in.remaining()) >= 8 && frameParsingError == null) {
            size = in.getInt();
            if (size < 8) {
                frameParsingError = createFramingError("specified frame size %d smaller than minimum frame header size %d", size, 8);
                break;
            }
            if (size > _connectionHandler.getMaxFrameSize()) {
                frameParsingError = createFramingError("specified frame size %d larger than maximum frame header size %d", size, _connectionHandler.getMaxFrameSize());
                break;
            }
            if (remaining < size) {
                in.position(in.position() - 4);
                break;
            }
            int dataOffset = (in.get() << 2) & 0x3FF;
            if (dataOffset < 8) {
                frameParsingError = createFramingError("specified frame data offset %d smaller than minimum frame header size %d", dataOffset, 8);
                break;
            }
            if (dataOffset > size) {
                frameParsingError = createFramingError("specified frame data offset %d larger than the frame size %d", dataOffset, size);
                break;
            }
            byte type = in.get();
            switch(type) {
                case 0:
                    if (_isSasl) {
                        frameParsingError = createFramingError("received an AMQP frame type when expecting an SASL frame");
                    }
                    break;
                case 1:
                    if (!_isSasl) {
                        frameParsingError = createFramingError("received a SASL frame type when expecting an AMQP frame");
                    }
                    break;
                default:
                    frameParsingError = createFramingError("unknown frame type: %d", type);
            }
            if (frameParsingError != null) {
                break;
            }
            int channel = in.getUnsignedShort();
            if (dataOffset != 8) {
                in.position(in.position() + dataOffset - 8);
            }
            try (QpidByteBuffer dup = in.slice()) {
                dup.limit(size - dataOffset);
                in.position(in.position() + size - dataOffset);
                final boolean hasFrameBody = dup.hasRemaining();
                Object frameBody;
                if (hasFrameBody) {
                    frameBody = _valueHandler.parse(dup);
                    if (dup.hasRemaining()) {
                        if (frameBody instanceof Transfer) {
                            try (QpidByteBuffer payload = dup.slice()) {
                                ((Transfer) frameBody).setPayload(payload);
                            }
                        } else {
                            frameParsingError = createFramingError("Frame length %d larger than contained frame body %s.", size, frameBody);
                            break;
                        }
                    }
                } else {
                    frameBody = null;
                    if (_isSasl) {
                        frameParsingError = createFramingError("Empty (heartbeat) frames are not permitted during SASL negotiation");
                        break;
                    }
                }
                channelFrameBodies.add(new ChannelFrameBody() {

                    @Override
                    public int getChannel() {
                        return channel;
                    }

                    @Override
                    public Object getFrameBody() {
                        return frameBody;
                    }
                });
                if (_isSasl) {
                    break;
                }
            } catch (AmqpErrorException ex) {
                frameParsingError = ex.getError();
            }
        }
        if (frameParsingError != null) {
            _connectionHandler.handleError(frameParsingError);
            _errored = true;
        } else {
            _connectionHandler.receive(channelFrameBodies);
        }
    } catch (RuntimeException e) {
        if (e instanceof ServerScopedRuntimeException) {
            throw e;
        }
        LOGGER.warn("Unexpected exception handling frame", e);
        // This exception is unexpected. The up layer should handle error condition gracefully
        _connectionHandler.handleError(this.createError(AmqpError.INTERNAL_ERROR, e.toString()));
    }
    return this;
}
Also used : ArrayList(java.util.ArrayList) Error(org.apache.qpid.server.protocol.v1_0.type.transport.Error) AmqpError(org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError) ConnectionError(org.apache.qpid.server.protocol.v1_0.type.transport.ConnectionError) AmqpErrorException(org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException) ServerScopedRuntimeException(org.apache.qpid.server.util.ServerScopedRuntimeException) ServerScopedRuntimeException(org.apache.qpid.server.util.ServerScopedRuntimeException) ChannelFrameBody(org.apache.qpid.server.protocol.v1_0.type.transport.ChannelFrameBody) Transfer(org.apache.qpid.server.protocol.v1_0.type.transport.Transfer) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer)

Example 22 with ServerScopedRuntimeException

use of org.apache.qpid.server.util.ServerScopedRuntimeException in project qpid-broker-j by apache.

the class HttpManagement method doStart.

@StateTransition(currentState = { State.UNINITIALIZED, State.ERRORED }, desiredState = State.ACTIVE)
@SuppressWarnings("unused")
private ListenableFuture<Void> doStart() {
    Collection<HttpPort<?>> httpPorts = getEligibleHttpPorts(getBroker().getPorts());
    if (httpPorts.isEmpty()) {
        LOGGER.warn("HttpManagement plugin is configured but no suitable HTTP ports are available.");
    } else {
        getBroker().getEventLogger().message(ManagementConsoleMessages.STARTUP(OPERATIONAL_LOGGING_NAME));
        _server = createServer(httpPorts);
        try {
            _server.start();
            logOperationalListenMessages();
        } catch (PortBindFailureException e) {
            getBroker().getEventLogger().message(PortMessages.BIND_FAILED("HTTP", e.getAddress().getPort()));
            throw e;
        } catch (Exception e) {
            throw new ServerScopedRuntimeException("Failed to start HTTP management on ports : " + httpPorts, e);
        }
        getBroker().getEventLogger().message(ManagementConsoleMessages.READY(OPERATIONAL_LOGGING_NAME));
    }
    setState(State.ACTIVE);
    return Futures.immediateFuture(null);
}
Also used : HttpPort(org.apache.qpid.server.model.port.HttpPort) PortBindFailureException(org.apache.qpid.server.transport.PortBindFailureException) IOException(java.io.IOException) PortBindFailureException(org.apache.qpid.server.transport.PortBindFailureException) BindException(java.net.BindException) ServerScopedRuntimeException(org.apache.qpid.server.util.ServerScopedRuntimeException) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) ServerScopedRuntimeException(org.apache.qpid.server.util.ServerScopedRuntimeException) StateTransition(org.apache.qpid.server.model.StateTransition)

Example 23 with ServerScopedRuntimeException

use of org.apache.qpid.server.util.ServerScopedRuntimeException in project qpid-broker-j by apache.

the class AMQPConnection_1_0Impl method closeConnection.

private void closeConnection(final Error error) {
    _closeCause = error.getDescription();
    Close close = new Close();
    close.setError(error);
    switch(_connectionState) {
        case AWAIT_AMQP_OR_SASL_HEADER:
        case AWAIT_SASL_INIT:
        case AWAIT_SASL_RESPONSE:
        case AWAIT_AMQP_HEADER:
            throw new ConnectionScopedRuntimeException("Connection is closed before being fully established: " + error.getDescription());
        case AWAIT_OPEN:
            sendOpen(0, 0);
            sendClose(close);
            _connectionState = ConnectionState.CLOSED;
            break;
        case OPENED:
            sendClose(close);
            _connectionState = ConnectionState.CLOSE_SENT;
            addCloseTicker();
            break;
        case CLOSE_RECEIVED:
            sendClose(close);
            _connectionState = ConnectionState.CLOSED;
            addCloseTicker();
            break;
        case CLOSE_SENT:
        case CLOSED:
            // already sent our close - too late to do anything more
            break;
        default:
            throw new ServerScopedRuntimeException("Unknown state: " + _connectionState);
    }
}
Also used : ConnectionScopedRuntimeException(org.apache.qpid.server.util.ConnectionScopedRuntimeException) Close(org.apache.qpid.server.protocol.v1_0.type.transport.Close) ServerScopedRuntimeException(org.apache.qpid.server.util.ServerScopedRuntimeException)

Example 24 with ServerScopedRuntimeException

use of org.apache.qpid.server.util.ServerScopedRuntimeException in project qpid-broker-j by apache.

the class AMQPConnection_1_0Impl method receiveClose.

@Override
public void receiveClose(final int channel, final Close close) {
    switch(_connectionState) {
        case AWAIT_AMQP_OR_SASL_HEADER:
        case AWAIT_SASL_INIT:
        case AWAIT_SASL_RESPONSE:
        case AWAIT_AMQP_HEADER:
            throw new ConnectionScopedRuntimeException("Received unexpected close when AMQP connection has not been established.");
        case AWAIT_OPEN:
            closeReceived();
            closeConnection(ConnectionError.CONNECTION_FORCED, "Connection close sent before connection was opened");
            break;
        case OPENED:
            _connectionState = ConnectionState.CLOSE_RECEIVED;
            closeReceived();
            if (close.getError() != null) {
                final Error error = close.getError();
                ErrorCondition condition = error.getCondition();
                Symbol errorCondition = condition == null ? null : condition.getValue();
                LOGGER.info("{} : Connection closed with error : {} - {}", getLogSubject(), errorCondition, close.getError().getDescription());
            }
            sendClose(new Close());
            _connectionState = ConnectionState.CLOSED;
            _orderlyClose.set(true);
            addCloseTicker();
            break;
        case CLOSE_SENT:
            closeReceived();
            _connectionState = ConnectionState.CLOSED;
            _orderlyClose.set(true);
            break;
        case CLOSE_RECEIVED:
        case CLOSED:
            break;
        default:
            throw new ServerScopedRuntimeException("Unknown state: " + _connectionState);
    }
}
Also used : ConnectionScopedRuntimeException(org.apache.qpid.server.util.ConnectionScopedRuntimeException) ErrorCondition(org.apache.qpid.server.protocol.v1_0.type.ErrorCondition) Symbol(org.apache.qpid.server.protocol.v1_0.type.Symbol) ConnectionError(org.apache.qpid.server.protocol.v1_0.type.transport.ConnectionError) AmqpError(org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError) Error(org.apache.qpid.server.protocol.v1_0.type.transport.Error) Close(org.apache.qpid.server.protocol.v1_0.type.transport.Close) ServerScopedRuntimeException(org.apache.qpid.server.util.ServerScopedRuntimeException)

Example 25 with ServerScopedRuntimeException

use of org.apache.qpid.server.util.ServerScopedRuntimeException in project qpid-broker-j by apache.

the class ServerSessionDelegate method command.

@Override
public void command(ServerSession session, Method method) {
    try {
        if (!session.isClosing()) {
            Object asyncCommandMark = session.getAsyncCommandMark();
            command(session, method, false);
            Object newOutstanding = session.getAsyncCommandMark();
            if (newOutstanding == null || newOutstanding == asyncCommandMark) {
                session.processed(method);
            }
            if (newOutstanding != null) {
                session.completeAsyncCommands();
            }
            if (method.isSync()) {
                session.awaitCommandCompletion();
                session.flushProcessed();
            }
        }
    } catch (ServerScopedRuntimeException | ConnectionScopedRuntimeException e) {
        throw e;
    } catch (RuntimeException e) {
        LOGGER.error("Exception processing command", e);
        exception(session, method, ExecutionErrorCode.INTERNAL_ERROR, "Exception processing command: " + e);
    }
}
Also used : ConnectionScopedRuntimeException(org.apache.qpid.server.util.ConnectionScopedRuntimeException) ServerScopedRuntimeException(org.apache.qpid.server.util.ServerScopedRuntimeException) ConnectionScopedRuntimeException(org.apache.qpid.server.util.ConnectionScopedRuntimeException) AbstractConfiguredObject(org.apache.qpid.server.model.AbstractConfiguredObject) ServerScopedRuntimeException(org.apache.qpid.server.util.ServerScopedRuntimeException)

Aggregations

ServerScopedRuntimeException (org.apache.qpid.server.util.ServerScopedRuntimeException)45 IOException (java.io.IOException)17 GeneralSecurityException (java.security.GeneralSecurityException)10 Map (java.util.Map)10 ConnectionScopedRuntimeException (org.apache.qpid.server.util.ConnectionScopedRuntimeException)10 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)9 URL (java.net.URL)9 InputStream (java.io.InputStream)8 HttpURLConnection (java.net.HttpURLConnection)8 ConnectionBuilder (org.apache.qpid.server.util.ConnectionBuilder)8 InvocationTargetException (java.lang.reflect.InvocationTargetException)7 IllegalConfigurationException (org.apache.qpid.server.configuration.IllegalConfigurationException)6 TrustStore (org.apache.qpid.server.model.TrustStore)6 UsernamePrincipal (org.apache.qpid.server.security.auth.UsernamePrincipal)6 IdentityResolverException (org.apache.qpid.server.security.auth.manager.oauth2.IdentityResolverException)6 Field (java.lang.reflect.Field)5 Method (java.lang.reflect.Method)4 ArrayList (java.util.ArrayList)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3