Search in sources :

Example 1 with Binary

use of org.apache.qpid.protonj2.types.Binary in project qpid-protonj2 by apache.

the class ClientMessageSupport method convertFromOutsideMessage.

// ----- Internal Implementation
private static <E> ClientMessage<E> convertFromOutsideMessage(Message<E> source) throws ClientException {
    Header header = new Header();
    header.setDurable(source.durable());
    header.setPriority(source.priority());
    header.setTimeToLive(source.timeToLive());
    header.setFirstAcquirer(source.firstAcquirer());
    header.setDeliveryCount(source.deliveryCount());
    Properties properties = new Properties();
    properties.setMessageId(source.messageId());
    properties.setUserId(source.userId() != null ? new Binary(source.userId()) : null);
    properties.setTo(source.to());
    properties.setSubject(source.subject());
    properties.setReplyTo(source.replyTo());
    properties.setCorrelationId(source.correlationId());
    properties.setContentType(source.contentType());
    properties.setContentEncoding(source.contentEncoding());
    properties.setAbsoluteExpiryTime(source.absoluteExpiryTime());
    properties.setCreationTime(source.creationTime());
    properties.setGroupId(source.groupId());
    properties.setGroupSequence(source.groupSequence());
    properties.setReplyToGroupId(source.replyToGroupId());
    final MessageAnnotations messageAnnotations;
    if (source.hasAnnotations()) {
        messageAnnotations = new MessageAnnotations(new LinkedHashMap<>());
        source.forEachAnnotation((key, value) -> {
            messageAnnotations.getValue().put(Symbol.valueOf(key), value);
        });
    } else {
        messageAnnotations = null;
    }
    final ApplicationProperties applicationProperties;
    if (source.hasProperties()) {
        applicationProperties = new ApplicationProperties(new LinkedHashMap<>());
        source.forEachProperty((key, value) -> {
            applicationProperties.getValue().put(key, value);
        });
    } else {
        applicationProperties = null;
    }
    final Footer footer;
    if (source.hasFooters()) {
        footer = new Footer(new LinkedHashMap<>());
        source.forEachFooter((key, value) -> {
            footer.getValue().put(Symbol.valueOf(key), value);
        });
    } else {
        footer = null;
    }
    ClientMessage<E> message = new ClientMessage<>(createSectionFromValue(source.body()));
    message.header(header);
    message.properties(properties);
    message.annotations(messageAnnotations);
    message.applicationProperties(applicationProperties);
    message.footer(footer);
    return message;
}
Also used : Header(org.apache.qpid.protonj2.types.messaging.Header) MessageAnnotations(org.apache.qpid.protonj2.types.messaging.MessageAnnotations) Footer(org.apache.qpid.protonj2.types.messaging.Footer) ApplicationProperties(org.apache.qpid.protonj2.types.messaging.ApplicationProperties) Binary(org.apache.qpid.protonj2.types.Binary) Properties(org.apache.qpid.protonj2.types.messaging.Properties) ApplicationProperties(org.apache.qpid.protonj2.types.messaging.ApplicationProperties) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with Binary

use of org.apache.qpid.protonj2.types.Binary in project qpid-protonj2 by apache.

the class AbstractMessageSectionMatcher method verify.

/**
 * @param receivedBinary
 *        The received Binary value that should be validated.
 *
 * @return the number of bytes consumed from the provided Binary
 *
 * @throws RuntimeException
 *         if the provided Binary does not match expectation in some way
 */
public int verify(ByteBuf receivedBinary) throws RuntimeException {
    int length = receivedBinary.readableBytes();
    Codec data = Codec.Factory.create();
    long decoded = data.decode(receivedBinary);
    if (decoded > Integer.MAX_VALUE) {
        throw new IllegalStateException("Decoded more bytes than Binary supports holding");
    }
    if (decoded < length && !expectTrailingBytes) {
        throw new IllegalArgumentException("Expected to consume all bytes, but trailing bytes remain: Got " + length + ", consumed " + decoded);
    }
    DescribedType decodedDescribedType = data.getDescribedType();
    verifyReceivedDescribedType(decodedDescribedType);
    // Integer.MAX_VALUE
    return (int) decoded;
}
Also used : Codec(org.apache.qpid.protonj2.test.driver.codec.Codec) DescribedType(org.apache.qpid.protonj2.test.driver.codec.primitives.DescribedType)

Example 3 with Binary

