Search in sources :

Example 66 with Transfer

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

the class Interaction method copyTransfer.

private Transfer copyTransfer(final Transfer transfer) {
    final Transfer transferCopy = new Transfer();
    transferCopy.setHandle(transfer.getHandle());
    transferCopy.setDeliveryId(transfer.getDeliveryId());
    transferCopy.setDeliveryTag(transfer.getDeliveryTag());
    transferCopy.setMessageFormat(transfer.getMessageFormat());
    transferCopy.setSettled(transfer.getSettled());
    transferCopy.setMore(transfer.getMore());
    transferCopy.setRcvSettleMode(transfer.getRcvSettleMode());
    transferCopy.setState(transfer.getState());
    transferCopy.setResume(transfer.getResume());
    transferCopy.setAborted(transfer.getAborted());
    transferCopy.setBatchable(transfer.getBatchable());
    try (QpidByteBuffer payload = transfer.getPayload()) {
        if (payload != null) {
            transferCopy.setPayload(payload);
        }
    }
    return transferCopy;
}
Also used : Transfer(org.apache.qpid.server.protocol.v1_0.type.transport.Transfer) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer)

Example 67 with Transfer

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

the class Interaction method createTransactionTransfer.

private Transfer createTransactionTransfer(final UnsignedInteger handle) {
    Transfer transfer = new Transfer();
    transfer.setHandle(handle);
    transfer.setDeliveryId(getNextDeliveryId());
    transfer.setDeliveryTag(new Binary(("transaction-" + transfer.getDeliveryId()).getBytes(StandardCharsets.UTF_8)));
    return transfer;
}
Also used : Transfer(org.apache.qpid.server.protocol.v1_0.type.transport.Transfer) Binary(org.apache.qpid.server.protocol.v1_0.type.Binary)

Example 68 with Transfer

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

the class Interaction method txnDischarge.

public Interaction txnDischarge(final InteractionTransactionalState txnState, boolean failed) throws Exception {
    final Discharge discharge = new Discharge();
    discharge.setTxnId(txnState.getCurrentTransactionId());
    discharge.setFail(failed);
    Transfer transfer = createTransactionTransfer(txnState.getHandle());
    transferPayload(transfer, discharge);
    sendPerformativeAndChainFuture(transfer, _sessionChannel);
    Disposition declareTransactionDisposition = null;
    Flow coordinatorFlow = null;
    do {
        consumeResponse(Disposition.class, Flow.class);
        Response<?> response = getLatestResponse();
        if (response.getBody() instanceof Disposition) {
            declareTransactionDisposition = (Disposition) response.getBody();
        }
        if (response.getBody() instanceof Flow) {
            final Flow flowResponse = (Flow) response.getBody();
            if (flowResponse.getHandle().equals(txnState.getHandle())) {
                coordinatorFlow = flowResponse;
            }
        }
    } while (declareTransactionDisposition == null || coordinatorFlow == null);
    assertThat(declareTransactionDisposition.getSettled(), is(equalTo(true)));
    assertThat(declareTransactionDisposition.getState(), is(instanceOf(Accepted.class)));
    txnState.setLastTransactionId(null);
    return this;
}
Also used : Transfer(org.apache.qpid.server.protocol.v1_0.type.transport.Transfer) Disposition(org.apache.qpid.server.protocol.v1_0.type.transport.Disposition) Discharge(org.apache.qpid.server.protocol.v1_0.type.transaction.Discharge) Flow(org.apache.qpid.server.protocol.v1_0.type.transport.Flow)

Example 69 with Transfer

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

the class Interaction method txnDeclare.

public Interaction txnDeclare(final InteractionTransactionalState txnState) throws Exception {
    Transfer transfer = createTransactionTransfer(txnState.getHandle());
    transferPayload(transfer, new Declare());
    sendPerformativeAndChainFuture(transfer, _sessionChannel);
    consumeResponse(Disposition.class);
    Disposition declareTransactionDisposition = getLatestResponse(Disposition.class);
    assertThat(declareTransactionDisposition.getSettled(), is(equalTo(true)));
    assertThat(declareTransactionDisposition.getState(), is(instanceOf(Declared.class)));
    Binary transactionId = ((Declared) declareTransactionDisposition.getState()).getTxnId();
    assertThat(transactionId, is(notNullValue()));
    consumeResponse(Flow.class);
    txnState.setLastTransactionId(transactionId);
    return this;
}
Also used : Transfer(org.apache.qpid.server.protocol.v1_0.type.transport.Transfer) Disposition(org.apache.qpid.server.protocol.v1_0.type.transport.Disposition) Binary(org.apache.qpid.server.protocol.v1_0.type.Binary) Declare(org.apache.qpid.server.protocol.v1_0.type.transaction.Declare) Declared(org.apache.qpid.server.protocol.v1_0.type.transaction.Declared)

