Search in sources :

Example 26 with AmqpValue

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

the class MessageEncoder method getPayload.

public QpidByteBuffer getPayload() {
    List<QpidByteBuffer> payload = new ArrayList<>();
    if (_header != null) {
        payload.add(_header.createEncodingRetainingSection().getEncodedForm());
    }
    if (_properties != null) {
        payload.add(_properties.createEncodingRetainingSection().getEncodedForm());
    }
    if (_applicationProperties != null) {
        payload.add(new ApplicationProperties(_applicationProperties).createEncodingRetainingSection().getEncodedForm());
    }
    if (_data.isEmpty()) {
        throw new IllegalStateException("Message should have at least one data section");
    }
    List<EncodingRetainingSection<?>> dataSections = new ArrayList<>();
    if (_data.size() == 1) {
        AmqpValue amqpValue = new AmqpValue(_data.get(0));
        dataSections.add(amqpValue.createEncodingRetainingSection());
    } else {
        throw new UnsupportedOperationException("Unsupported yet");
    }
    for (EncodingRetainingSection<?> section : dataSections) {
        payload.add(section.getEncodedForm());
        section.dispose();
    }
    QpidByteBuffer combined = QpidByteBuffer.concatenate(payload);
    payload.forEach(QpidByteBuffer::dispose);
    return combined;
}
Also used : EncodingRetainingSection(org.apache.qpid.server.protocol.v1_0.type.messaging.EncodingRetainingSection) ArrayList(java.util.ArrayList) ApplicationProperties(org.apache.qpid.server.protocol.v1_0.type.messaging.ApplicationProperties) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) AmqpValue(org.apache.qpid.server.protocol.v1_0.type.messaging.AmqpValue)

Example 27 with AmqpValue

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

the class TxnCoordinatorReceivingLinkEndpoint method receiveDelivery.

@Override
protected Error receiveDelivery(Delivery delivery) {
    // Only interested in the amqp-value section that holds the message to the coordinator
    try (QpidByteBuffer payload = delivery.getPayload()) {
        List<EncodingRetainingSection<?>> sections = getSectionDecoder().parseAll(payload);
        boolean amqpValueSectionFound = false;
        for (EncodingRetainingSection section : sections) {
            try {
                if (section instanceof AmqpValueSection) {
                    if (amqpValueSectionFound) {
                        throw new ConnectionScopedRuntimeException("Received more than one AmqpValue sections");
                    }
                    amqpValueSectionFound = true;
                    Object command = section.getValue();
                    Session_1_0 session = getSession();
                    AMQPConnection_1_0<?> connection = session.getConnection();
                    connection.receivedComplete();
                    if (command instanceof Declare) {
                        final IdentifiedTransaction txn = connection.createIdentifiedTransaction();
                        _createdTransactions.put(txn.getId(), txn.getServerTransaction());
                        long notificationRepeatPeriod = getSession().getContextValue(Long.class, Session.TRANSACTION_TIMEOUT_NOTIFICATION_REPEAT_PERIOD);
                        connection.registerTransactionTickers(txn.getServerTransaction(), this::doTimeoutAction, notificationRepeatPeriod);
                        Declared state = new Declared();
                        state.setTxnId(Session_1_0.integerToTransactionId(txn.getId()));
                        updateDisposition(delivery.getDeliveryTag(), state, true);
                    } else if (command instanceof Discharge) {
                        Discharge discharge = (Discharge) command;
                        Error error = discharge(discharge.getTxnId(), Boolean.TRUE.equals(discharge.getFail()));
                        final DeliveryState outcome;
                        if (error == null) {
                            outcome = new Accepted();
                        } else if (Arrays.asList(getSource().getOutcomes()).contains(Rejected.REJECTED_SYMBOL)) {
                            final Rejected rejected = new Rejected();
                            rejected.setError(error);
                            outcome = rejected;
                            error = null;
                        } else {
                            outcome = null;
                        }
                        if (error == null) {
                            updateDisposition(delivery.getDeliveryTag(), outcome, true);
                        }
                        return error;
                    } else {
                        throw new ConnectionScopedRuntimeException(String.format("Received unknown command '%s'", command.getClass().getSimpleName()));
                    }
                }
            } finally {
                section.dispose();
            }
        }
        if (!amqpValueSectionFound) {
            throw new ConnectionScopedRuntimeException("Received no AmqpValue section");
        }
    } catch (AmqpErrorException e) {
        return e.getError();
    }
    return null;
}
Also used : EncodingRetainingSection(org.apache.qpid.server.protocol.v1_0.type.messaging.EncodingRetainingSection) Error(org.apache.qpid.server.protocol.v1_0.type.transport.Error) AmqpError(org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError) TransactionError(org.apache.qpid.server.protocol.v1_0.type.transaction.TransactionError) AmqpErrorException(org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException) Rejected(org.apache.qpid.server.protocol.v1_0.type.messaging.Rejected) Declare(org.apache.qpid.server.protocol.v1_0.type.transaction.Declare) Declared(org.apache.qpid.server.protocol.v1_0.type.transaction.Declared) Discharge(org.apache.qpid.server.protocol.v1_0.type.transaction.Discharge) Accepted(org.apache.qpid.server.protocol.v1_0.type.messaging.Accepted) DeliveryState(org.apache.qpid.server.protocol.v1_0.type.DeliveryState) ConnectionScopedRuntimeException(org.apache.qpid.server.util.ConnectionScopedRuntimeException) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) AmqpValueSection(org.apache.qpid.server.protocol.v1_0.type.messaging.AmqpValueSection)

