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;
}
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);
}
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);
}
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;
}
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);
}
}
}
Aggregations