Example 70 with Transfer

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

the class DecodeErrorTest method illegalMessageFormatPayload.

@Test
@SpecificationTest(section = "3.2", description = "Altogether a message consists of the following sections: Zero or one header," + " Zero or one delivery-annotations, [...]")
public void illegalMessageFormatPayload() throws Exception {
    try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
        List<QpidByteBuffer> payloads = new ArrayList<>();
        final HeaderSection headerSection = new Header().createEncodingRetainingSection();
        payloads.add(headerSection.getEncodedForm());
        headerSection.dispose();
        final StringWriter stringWriter = new StringWriter("string in between annotation sections");
        QpidByteBuffer encodedString = QpidByteBuffer.allocate(stringWriter.getEncodedSize());
        stringWriter.writeToBuffer(encodedString);
        encodedString.flip();
        payloads.add(encodedString);
        final DeliveryAnnotationsSection deliveryAnnotationsSection = new DeliveryAnnotations(Collections.emptyMap()).createEncodingRetainingSection();
        payloads.add(deliveryAnnotationsSection.getEncodedForm());
        deliveryAnnotationsSection.dispose();
        final Detach detachResponse;
        try (QpidByteBuffer combinedPayload = QpidByteBuffer.concatenate(payloads)) {
            detachResponse = transport.newInteraction().negotiateProtocol().consumeResponse().open().consumeResponse(Open.class).begin().consumeResponse(Begin.class).attachRole(Role.SENDER).attachTargetAddress(BrokerAdmin.TEST_QUEUE_NAME).attach().consumeResponse(Attach.class).consumeResponse(Flow.class).transferMessageFormat(UnsignedInteger.ZERO).transferPayload(combinedPayload).transfer().consumeResponse().getLatestResponse(Detach.class);
        }
        payloads.forEach(QpidByteBuffer::dispose);
        assertThat(detachResponse.getError(), is(notNullValue()));
        assertThat(detachResponse.getError().getCondition(), is(equalTo(DECODE_ERROR)));
    }
}
Also used : DeliveryAnnotationsSection(org.apache.qpid.server.protocol.v1_0.type.messaging.DeliveryAnnotationsSection) Attach(org.apache.qpid.server.protocol.v1_0.type.transport.Attach) ArrayList(java.util.ArrayList) DeliveryAnnotations(org.apache.qpid.server.protocol.v1_0.type.messaging.DeliveryAnnotations) HeaderSection(org.apache.qpid.server.protocol.v1_0.type.messaging.HeaderSection) Open(org.apache.qpid.server.protocol.v1_0.type.transport.Open) Header(org.apache.qpid.server.protocol.v1_0.type.messaging.Header) StringWriter(org.apache.qpid.server.protocol.v1_0.codec.StringWriter) Begin(org.apache.qpid.server.protocol.v1_0.type.transport.Begin) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) Detach(org.apache.qpid.server.protocol.v1_0.type.transport.Detach) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Aggregations

Test (org.junit.Test)54 SpecificationTest (org.apache.qpid.tests.protocol.SpecificationTest)53 FrameTransport (org.apache.qpid.tests.protocol.v1_0.FrameTransport)53 Interaction (org.apache.qpid.tests.protocol.v1_0.Interaction)46 Attach (org.apache.qpid.server.protocol.v1_0.type.transport.Attach)36 UnsignedInteger (org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger)29 Disposition (org.apache.qpid.server.protocol.v1_0.type.transport.Disposition)29 Binary (org.apache.qpid.server.protocol.v1_0.type.Binary)26 Flow (org.apache.qpid.server.protocol.v1_0.type.transport.Flow)26 Transfer (org.apache.qpid.server.protocol.v1_0.type.transport.Transfer)24 Begin (org.apache.qpid.server.protocol.v1_0.type.transport.Begin)21 QpidByteBuffer (org.apache.qpid.server.bytebuffer.QpidByteBuffer)20 Open (org.apache.qpid.server.protocol.v1_0.type.transport.Open)19 InteractionTransactionalState (org.apache.qpid.tests.protocol.v1_0.InteractionTransactionalState)19 Error (org.apache.qpid.server.protocol.v1_0.type.transport.Error)18 AmqpError (org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError)14 Detach (org.apache.qpid.server.protocol.v1_0.type.transport.Detach)13 DeliveryState (org.apache.qpid.server.protocol.v1_0.type.DeliveryState)11 Accepted (org.apache.qpid.server.protocol.v1_0.type.messaging.Accepted)11 TransactionError (org.apache.qpid.server.protocol.v1_0.type.transaction.TransactionError)11