Example 28 with AmqpValue

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

the class MessageConverter_v1_0_to_InternalTest method testAmqpValueWithNullWithObjectMessageAnnotation.

public void testAmqpValueWithNullWithObjectMessageAnnotation() throws Exception {
    final Object expected = null;
    final AmqpValue amqpValue = new AmqpValue(expected);
    Message_1_0 sourceMessage = createTestMessage(OBJECT_MESSAGE_MESSAGE_ANNOTATION, amqpValue.createEncodingRetainingSection());
    final InternalMessage convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
    assertEquals("Unexpected mime type", "application/x-java-serialized-object", convertedMessage.getMessageHeader().getMimeType());
    assertNull("Unexpected content", convertedMessage.getMessageBody());
}
Also used : InternalMessage(org.apache.qpid.server.message.internal.InternalMessage) NamedAddressSpace(org.apache.qpid.server.model.NamedAddressSpace) AmqpValue(org.apache.qpid.server.protocol.v1_0.type.messaging.AmqpValue)

Example 29 with AmqpValue

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

the class MessageConverter_v1_0_to_InternalTest method testAmqpValueWithNull.

public void testAmqpValueWithNull() throws Exception {
    final Object expected = null;
    final AmqpValue amqpValue = new AmqpValue(expected);
    Message_1_0 sourceMessage = createTestMessage(amqpValue.createEncodingRetainingSection());
    final InternalMessage convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
    assertEquals("Unexpected mime type", null, convertedMessage.getMessageHeader().getMimeType());
    assertNull("Unexpected content", convertedMessage.getMessageBody());
}
Also used : InternalMessage(org.apache.qpid.server.message.internal.InternalMessage) NamedAddressSpace(org.apache.qpid.server.model.NamedAddressSpace) AmqpValue(org.apache.qpid.server.protocol.v1_0.type.messaging.AmqpValue)

Example 30 with AmqpValue

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

the class MessageConverter_v1_0_to_InternalTest method testAmqpValueWithString.

public void testAmqpValueWithString() throws Exception {
    final String expected = "testContent";
    final AmqpValue amqpValue = new AmqpValue(expected);
    Message_1_0 sourceMessage = createTestMessage(amqpValue.createEncodingRetainingSection());
    final InternalMessage convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
    assertEquals("Unexpected mime type", "text/plain", convertedMessage.getMessageHeader().getMimeType());
    assertEquals("Unexpected content", expected, convertedMessage.getMessageBody());
}
Also used : InternalMessage(org.apache.qpid.server.message.internal.InternalMessage) NamedAddressSpace(org.apache.qpid.server.model.NamedAddressSpace) AmqpValue(org.apache.qpid.server.protocol.v1_0.type.messaging.AmqpValue)

Aggregations

AmqpValue (org.apache.qpid.server.protocol.v1_0.type.messaging.AmqpValue)57 NamedAddressSpace (org.apache.qpid.server.model.NamedAddressSpace)55 Message_1_0 (org.apache.qpid.server.protocol.v1_0.Message_1_0)40 QpidByteBuffer (org.apache.qpid.server.bytebuffer.QpidByteBuffer)21 MessageTransferMessage (org.apache.qpid.server.protocol.v0_10.MessageTransferMessage)17 AMQMessage (org.apache.qpid.server.protocol.v0_8.AMQMessage)17 InternalMessage (org.apache.qpid.server.message.internal.InternalMessage)15 ApplicationProperties (org.apache.qpid.server.protocol.v1_0.type.messaging.ApplicationProperties)11 Properties (org.apache.qpid.server.protocol.v1_0.type.messaging.Properties)10 LinkedHashMap (java.util.LinkedHashMap)8 HashMap (java.util.HashMap)7 Map (java.util.Map)7 ArrayList (java.util.ArrayList)6 MessageConversionException (org.apache.qpid.server.protocol.converter.MessageConversionException)6 Binary (org.apache.qpid.server.protocol.v1_0.type.Binary)6 JmsMapMessageToMap (org.apache.qpid.server.typedmessage.mimecontentconverter.JmsMapMessageToMap)6 MapToJmsMapMessage (org.apache.qpid.server.typedmessage.mimecontentconverter.MapToJmsMapMessage)4 MessageAnnotations (org.apache.qpid.server.protocol.v1_0.type.messaging.MessageAnnotations)3 Section (org.apache.qpid.amqp_1_0.type.Section)2 AmqpValue (org.apache.qpid.amqp_1_0.type.messaging.AmqpValue)2