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;
}
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;
}
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;
}
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;
}
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)));
}
}
Aggregations