Search in sources :

Example 16 with Symbol

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;
}
Also used : ConsumerOption(org.apache.qpid.server.consumer.ConsumerOption) MessageSource(org.apache.qpid.server.message.MessageSource) BaseSource(org.apache.qpid.server.protocol.v1_0.type.BaseSource) Source(org.apache.qpid.server.protocol.v1_0.type.messaging.Source) FilterManager(org.apache.qpid.server.filter.FilterManager) SelectorParsingException(org.apache.qpid.server.filter.SelectorParsingException) ConnectionScopedRuntimeException(org.apache.qpid.server.util.ConnectionScopedRuntimeException) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) Queue(org.apache.qpid.server.model.Queue) JMSSelectorFilter(org.apache.qpid.server.filter.JMSSelectorFilter) NoLocalFilter(org.apache.qpid.server.protocol.v1_0.type.messaging.NoLocalFilter) MessageSource(org.apache.qpid.server.message.MessageSource) TransactionError(org.apache.qpid.server.protocol.v1_0.type.transaction.TransactionError) TokenMgrError(org.apache.qpid.server.filter.selector.TokenMgrError) Error(org.apache.qpid.server.protocol.v1_0.type.transport.Error) AmqpError(org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError) AmqpErrorException(org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException) TokenMgrError(org.apache.qpid.server.filter.selector.TokenMgrError) ParseException(org.apache.qpid.server.filter.selector.ParseException) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap)

Example 17 with Symbol

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();
    }
}
Also used : Symbol(org.apache.qpid.server.protocol.v1_0.type.Symbol) TransactionError(org.apache.qpid.server.protocol.v1_0.type.transaction.TransactionError) TokenMgrError(org.apache.qpid.server.filter.selector.TokenMgrError) Error(org.apache.qpid.server.protocol.v1_0.type.transport.Error) AmqpError(org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError) Binary(org.apache.qpid.server.protocol.v1_0.type.Binary) UnsignedInteger(org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger)

Example 18 with Symbol

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;
}
Also used : Symbol(org.apache.qpid.server.protocol.v1_0.type.Symbol) ByteBuffer(java.nio.ByteBuffer)

Example 19 with Symbol

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);
    }
}
Also used : InternalMessage(org.apache.qpid.server.message.internal.InternalMessage) EncodingRetainingSection(org.apache.qpid.server.protocol.v1_0.type.messaging.EncodingRetainingSection) Symbol(org.apache.qpid.server.protocol.v1_0.type.Symbol) NamedAddressSpace(org.apache.qpid.server.model.NamedAddressSpace) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer)

Example 20 with Symbol

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();
        }
    }
}
Also used : Symbol(org.apache.qpid.server.protocol.v1_0.type.Symbol) SASLFrame(org.apache.qpid.server.protocol.v1_0.framing.SASLFrame) ArrayList(java.util.ArrayList) SaslMechanisms(org.apache.qpid.server.protocol.v1_0.type.security.SaslMechanisms) AuthenticatedPrincipal(org.apache.qpid.server.security.auth.AuthenticatedPrincipal) AnonymousAuthenticationManager(org.apache.qpid.server.security.auth.manager.AnonymousAuthenticationManager) ConnectionScopedRuntimeException(org.apache.qpid.server.util.ConnectionScopedRuntimeException) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) Futures.allAsList(com.google.common.util.concurrent.Futures.allAsList) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

Symbol (org.apache.qpid.server.protocol.v1_0.type.Symbol)27 Source (org.apache.qpid.server.protocol.v1_0.type.messaging.Source)11 NamedAddressSpace (org.apache.qpid.server.model.NamedAddressSpace)7 Map (java.util.Map)6 BaseSource (org.apache.qpid.server.protocol.v1_0.type.BaseSource)6 Binary (org.apache.qpid.server.protocol.v1_0.type.Binary)6 Target (org.apache.qpid.server.protocol.v1_0.type.messaging.Target)6 Properties (org.apache.qpid.server.protocol.v1_0.type.messaging.Properties)5 AmqpError (org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError)5 Error (org.apache.qpid.server.protocol.v1_0.type.transport.Error)5 HashMap (java.util.HashMap)4 LinkedHashMap (java.util.LinkedHashMap)4 QpidByteBuffer (org.apache.qpid.server.bytebuffer.QpidByteBuffer)4 TokenMgrError (org.apache.qpid.server.filter.selector.TokenMgrError)4 UnsignedInteger (org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger)4 MessageAnnotations (org.apache.qpid.server.protocol.v1_0.type.messaging.MessageAnnotations)4 TransactionError (org.apache.qpid.server.protocol.v1_0.type.transaction.TransactionError)4 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3