Search in sources :

Example 21 with AmqpErrorException

use of org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException in project qpid-broker-j by apache.

the class Session_1_0 method getSendingDestination.

public SendingDestination getSendingDestination(final Link_1_0<?, ?> link, final Source source) throws AmqpErrorException {
    SendingDestination destination = null;
    if (Boolean.TRUE.equals(source.getDynamic())) {
        MessageSource tempSource = createDynamicSource(link, source.getDynamicNodeProperties());
        if (tempSource != null) {
            source.setAddress(_primaryDomain + tempSource.getName());
        } else {
            throw new AmqpErrorException(AmqpError.INTERNAL_ERROR, "Cannot create dynamic source");
        }
    }
    String address = source.getAddress();
    if (address != null) {
        if (!address.startsWith("/") && address.contains("/")) {
            destination = createExchangeDestination(address, link.getName(), source);
        } else {
            MessageSource queue = getAddressSpace().getAttainedMessageSource(address);
            if (queue != null) {
                destination = new StandardSendingDestination(queue);
            } else {
                destination = createExchangeDestination(address, null, link.getName(), source);
            }
        }
    }
    if (destination == null) {
        throw new AmqpErrorException(AmqpError.NOT_FOUND, String.format("Could not find destination for source '%s'", source));
    }
    return destination;
}
Also used : MessageSource(org.apache.qpid.server.message.MessageSource) AmqpErrorException(org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException)

Example 22 with AmqpErrorException

use of org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException in project qpid-broker-j by apache.

the class StandardReceivingLinkEndpoint method attachReceived.

@Override
public void attachReceived(final Attach attach) throws AmqpErrorException {
    super.attachReceived(attach);
    Source source = (Source) attach.getSource();
    Target target = new Target();
    Target attachTarget = (Target) attach.getTarget();
    setDeliveryCount(new SequenceNumber(attach.getInitialDeliveryCount().intValue()));
    target.setAddress(attachTarget.getAddress());
    target.setDynamic(attachTarget.getDynamic());
    if (Boolean.TRUE.equals(attachTarget.getDynamic()) && attachTarget.getDynamicNodeProperties() != null) {
        Map<Symbol, Object> dynamicNodeProperties = new HashMap<>();
        if (attachTarget.getDynamicNodeProperties().containsKey(Session_1_0.LIFETIME_POLICY)) {
            dynamicNodeProperties.put(Session_1_0.LIFETIME_POLICY, attachTarget.getDynamicNodeProperties().get(Session_1_0.LIFETIME_POLICY));
        }
        target.setDynamicNodeProperties(dynamicNodeProperties);
    }
    target.setDurable(TerminusDurability.min(attachTarget.getDurable(), getLink().getHighestSupportedTerminusDurability()));
    final List<Symbol> targetCapabilities = new ArrayList<>();
    if (attachTarget.getCapabilities() != null) {
        final List<Symbol> desiredCapabilities = Arrays.asList(attachTarget.getCapabilities());
        if (desiredCapabilities.contains(Symbol.valueOf("temporary-topic"))) {
            targetCapabilities.add(Symbol.valueOf("temporary-topic"));
        }
        if (desiredCapabilities.contains(Symbol.valueOf("topic"))) {
            targetCapabilities.add(Symbol.valueOf("topic"));
        }
        target.setCapabilities(targetCapabilities.toArray(new Symbol[targetCapabilities.size()]));
    }
    target.setExpiryPolicy(attachTarget.getExpiryPolicy());
    final ReceivingDestination destination = getSession().getReceivingDestination(getLink(), target);
    targetCapabilities.addAll(Arrays.asList(destination.getCapabilities()));
    target.setCapabilities(targetCapabilities.toArray(new Symbol[targetCapabilities.size()]));
    setCapabilities(targetCapabilities);
    setDestination(destination);
    if (!Boolean.TRUE.equals(attach.getIncompleteUnsettled())) {
        Map remoteUnsettled = attach.getUnsettled();
        Map<Binary, DeliveryState> unsettledCopy = new HashMap<>(_unsettled);
        for (Map.Entry<Binary, DeliveryState> entry : unsettledCopy.entrySet()) {
            Binary deliveryTag = entry.getKey();
            if (remoteUnsettled == null || !remoteUnsettled.containsKey(deliveryTag)) {
                _unsettled.remove(deliveryTag);
            }
        }
    }
    getLink().setTermini(source, target);
    _rejectedOutcomeSupportedBySource = source.getOutcomes() != null && Arrays.asList(source.getOutcomes()).contains(Rejected.REJECTED_SYMBOL);
}
Also used : HashMap(java.util.HashMap) Symbol(org.apache.qpid.server.protocol.v1_0.type.Symbol) ArrayList(java.util.ArrayList) Source(org.apache.qpid.server.protocol.v1_0.type.messaging.Source) Target(org.apache.qpid.server.protocol.v1_0.type.messaging.Target) DeliveryState(org.apache.qpid.server.protocol.v1_0.type.DeliveryState) Binary(org.apache.qpid.server.protocol.v1_0.type.Binary) Map(java.util.Map) HashMap(java.util.HashMap)