use of org.apache.qpid.protonj2.types.Binary in project qpid-protonj2 by apache.

the class DeclareExpectation method accept.

/**
 * Indicates a successful transaction declaration by returning a {@link Declared}
 * disposition with the given transaction Id.
 *
 * @param txnId
 * 		byte array containing the transaction id that has been declared.
 *
 * @return this {@link DispositionInjectAction} instance.
 */
public DispositionInjectAction accept(byte[] txnId) {
    response = new DispositionInjectAction(driver);
    response.withSettled(true);
    if (txnId != null) {
        response.withState(new Declared().setTxnId(new Binary(txnId)));
    } else {
        response.withState(new Declared());
    }
    driver.addScriptedElement(response);
    return response;
}
Also used : DispositionInjectAction(org.apache.qpid.protonj2.test.driver.actions.DispositionInjectAction) Binary(org.apache.qpid.protonj2.test.driver.codec.primitives.Binary) Declared(org.apache.qpid.protonj2.test.driver.codec.transactions.Declared)

Example 4 with Binary

use of org.apache.qpid.protonj2.types.Binary in project qpid-protonj2 by apache.

the class DeclareExpectation method declared.

/**
 * Indicates a successful transaction declaration by returning a {@link Declared}
 * disposition with the given transaction Id.
 *
 * @param txnId
 * 		byte array containing the transaction id that has been declared.
 *
 * @return this {@link DispositionInjectAction} instance.
 */
public DispositionInjectAction declared(byte[] txnId) {
    response = new DispositionInjectAction(driver);
    response.withSettled(true);
    if (txnId != null) {
        response.withState(new Declared().setTxnId(new Binary(txnId)));
    } else {
        response.withState(new Declared());
    }
    driver.addScriptedElement(response);
    return response;
}
Also used : DispositionInjectAction(org.apache.qpid.protonj2.test.driver.actions.DispositionInjectAction) Binary(org.apache.qpid.protonj2.test.driver.codec.primitives.Binary) Declared(org.apache.qpid.protonj2.test.driver.codec.transactions.Declared)

Example 5 with Binary

use of org.apache.qpid.protonj2.types.Binary in project qpid-protonj2 by apache.

the class DataTypeEncoder method writeRawArray.

@Override
public void writeRawArray(ProtonBuffer buffer, EncoderState state, Object[] values) {
    buffer.writeByte(EncodingCodes.DESCRIBED_TYPE_INDICATOR);
    state.getEncoder().writeUnsignedLong(buffer, state, getDescriptorCode());
    buffer.writeByte(EncodingCodes.VBIN32);
    for (Object value : values) {
        final Binary binary = ((Data) value).getBinary();
        buffer.writeInt(binary.getLength());
        buffer.writeBytes(binary.getArray(), binary.getArrayOffset(), binary.getLength());
    }
}
Also used : Data(org.apache.qpid.protonj2.types.messaging.Data) Binary(org.apache.qpid.protonj2.types.Binary)

Aggregations

Binary (org.apache.qpid.protonj2.types.Binary)86 ProtonBuffer (org.apache.qpid.protonj2.buffer.ProtonBuffer)62 InputStream (java.io.InputStream)45 ProtonBufferInputStream (org.apache.qpid.protonj2.buffer.ProtonBufferInputStream)45 Test (org.junit.jupiter.api.Test)38 Data (org.apache.qpid.protonj2.types.messaging.Data)15 Engine (org.apache.qpid.protonj2.engine.Engine)13 AtomicReference (java.util.concurrent.atomic.AtomicReference)11 DecodeException (org.apache.qpid.protonj2.codec.DecodeException)9 Connection (org.apache.qpid.protonj2.engine.Connection)9 Session (org.apache.qpid.protonj2.engine.Session)9 ProtonTestConnector (org.apache.qpid.protonj2.test.driver.ProtonTestConnector)9 SaslInit (org.apache.qpid.protonj2.types.security.SaslInit)9 Random (java.util.Random)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)6 TransactionManager (org.apache.qpid.protonj2.engine.TransactionManager)6 Symbol (org.apache.qpid.protonj2.types.Symbol)6 SaslChallenge (org.apache.qpid.protonj2.types.security.SaslChallenge)5 SaslResponse (org.apache.qpid.protonj2.types.security.SaslResponse)5 Declared (org.apache.qpid.protonj2.types.transactions.Declared)5