use of org.apache.axis2.engine.AxisConfiguration in project wso2-synapse by wso2.
the class ThrottleHandler method loadThrottle.
/**
* Loads a throttle metadata for a particular throttle type
*
* @param messageContext - The messageContext
* @param throttleType - The type of throttle
* @return IPBaseThrottleConfiguration - The IPBaseThrottleConfiguration - load from AxisConfiguration
* @throws ThrottleException Throws if the throttle type is unsupported
*/
public Throttle loadThrottle(MessageContext messageContext, int throttleType) throws ThrottleException {
Throttle throttle = null;
ConfigurationContext configContext = messageContext.getConfigurationContext();
// the Parameter which hold throttle ipbase object
// to get throttles map from the configuration context
Map throttles = (Map) configContext.getPropertyNonReplicable(ThrottleConstants.THROTTLES_MAP);
if (throttles == null) {
if (debugOn) {
log.debug("Couldn't find throttles object map .. thottlling will not be occurred ");
}
return null;
}
switch(throttleType) {
case ThrottleConstants.GLOBAL_THROTTLE:
{
throttle = (Throttle) throttles.get(ThrottleConstants.GLOBAL_THROTTLE_KEY);
break;
}
case ThrottleConstants.OPERATION_BASED_THROTTLE:
{
AxisOperation axisOperation = messageContext.getAxisOperation();
if (axisOperation != null) {
QName opName = axisOperation.getName();
if (opName != null) {
AxisService service = (AxisService) axisOperation.getParent();
if (service != null) {
String currentServiceName = service.getName();
if (currentServiceName != null) {
throttle = (Throttle) throttles.get(currentServiceName + opName.getLocalPart());
}
}
}
} else {
if (debugOn) {
log.debug("Couldn't find axis operation ");
}
return null;
}
break;
}
case ThrottleConstants.SERVICE_BASED_THROTTLE:
{
AxisService axisService = messageContext.getAxisService();
if (axisService != null) {
throttle = (Throttle) throttles.get(axisService.getName());
} else {
if (debugOn) {
log.debug("Couldn't find axis service ");
}
return null;
}
break;
}
default:
{
throw new ThrottleException("Unsupported Throttle type");
}
}
return throttle;
}
use of org.apache.axis2.engine.AxisConfiguration in project wso2-synapse by wso2.
the class ThrottleEnguageUtils method enguage.
public static void enguage(AxisDescription axisDescription, ConfigurationContext configctx, Throttle defaultThrottle) throws AxisFault {
String currentServiceName;
if (axisDescription instanceof AxisService) {
Throttle throttle = null;
AxisService currentService = ((AxisService) axisDescription);
PolicySubject policySubject = currentService.getPolicySubject();
if (policySubject != null) {
try {
List policies = new ArrayList(policySubject.getAttachedPolicyComponents());
Policy currentPolicy = PolicyUtil.getMergedPolicy(policies, currentService);
if (currentPolicy != null) {
throttle = ThrottleFactory.createServiceThrottle(currentPolicy);
if (throttle == null) {
// this is for the scenario when throttle policy is empty rather than
// null (eg: removing the throttle policy via policy editor)
throttle = defaultThrottle;
}
// todo - done by isuru, recheck
} else {
AxisConfiguration axisConfig = configctx.getAxisConfiguration();
AxisModule throttleModule = axisConfig.getModule(ThrottleConstants.THROTTLE_MODULE_NAME);
policySubject = throttleModule.getPolicySubject();
if (policySubject != null) {
currentPolicy = ThrottleEnguageUtils.getThrottlePolicy(policySubject.getAttachedPolicyComponents());
if (currentPolicy != null) {
throttle = ThrottleFactory.createModuleThrottle(currentPolicy);
}
}
// todo - done by isuru
}
} catch (ThrottleException e) {
log.error("Error was occurred when engaging throttle module for" + " the service :" + currentService.getName() + e.getMessage());
log.info("Throttling will occur using default module policy");
throttle = defaultThrottle;
}
if (throttle != null) {
Map throttles = (Map) configctx.getPropertyNonReplicable(ThrottleConstants.THROTTLES_MAP);
if (throttles == null) {
throttles = new HashMap();
configctx.setNonReplicableProperty(ThrottleConstants.THROTTLES_MAP, throttles);
}
String serviceName = currentService.getName();
throttle.setId(serviceName);
throttles.put(serviceName, throttle);
ConcurrentAccessController cac = throttle.getConcurrentAccessController();
if (cac != null) {
String cacKey = ThrottleConstants.THROTTLE_PROPERTY_PREFIX + serviceName + ThrottleConstants.CAC_SUFFIX;
configctx.setProperty(cacKey, cac);
}
}
}
} else if (axisDescription instanceof AxisOperation) {
Throttle throttle = null;
AxisOperation currentOperation = ((AxisOperation) axisDescription);
AxisService axisService = (AxisService) currentOperation.getParent();
if (axisService != null) {
currentServiceName = axisService.getName();
PolicySubject policySubject = currentOperation.getPolicySubject();
if (policySubject != null) {
try {
List policies = new ArrayList(policySubject.getAttachedPolicyComponents());
Policy currentPolicy = PolicyUtil.getMergedPolicy(policies, currentOperation);
if (currentPolicy != null) {
throttle = ThrottleFactory.createOperationThrottle(currentPolicy);
}
} catch (ThrottleException e) {
log.error("Error was occurred when engaging throttle module " + "for operation : " + currentOperation.getName() + " in the service :" + currentServiceName + e.getMessage());
log.info("Throttling will occur using default module policy");
}
// if current throttle is null, use the default throttle
if (throttle == null) {
throttle = defaultThrottle;
}
Map throttles = (Map) configctx.getPropertyNonReplicable(ThrottleConstants.THROTTLES_MAP);
if (throttles == null) {
throttles = new HashMap();
configctx.setNonReplicableProperty(ThrottleConstants.THROTTLES_MAP, throttles);
}
QName opQName = currentOperation.getName();
if (opQName != null) {
String opName = opQName.getLocalPart();
String key = currentServiceName + opName;
throttle.setId(key);
throttles.put(key, throttle);
ConcurrentAccessController cac = throttle.getConcurrentAccessController();
if (cac != null) {
String cacKey = ThrottleConstants.THROTTLE_PROPERTY_PREFIX + key + ThrottleConstants.CAC_SUFFIX;
configctx.setProperty(cacKey, cac);
}
}
}
}
}
}
use of org.apache.axis2.engine.AxisConfiguration in project wso2-synapse by wso2.
the class SynapseEventSource method buildService.
public void buildService(AxisConfiguration axisCfg) throws AxisFault {
AxisService eventSourceService = new AxisService();
eventSourceService.setName(this.name);
// Add wse operations
addOperations(eventSourceService);
axisCfg.addService(eventSourceService);
// Set the service parameters
eventSourceService.addParameter(EventingConstants.SUBSCRIPTION_MANAGER, subscriptionManager);
eventSourceService.addParameter(SynapseEventingConstants.SERVICE_TYPE, SynapseEventingConstants.EVENTING_ST);
}
use of org.apache.axis2.engine.AxisConfiguration in project wso2-synapse by wso2.
the class ConnectorDeployer method updateStatus.
/**
* Performing the action of enabling/disabling the given meidation library.
*
* @param libName library name
* @param packageName package name
* @param status current status
* @param axisConfig AxisConfiguration of the current tenant
* @throws AxisFault asxis fault
*/
private static boolean updateStatus(String libQName, String libName, String packageName, String status, AxisConfiguration axisConfig) throws AxisFault {
try {
SynapseConfiguration synapseConfiguration = getSynapseConfiguration(axisConfig);
SynapseImport synapseImport = synapseConfiguration.getSynapseImports().get(libQName);
if (synapseImport == null && libName != null && packageName != null) {
addImport(libName, packageName, axisConfig);
synapseImport = synapseConfiguration.getSynapseImports().get(libQName);
}
Library synLib = synapseConfiguration.getSynapseLibraries().get(libQName);
if (libQName != null && synLib != null) {
if ("enabled".equals(status)) {
synapseImport.setStatus(true);
synLib.setLibStatus(true);
synLib.loadLibrary();
deployingLocalEntries(synLib, synapseConfiguration, axisConfig);
} else {
synapseImport.setStatus(false);
synLib.setLibStatus(false);
synLib.unLoadLibrary();
undeployingLocalEntries(synLib, synapseConfiguration, axisConfig);
}
}
} catch (Exception e) {
log.error("Unable to update status for : " + libQName, e);
}
return true;
}
use of org.apache.axis2.engine.AxisConfiguration in project wso2-synapse by wso2.
the class ConnectorDeployer method getSynapseLibraryDeployer.
/**
* Get the deployer for the Synapse Library.
*
* @param axisConfig AxisConfiguration instance
* @return Deployer instance
*/
private static Deployer getSynapseLibraryDeployer(AxisConfiguration axisConfig) {
try {
String synapseLibraryPath = axisConfig.getRepository().getPath() + SYNAPSE_LIBS;
DeploymentEngine deploymentEngine = (DeploymentEngine) axisConfig.getConfigurator();
deploymentEngine.addDeployer(new LibraryArtifactDeployer(), synapseLibraryPath, SYNAPSE_LIBRARY_EXTENSION);
return deploymentEngine.getDeployer(synapseLibraryPath, SYNAPSE_LIBRARY_EXTENSION);
} catch (Exception e) {
log.error("Error occured while getting the deployer");
return null;
}
}
Aggregations