Example 23 with AmqpErrorException

use of org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException in project qpid-broker-j by apache.

the class TxnCoordinatorReceivingLinkEndpoint method establishLink.

@Override
protected void establishLink(final Attach attach) throws AmqpErrorException {
    if (getSource() != null || getTarget() != null) {
        throw new IllegalStateException("LinkEndpoint and Termini should be null when establishing a Link.");
    }
    Coordinator target = new Coordinator();
    Source source = (Source) attach.getSource();
    getLink().setTermini(source, target);
    attachReceived(attach);
}
Also used : Coordinator(org.apache.qpid.server.protocol.v1_0.type.transaction.Coordinator) Source(org.apache.qpid.server.protocol.v1_0.type.messaging.Source)

Example 24 with AmqpErrorException

use of org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException in project qpid-broker-j by apache.

the class SymbolTypeConstructor method construct.

@Override
public Symbol construct(final QpidByteBuffer in, final ValueHandler handler) throws AmqpErrorException {
    int size;
    if (!in.hasRemaining(getSize())) {
        throw new AmqpErrorException(AmqpError.DECODE_ERROR, "Cannot construct symbol: insufficient input data");
    }
    if (getSize() == 1) {
        size = in.getUnsignedByte();
    } else {
        size = in.getInt();
    }
    if (!in.hasRemaining(size)) {
        throw new AmqpErrorException(AmqpError.DECODE_ERROR, "Cannot construct symbol: insufficient input data");
    }
    byte[] data = new byte[size];
    in.get(data);
    final BinaryString binaryStr = new BinaryString(data);
    Symbol symbolVal = SYMBOL_MAP.get(binaryStr);
    if (symbolVal == null) {
        symbolVal = Symbol.valueOf(new String(data, ASCII));
        SYMBOL_MAP.putIfAbsent(binaryStr, symbolVal);
    }
    return symbolVal;
}
Also used : Symbol(org.apache.qpid.server.protocol.v1_0.type.Symbol) AmqpErrorException(org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException)

Example 25 with AmqpErrorException

use of org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException in project qpid-broker-j by apache.

the class AbstractSection method decode.

private S decode(DescribedTypeConstructor<S> constructor) {
    try (QpidByteBuffer input = getEncodedForm()) {
        int originalPosition = input.position();
        int describedByte = input.get();
        if (describedByte != ValueHandler.DESCRIBED_TYPE) {
            throw new ConnectionScopedRuntimeException("Cannot decode section", new AmqpErrorException(AmqpError.DECODE_ERROR, "Not a described type."));
        }
        ValueHandler handler = new ValueHandler(TYPE_REGISTRY);
        try {
            Object descriptor = handler.parse(input);
            return constructor.construct(descriptor, input, originalPosition, handler).construct(input, handler);
        } catch (AmqpErrorException e) {
            throw new ConnectionScopedRuntimeException("Cannot decode section", e);
        }
    }
}
Also used : ConnectionScopedRuntimeException(org.apache.qpid.server.util.ConnectionScopedRuntimeException) AmqpErrorException(org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) ValueHandler(org.apache.qpid.server.protocol.v1_0.codec.ValueHandler)

Aggregations

AmqpErrorException (org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException)20 AmqpError (org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError)10 Error (org.apache.qpid.server.protocol.v1_0.type.transport.Error)10 QpidByteBuffer (org.apache.qpid.server.bytebuffer.QpidByteBuffer)8 Source (org.apache.qpid.server.protocol.v1_0.type.messaging.Source)8 MessageSource (org.apache.qpid.server.message.MessageSource)7 BaseSource (org.apache.qpid.server.protocol.v1_0.type.BaseSource)6 ConnectionScopedRuntimeException (org.apache.qpid.server.util.ConnectionScopedRuntimeException)6 ArrayList (java.util.ArrayList)5 Symbol (org.apache.qpid.server.protocol.v1_0.type.Symbol)5 EncodingRetainingSection (org.apache.qpid.server.protocol.v1_0.type.messaging.EncodingRetainingSection)5 HashMap (java.util.HashMap)4 Map (java.util.Map)4 TokenMgrError (org.apache.qpid.server.filter.selector.TokenMgrError)4 AmqpValueSection (org.apache.qpid.server.protocol.v1_0.type.messaging.AmqpValueSection)4 TransactionError (org.apache.qpid.server.protocol.v1_0.type.transaction.TransactionError)4 DeliveryState (org.apache.qpid.server.protocol.v1_0.type.DeliveryState)3 AmqpSequenceSection (org.apache.qpid.server.protocol.v1_0.type.messaging.AmqpSequenceSection)3 DataSection (org.apache.qpid.server.protocol.v1_0.type.messaging.DataSection)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2