// Transform the operation if needed
if(proxyController instanceof TransformingProxyController) {
final TransformingProxyController transformingProxyController = (TransformingProxyController) proxyController;
final OperationTransformer.TransformedOperation result = transformingProxyController.transformOperation(context, operation);
final ModelNode transformedOperation = result.getTransformedOperation();
final OperationResultTransformer resultTransformer = result.getResultTransformer();
if(transformedOperation != null) {
final ProxyController.ProxyOperationControl transformingProxyControl = new ProxyController.ProxyOperationControl() {
@Override
public void operationFailed(final ModelNode response) {
final ModelNode transformed;
// Check if we can provide a better error message
if(result.rejectOperation(response)) {
final ModelNode newResponse = new ModelNode();
newResponse.get(OUTCOME).set(FAILED);
newResponse.get(FAILURE_DESCRIPTION).set(result.getFailureDescription());
transformed = newResponse;
} else {
transformed = response;
}
final ModelNode result = resultTransformer.transformResult(transformed);
proxyControl.operationFailed(result);
}
@Override
public void operationCompleted(ModelNode response) {
final ModelNode result = resultTransformer.transformResult(response);
proxyControl.operationCompleted(result);
}
@Override
public void operationPrepared(ModelController.OperationTransaction transaction, ModelNode response) {
final ModelNode transformed;
// Check if we have to reject the operation
if(result.rejectOperation(response)) {
final ModelNode newResponse = new ModelNode();
newResponse.get(OUTCOME).set(FAILED);
newResponse.get(FAILURE_DESCRIPTION).set(result.getFailureDescription());
transformed = newResponse;
} else {
transformed = response;
}
proxyControl.operationPrepared(transaction, transformed);
}
};
proxyController.execute(transformedOperation, messageHandler, transformingProxyControl, new DelegatingOperationAttachments(context));
} else {
// discard the operation
final ModelNode transformedResult = resultTransformer.transformResult(new ModelNode());
if(transformedResult != null) {
context.getResult().set(transformedResult);
}
context.completeStep(OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER);
return;