use of org.apache.qpid.server.protocol.v1_0.type.Symbol in project qpid-broker-j by apache.
the class SendingLinkEndpoint method prepareConsumerOptionsAndFilters.
private void prepareConsumerOptionsAndFilters(final SendingDestination destination) throws AmqpErrorException {
// TODO QPID-7952: this method might modify the source. this is not good encapsulation. furthermore if it does so then it should inform the link/linkregistry about it!
_destination = destination;
final Source source = getSource();
EnumSet<ConsumerOption> options = EnumSet.noneOf(ConsumerOption.class);
boolean noLocal = false;
JMSSelectorFilter messageFilter = null;
if (destination instanceof ExchangeSendingDestination) {
options.add(ConsumerOption.ACQUIRES);
options.add(ConsumerOption.SEES_REQUEUES);
} else if (destination instanceof StandardSendingDestination) {
MessageSource messageSource = _destination.getMessageSource();
if (messageSource instanceof Queue && ((Queue<?>) messageSource).getAvailableAttributes().contains("topic")) {
source.setDistributionMode(StdDistMode.COPY);
}
Map<Symbol, Filter> filters = source.getFilter();
Map<Symbol, Filter> actualFilters = new HashMap<>();
if (filters != null) {
for (Map.Entry<Symbol, Filter> entry : filters.entrySet()) {
if (entry.getValue() instanceof NoLocalFilter) {
actualFilters.put(entry.getKey(), entry.getValue());
noLocal = true;
} else if (messageFilter == null && entry.getValue() instanceof org.apache.qpid.server.protocol.v1_0.type.messaging.JMSSelectorFilter) {
org.apache.qpid.server.protocol.v1_0.type.messaging.JMSSelectorFilter selectorFilter = (org.apache.qpid.server.protocol.v1_0.type.messaging.JMSSelectorFilter) entry.getValue();
try {
messageFilter = new JMSSelectorFilter(selectorFilter.getValue());
actualFilters.put(entry.getKey(), entry.getValue());
} catch (ParseException | SelectorParsingException | TokenMgrError e) {
Error error = new Error();
error.setCondition(AmqpError.INVALID_FIELD);
error.setDescription("Invalid JMS Selector: " + selectorFilter.getValue());
error.setInfo(Collections.singletonMap(Symbol.valueOf("field"), Symbol.valueOf("filter")));
throw new AmqpErrorException(error);
}
}
}
}
source.setFilter(actualFilters.isEmpty() ? null : actualFilters);
if (source.getDistributionMode() != StdDistMode.COPY) {
options.add(ConsumerOption.ACQUIRES);
options.add(ConsumerOption.SEES_REQUEUES);
}
} else {
throw new ConnectionScopedRuntimeException("Unknown destination type");
}
if (noLocal) {
options.add(ConsumerOption.NO_LOCAL);
}
FilterManager filters = null;
if (messageFilter != null) {
filters = new FilterManager();
filters.add(messageFilter.getName(), messageFilter);
}
_consumerOptions = options;
_consumerFilters = filters;
}
use of org.apache.qpid.server.protocol.v1_0.type.Symbol in project qpid-broker-j by apache.
the class SendingLinkEndpoint method receiveFlow.
@Override
public void receiveFlow(final Flow flow) {
UnsignedInteger receiverDeliveryCount = flow.getDeliveryCount();
UnsignedInteger receiverLinkCredit = flow.getLinkCredit();
setDrain(flow.getDrain());
Map<Symbol, Object> properties = flow.getProperties();
if (properties != null) {
final Binary transactionId = (Binary) properties.get(Symbol.valueOf("txn-id"));
if (transactionId != null) {
try {
getSession().getTransaction(transactionId);
} catch (UnknownTransactionException e) {
close(new Error(TransactionError.UNKNOWN_ID, e.getMessage()));
return;
}
}
_transactionId = transactionId;
}
if (receiverDeliveryCount == null) {
setLinkCredit(receiverLinkCredit);
} else {
// 2.6.7 Flow Control : link_credit_snd := delivery_count_rcv + link_credit_rcv - delivery_count_snd
UnsignedInteger limit = receiverDeliveryCount.add(receiverLinkCredit);
if (limit.compareTo(getDeliveryCount().unsignedIntegerValue()) <= 0) {
setLinkCredit(UnsignedInteger.valueOf(0));
} else {
setLinkCredit(limit.subtract(getDeliveryCount().unsignedIntegerValue()));
}
}
// send flow when echo=true or drain=true but link credit is zero
boolean sendFlow = Boolean.TRUE.equals(flow.getEcho()) || (Boolean.TRUE.equals(flow.getDrain()) && getLinkCredit().equals(UnsignedInteger.ZERO));
flowStateChanged();
if (sendFlow) {
sendFlow();
}
}
use of org.apache.qpid.server.protocol.v1_0.type.Symbol in project qpid-broker-j by apache.
the class SymbolArrayWriter method getEncodedValue.
private static byte[] getEncodedValue(final Symbol[] value) {
byte[] encodedVal;
int length;
boolean useSmallConstructor = useSmallConstructor(value);
boolean isSmall = useSmallConstructor && canFitInSmall(value);
if (isSmall) {
length = 2;
} else {
length = 5;
}
for (Symbol symbol : value) {
length += symbol.length();
}
length += value.length * (useSmallConstructor ? 1 : 4);
encodedVal = new byte[length];
ByteBuffer buf = ByteBuffer.wrap(encodedVal);
if (isSmall) {
buf.put((byte) value.length);
buf.put(SymbolWriter.SMALL_ENCODING_CODE);
} else {
buf.putInt(value.length);
buf.put(SymbolWriter.LARGE_ENCODING_CODE);
}
for (Symbol symbol : value) {
if (isSmall) {
buf.put((byte) symbol.length());
} else {
buf.putInt(symbol.length());
}
for (int i = 0; i < symbol.length(); i++) {
buf.put((byte) symbol.charAt(i));
}
}
return encodedVal;
}
use of org.apache.qpid.server.protocol.v1_0.type.Symbol in project qpid-broker-j by apache.
the class MessageConverter_Internal_to_1_0Test method doTest.
private void doTest(final Serializable messageBytes, final String mimeType, final Class<? extends EncodingRetainingSection<?>> expectedBodySection, final Object expectedContent, final Symbol expectedContentType, final Byte expectedJmsTypeAnnotation) throws Exception {
final InternalMessage sourceMessage = getAmqMessage(messageBytes, mimeType);
final Message_1_0 convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
final QpidByteBuffer content = convertedMessage.getContent();
List<EncodingRetainingSection<?>> sections = getEncodingRetainingSections(content, 1);
EncodingRetainingSection<?> encodingRetainingSection = sections.get(0);
assertEquals("Unexpected section type", expectedBodySection, encodingRetainingSection.getClass());
if (expectedContent instanceof byte[]) {
assertArrayEquals("Unexpected content", ((byte[]) expectedContent), ((Binary) encodingRetainingSection.getValue()).getArray());
} else {
assertEquals("Unexpected content", expectedContent, encodingRetainingSection.getValue());
}
Symbol contentType = getContentType(convertedMessage);
if (expectedContentType == null) {
assertNull("Content type should be null", contentType);
} else {
assertEquals("Unexpected content type", expectedContentType, contentType);
}
Byte jmsMessageTypeAnnotation = getJmsMessageTypeAnnotation(convertedMessage);
if (expectedJmsTypeAnnotation == null) {
assertEquals("Unexpected annotation 'x-opt-jms-msg-type'", null, jmsMessageTypeAnnotation);
} else {
assertEquals("Unexpected annotation 'x-opt-jms-msg-type'", expectedJmsTypeAnnotation, jmsMessageTypeAnnotation);
}
}
use of org.apache.qpid.server.protocol.v1_0.type.Symbol in project qpid-broker-j by apache.
the class AMQPConnection_1_0Impl method processProtocolHeader.
private void processProtocolHeader(final QpidByteBuffer msg) {
if (msg.remaining() >= 8) {
byte[] header = new byte[8];
msg.get(header);
final AuthenticationProvider<?> authenticationProvider = getPort().getAuthenticationProvider();
if (Arrays.equals(header, SASL_HEADER)) {
if (_saslComplete) {
throw new ConnectionScopedRuntimeException("SASL Layer header received after SASL already established");
}
try (QpidByteBuffer protocolHeader = QpidByteBuffer.wrap(SASL_HEADER)) {
getSender().send(protocolHeader);
}
SaslMechanisms mechanisms = new SaslMechanisms();
ArrayList<Symbol> mechanismsList = new ArrayList<>();
for (String name : authenticationProvider.getAvailableMechanisms(getTransport().isSecure())) {
mechanismsList.add(Symbol.valueOf(name));
}
mechanisms.setSaslServerMechanisms(mechanismsList.toArray(new Symbol[mechanismsList.size()]));
send(new SASLFrame(mechanisms), null);
_connectionState = ConnectionState.AWAIT_SASL_INIT;
_frameHandler = getFrameHandler(true);
} else if (Arrays.equals(header, AMQP_HEADER)) {
if (!_saslComplete) {
final List<String> mechanisms = authenticationProvider.getAvailableMechanisms(getTransport().isSecure());
if (mechanisms.contains(ExternalAuthenticationManagerImpl.MECHANISM_NAME) && getNetwork().getPeerPrincipal() != null) {
setUserPrincipal(new AuthenticatedPrincipal(getNetwork().getPeerPrincipal()));
} else if (mechanisms.contains(AnonymousAuthenticationManager.MECHANISM_NAME)) {
setUserPrincipal(new AuthenticatedPrincipal(((AnonymousAuthenticationManager) authenticationProvider).getAnonymousPrincipal()));
} else {
LOGGER.warn("{} : attempt to initiate AMQP connection without correctly authenticating", getLogSubject());
_connectionState = ConnectionState.CLOSED;
getNetwork().close();
}
}
try (QpidByteBuffer protocolHeader = QpidByteBuffer.wrap(AMQP_HEADER)) {
getSender().send(protocolHeader);
}
_connectionState = ConnectionState.AWAIT_OPEN;
_frameHandler = getFrameHandler(false);
} else {
LOGGER.warn("{} : unknown AMQP header {}", getLogSubject(), Functions.str(header));
_connectionState = ConnectionState.CLOSED;
getNetwork().close();
}
}
}
Aggregations