use of com.unboundid.ldap.sdk.controls.TransactionSpecificationRequestControl in project ldapsdk by pingidentity.
the class InMemoryRequestHandler method processTransactionRequest.
/**
* Determines whether the provided set of controls includes a transaction
* specification request control. If so, then it will verify that it
* references a valid transaction for the client. If the request is part of a
* valid transaction, then the transaction specification request control will
* be removed and the request will be stashed in the client connection state
* so that it can be retrieved and processed when the transaction is
* committed.
*
* @param messageID The message ID for the request to be processed.
* @param request The protocol op for the request to be processed.
* @param controls The set of controls for the request to be processed.
*
* @return The transaction ID for the associated transaction, or {@code null}
* if the request is not part of any transaction.
*
* @throws LDAPException If the transaction specification request control is
* present but does not refer to a valid transaction
* for the associated client connection.
*/
@SuppressWarnings("unchecked")
@Nullable()
private ASN1OctetString processTransactionRequest(final int messageID, @NotNull final ProtocolOp request, @NotNull final Map<String, Control> controls) throws LDAPException {
final TransactionSpecificationRequestControl txnControl = (TransactionSpecificationRequestControl) controls.remove(TransactionSpecificationRequestControl.TRANSACTION_SPECIFICATION_REQUEST_OID);
if (txnControl == null) {
return null;
}
// See if the client has an active transaction. If not, then fail.
final ASN1OctetString txnID = txnControl.getTransactionID();
final ObjectPair<ASN1OctetString, List<LDAPMessage>> txnInfo = (ObjectPair<ASN1OctetString, List<LDAPMessage>>) connectionState.get(TransactionExtendedOperationHandler.STATE_VARIABLE_TXN_INFO);
if (txnInfo == null) {
throw new LDAPException(ResultCode.UNAVAILABLE_CRITICAL_EXTENSION, ERR_MEM_HANDLER_TXN_CONTROL_WITHOUT_TXN.get(txnID.stringValue()));
}
// Make sure that the active transaction has a transaction ID that matches
// the transaction ID from the control. If not, then abort the existing
// transaction and fail.
final ASN1OctetString existingTxnID = txnInfo.getFirst();
if (!txnID.stringValue().equals(existingTxnID.stringValue())) {
connectionState.remove(TransactionExtendedOperationHandler.STATE_VARIABLE_TXN_INFO);
connection.sendUnsolicitedNotification(new AbortedTransactionExtendedResult(existingTxnID, ResultCode.CONSTRAINT_VIOLATION, ERR_MEM_HANDLER_TXN_ABORTED_BY_CONTROL_TXN_ID_MISMATCH.get(existingTxnID.stringValue(), txnID.stringValue()), null, null, null));
throw new LDAPException(ResultCode.UNAVAILABLE_CRITICAL_EXTENSION, ERR_MEM_HANDLER_TXN_CONTROL_ID_MISMATCH.get(txnID.stringValue(), existingTxnID.stringValue()));
}
// Stash the request in the transaction state information so that it will
// be processed when the transaction is committed.
txnInfo.getSecond().add(new LDAPMessage(messageID, request, new ArrayList<>(controls.values())));
return txnID;
}
Aggregations