use of io.gravitee.policy.api.PolicyConfiguration in project gravitee-gateway by gravitee-io.
the class DefaultPolicyManager method create.
@Override
public io.gravitee.gateway.policy.Policy create(StreamType streamType, String policy, String configuration) {
PolicyMetadata policyMetadata = get(policy);
if ((streamType == StreamType.ON_REQUEST && (policyMetadata.method(OnRequest.class) != null || policyMetadata.method(OnRequestContent.class) != null)) || (streamType == StreamType.ON_RESPONSE && (policyMetadata.method(OnResponse.class) != null || policyMetadata.method(OnResponseContent.class) != null))) {
PolicyConfiguration policyConfiguration = policyConfigurationFactory.create(policyMetadata.configuration(), configuration);
// TODO: this should be done only if policy is injectable
Map<Class<?>, Object> injectables = new HashMap<>(2);
injectables.put(policyMetadata.configuration(), policyConfiguration);
if (policyMetadata.context() != null) {
injectables.put(policyMetadata.context().getClass(), policyMetadata.context());
}
Object policyInst = policyFactory.create(policyMetadata, injectables);
logger.debug("Policy {} has been added to the policy chain", policyMetadata.id());
return PolicyImpl.target(policyInst).definition(policyMetadata).build();
}
return null;
}
use of io.gravitee.policy.api.PolicyConfiguration in project gravitee-gateway by gravitee-io.
the class CachedPolicyConfigurationFactory method create.
@Override
public <T extends PolicyConfiguration> T create(Class<T> policyConfigurationClass, String configuration) {
if (policyConfigurationClass == null) {
return null;
}
String hash = hash(policyConfigurationClass, configuration);
PolicyConfiguration config = cachedPolicyConfiguration.get(hash);
if (config == null) {
config = super.create(policyConfigurationClass, configuration);
if (config != null) {
cachedPolicyConfiguration.put(hash, config);
}
}
return (T) config;
}
use of io.gravitee.policy.api.PolicyConfiguration in project gravitee-gateway by gravitee-io.
the class CachedPolicyConfigurationFactoryTest method createNullPolicyClassFromCache.
@Test
public void createNullPolicyClassFromCache() {
PolicyConfiguration policyConfiguration1 = policyConfigurationFactory.create(null, null);
Assert.assertNull(policyConfiguration1);
}
use of io.gravitee.policy.api.PolicyConfiguration in project gravitee-gateway by gravitee-io.
the class PolicyConfigurationFactoryTest method createPolicyWithConfigurationAndWithoutConfigurationData.
@Test
public void createPolicyWithConfigurationAndWithoutConfigurationData() {
PolicyConfiguration policyConfiguration = policyConfigurationFactory.create(DummyPolicyConfiguration.class, null);
Assert.assertNull(policyConfiguration);
}
use of io.gravitee.policy.api.PolicyConfiguration in project gravitee-gateway by gravitee-io.
the class PolicyConfigurationFactoryTest method createPolicyWithConfigurationAndEmptyConfigurationData.
@Test
public void createPolicyWithConfigurationAndEmptyConfigurationData() {
PolicyConfiguration policyConfiguration = policyConfigurationFactory.create(DummyPolicyConfiguration.class, "");
Assert.assertNull(policyConfiguration);
}
Aggregations