public Optional<PhysicalInterceptor> generate(LogicalOperation source, LogicalOperation target) { return source.getDefinition().isOneWay() ? Optional.of(new PhysicalNonBlockingInterceptor()) : Optional.empty(); } }
public LogicalOperation resolve(LogicalOperation source, List<LogicalOperation> targets) { Operation sourceDefinition = source.getDefinition(); for (LogicalOperation target : targets) { Operation targetDefinition = target.getDefinition(); if (sourceDefinition.getName().equals(targetDefinition.getName())) { List<DataType> sourceInputTypes = sourceDefinition.getInputTypes(); DataType sourceOutputType = sourceDefinition.getOutputType(); DataType targetOutputType = targetDefinition.getOutputType(); if (sourceOutputType.equals(targetOutputType) && sourceInputTypes.equals(targetDefinition.getInputTypes())) { return target; } } } LogicalInvocable parent = source.getParent(); if (parent != null) { String sourceComponent = parent.getParent().getUri().toString(); throw new Fabric3Exception("Target operation not found for " + sourceDefinition.getName() + " on source component " + sourceComponent); } else { throw new Fabric3Exception("Target operation not found for " + sourceDefinition.getName()); } }
private boolean useByReference(LogicalOperation operation, boolean remote) { if (!passByValueEnabled || remote) { // Pass-by-value is disabled or the invocation chain is remote. Pass-by-reference semantics should be used for remote invocation chains // since the binding will enforce pass-by-value implicitly through serialization return true; } LogicalAttachPoint logicalAttachPoint = operation.getParent(); LogicalComponent<?> component = logicalAttachPoint.getParent(); return operation.getIntents().contains(ALLOWS_BY_REFERENCE) || logicalAttachPoint.getIntents().contains(ALLOWS_BY_REFERENCE) || component.getIntents().contains(ALLOWS_BY_REFERENCE) || component.getDefinition().getImplementation().getIntents().contains( ALLOWS_BY_REFERENCE) || component.getDefinition().getImplementation().getComponentType().getIntents().contains(ALLOWS_BY_REFERENCE); } }
public PolicyResult resolvePolicies(LogicalConsumer consumer) throws PolicyResolutionException { LogicalComponent<?> component = consumer.getParent(); if (noPolicy(component)) { return EMPTY_RESULT; } // synthesize an operation and binding PolicyResultImpl policyResult = new PolicyResultImpl(); LogicalOperation operation = new LogicalOperation(DEFINITION, consumer); IntentPair targetOperationIntentPair = interactionResolver.resolveIntents(operation, LocalBindingDefinition.INSTANCE.getType()); policyResult.addTargetProvidedIntents(operation, targetOperationIntentPair.getProvidedIntents()); IntentPair sourceImplementationIntentPair = implementationResolver.resolveIntents(component, operation); policyResult.addSourceProvidedIntents(operation, sourceImplementationIntentPair.getProvidedIntents()); Set<PolicySet> policies = interactionResolver.resolvePolicySets(operation, consumer, LocalBindingDefinition.INSTANCE.getType()); policyResult.addTargetPolicySets(operation, CollectionUtils.filter(policies, PROVIDED)); policyResult.addInterceptedPolicySets(operation, CollectionUtils.filter(policies, INTERCEPTION)); // resolve policies using the target (as opposed to source) operation so target implementation policies are included policies = implementationResolver.resolvePolicySets(component, operation); // add policy metadata to the result PolicyMetadata metadata = policyResult.getMetadata(operation); metadata.addAll(operation.getDefinition().getMetadata()); // add metadata from implementation metadata.addAll(operation.getParent().getParent().getDefinition().getImplementation().getMetadata()); // important: use reference side operation as the key policyResult.addTargetPolicySets(operation, CollectionUtils.filter(policies, PROVIDED)); policyResult.addInterceptedPolicySets(operation, CollectionUtils.filter(policies, INTERCEPTION)); overrideDirectIfExternalAttachedPolicies(policyResult); return policyResult; }
public AuthorizationInterceptorDefinition generate(Element policy, PolicyMetadata metadata, LogicalOperation operation) throws GenerationException { String[] roles = metadata.get(AUTHORIZATION, String[].class); if (roles == null) { LogicalComponent component = operation.getParent().getParent(); throw new GenerationException("No roles specified for authorization intent on component: " + component.getUri()); } return new AuthorizationInterceptorDefinition(Arrays.asList(roles)); }
if (!operation.getPolicySets().contains(policySet)) { return; operation.removePolicySet(policySet); LogicalAttachPoint attachPoint = operation.getParent(); if (attachPoint instanceof LogicalReference) { processDetachReference((LogicalReference) attachPoint, policySet, true);
if (operation.getPolicySets().contains(policySet)) { return; operation.addPolicySet(policySet); LogicalAttachPoint attachPoint = operation.getParent(); if (attachPoint instanceof LogicalReference) { processReference((LogicalReference) attachPoint, policySet, incremental);
private Set<Intent> aggregateOperationIntents(LogicalOperation operation) throws PolicyResolutionException { Set<QName> intentNames = new LinkedHashSet<>(); intentNames.addAll(operation.getIntents()); return expandAndFilterIntents(intentNames, operation); }
/** * Instantiates logical operations from a service contract * * @param contract the contract */ protected final void createOperations(ServiceContract contract) { operations = new ArrayList<>(); callbackOperations = new ArrayList<>(); if (contract != null) { // null is a convenience allowed for testing so the logical model does not need to be fully created operations.addAll(contract.getOperations().stream().map(operation -> new LogicalOperation(operation, this)).collect(Collectors.toList())); ServiceContract callbackContract = contract.getCallbackContract(); if (callbackContract != null) { for (Operation operation : callbackContract.getOperations()) { callbackOperations.add(new LogicalOperation(operation, this)); } } } }
PhysicalInterceptorDefinition pid = generator.generate(policy.getExpression(), metadata, operation); if (pid != null) { URI contributionClassLoaderId = operation.getParent().getParent().getDefinition().getContributionUri(); pid.setWireClassLoaderId(contributionClassLoaderId); pid.setPolicyClassLoaderId(policy.getContributionUri());
private Set<Intent> getRequestedIntents(LogicalComponent<?> logicalComponent, LogicalOperation operation) throws PolicyResolutionException { // Aggregate all the intents from the ancestors Set<QName> intentNames = new LinkedHashSet<>(); intentNames.addAll(operation.getIntents()); ComponentDefinition<? extends Implementation<?>> definition = logicalComponent.getDefinition(); Implementation<?> implementation = definition.getImplementation(); ComponentType componentType = implementation.getComponentType(); intentNames.addAll(implementation.getIntents()); intentNames.addAll(componentType.getIntents()); intentNames.addAll(aggregateIntents(logicalComponent)); // Expand all the profile intents Set<Intent> requiredIntents = resolveIntents(intentNames); // Remove intents not applicable to the artifact filterInvalidIntents(Intent.IMPLEMENTATION, requiredIntents); filterMutuallyExclusiveIntents(requiredIntents); return requiredIntents; }
private void setPolicyConfigs(Axis2PolicyAware policyAware, Policy policy, List<LogicalOperation> operations) throws Axis2GenerationException { for (LogicalOperation operation : operations) { List<PolicySet> policySets = policy.getProvidedPolicySets(operation); if (policySets == null) { continue; } for (PolicySet policySet : policy.getProvidedPolicySets(operation)) { Element policyDefinition = policySet.getExtension(); QName qname = new QName(policyDefinition.getNamespaceURI(), policyDefinition.getNodeName()); if (POLICY_ELEMENT.equals(qname)) { throw new Axis2GenerationException("Unknow policy element " + qname); } String module = policyDefinition.getAttribute("module"); String message = policyDefinition.getAttribute("message"); Element opaquePolicy = null; NodeList nodeList = policyDefinition.getChildNodes(); for (int i = 0; i < nodeList.getLength(); i++) { if (nodeList.item(i) instanceof Element) { opaquePolicy = (Element) nodeList.item(i); break; } } AxisPolicy axisPolicy = new AxisPolicy(message, module, opaquePolicy); policyAware.addPolicy(operation.getDefinition().getName(), axisPolicy); } } }
public LogicalOperation resolve(LogicalOperation source, List<LogicalOperation> targets) { Operation sourceDefinition = source.getDefinition(); for (LogicalOperation target : targets) { Operation targetDefinition = target.getDefinition(); if (sourceDefinition.getName().equals(targetDefinition.getName())) { List<DataType> sourceInputTypes = sourceDefinition.getInputTypes(); DataType sourceOutputType = sourceDefinition.getOutputType(); DataType targetOutputType = targetDefinition.getOutputType(); if (sourceOutputType.equals(targetOutputType) && sourceInputTypes.equals(targetDefinition.getInputTypes())) { return target; } } } LogicalInvocable parent = source.getParent(); if (parent != null) { String sourceComponent = parent.getParent().getUri().toString(); throw new Fabric3Exception("Target operation not found for " + sourceDefinition.getName() + " on source component " + sourceComponent); } else { throw new Fabric3Exception("Target operation not found for " + sourceDefinition.getName()); } }
List<LogicalOperation> operations = parent.getOperations(); for (LogicalOperation operation : operations) { if (!operation.getIntents().contains(ONEWAY)) { throw new PolicyResolutionException("Cannot specify transacted one-way for a request-response operation: " + parent.getUri()); if (!operation.getIntents().contains(ONEWAY)) { throw new PolicyResolutionException( "Cannot specify transacted one-way for a request-response operation: " + operation.getParent().getUri()); List<LogicalOperation> operations = parent.getOperations(); for (LogicalOperation operation : operations) { if (!operation.getIntents().contains(ONEWAY)) { throw new PolicyResolutionException("Cannot specify immediate one-way for a request-response operation: " + parent.getUri()); if (!operation.getIntents().contains(ONEWAY)) { throw new PolicyResolutionException("Cannot specify immediate one-way for a request-response operation: " + operation.getParent().getUri());
if (((LogicalOperation) entry).getParent().getParent() == target) { return true;
if (containsTransactionIntent(operation.getIntents())) { return true; if (containsTransactionIntent(operation.getIntents())) { return true;
private Class<?> getType(LogicalProducer producer) { Operation operation = producer.getStreamOperation().getDefinition(); List<DataType> params = operation.getInputTypes(); if (params.size() != 1) { String interfaceName = producer.getServiceContract().getQualifiedInterfaceName(); throw new Fabric3Exception("A channel interface must have one parameter: operation " + operation.getName() + " on " + interfaceName); } return params.get(0).getType(); }
public LogicalOperation resolve(LogicalOperation source, List<LogicalOperation> targets) throws OperationNotFoundException { Operation sourceDefinition = source.getDefinition(); for (LogicalOperation target : targets) { Operation targetDefinition = target.getDefinition(); LogicalAttachPoint parent = source.getParent(); if (parent != null) { String sourceComponent = parent.getParent().getUri().toString();
private Class<?> getType(LogicalProducer producer) { Operation operation = producer.getStreamOperation().getDefinition(); List<DataType> params = operation.getInputTypes(); if (params.size() != 1) { String interfaceName = producer.getServiceContract().getQualifiedInterfaceName(); throw new Fabric3Exception("A channel interface must have one parameter: operation " + operation.getName() + " on " + interfaceName); } return params.get(0).getType(); }
metadata.addAll(targetOperation.getDefinition().getMetadata()); ComponentDefinition<? extends Implementation<?>> parentDefinition = targetOperation.getParent().getParent().getDefinition(); Implementation<?> parentImplementation = parentDefinition.getImplementation(); metadata.addAll(parentImplementation.getMetadata());