Search in sources :

Example 31 with AxisConfiguration

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;
}
Also used : ConfigurationContext(org.apache.axis2.context.ConfigurationContext) AxisOperation(org.apache.axis2.description.AxisOperation) QName(javax.xml.namespace.QName) ThrottleException(org.apache.synapse.commons.throttle.core.ThrottleException) AxisService(org.apache.axis2.description.AxisService) Map(java.util.Map) Throttle(org.apache.synapse.commons.throttle.core.Throttle)

Example 32 with AxisConfiguration

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);
                    }
                }
            }
        }
    }
}
Also used : Policy(org.apache.neethi.Policy) AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) Throttle(org.apache.synapse.commons.throttle.core.Throttle) ThrottleException(org.apache.synapse.commons.throttle.core.ThrottleException) ArrayList(java.util.ArrayList) List(java.util.List) ConcurrentAccessController(org.apache.synapse.commons.throttle.core.ConcurrentAccessController) HashMap(java.util.HashMap) Map(java.util.Map)

Example 33 with AxisConfiguration

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);
}
Also used : AxisService(org.apache.axis2.description.AxisService)

Example 34 with AxisConfiguration

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;
}
Also used : SynapseImport(org.apache.synapse.libraries.imports.SynapseImport) Library(org.apache.synapse.libraries.model.Library) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration) XMLStreamException(javax.xml.stream.XMLStreamException) DeploymentException(org.apache.axis2.deployment.DeploymentException) SynapseException(org.apache.synapse.SynapseException) IOException(java.io.IOException) OMException(org.apache.axiom.om.OMException)

Example 35 with AxisConfiguration

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;
    }
}
Also used : LibraryArtifactDeployer(org.apache.synapse.deployers.LibraryArtifactDeployer) DeploymentEngine(org.apache.axis2.deployment.DeploymentEngine) XMLStreamException(javax.xml.stream.XMLStreamException) DeploymentException(org.apache.axis2.deployment.DeploymentException) SynapseException(org.apache.synapse.SynapseException) IOException(java.io.IOException) OMException(org.apache.axiom.om.OMException)

Aggregations

AxisConfiguration (org.apache.axis2.engine.AxisConfiguration)211 ConfigurationContext (org.apache.axis2.context.ConfigurationContext)122 SynapseConfiguration (org.apache.synapse.config.SynapseConfiguration)95 Test (org.junit.Test)68 Axis2SynapseEnvironment (org.apache.synapse.core.axis2.Axis2SynapseEnvironment)65 Parameter (org.apache.axis2.description.Parameter)62 SynapseEnvironment (org.apache.synapse.core.SynapseEnvironment)62 OMElement (org.apache.axiom.om.OMElement)40 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)35 AxisService (org.apache.axis2.description.AxisService)33 DeploymentEngine (org.apache.axis2.deployment.DeploymentEngine)32 MessageContext (org.apache.synapse.MessageContext)32 AxisFault (org.apache.axis2.AxisFault)31 Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)28 TransportOutDescription (org.apache.axis2.description.TransportOutDescription)21 DeploymentException (org.apache.axis2.deployment.DeploymentException)20 SynapseException (org.apache.synapse.SynapseException)20 IOException (java.io.IOException)19 XMLStreamException (javax.xml.stream.XMLStreamException)16 File (java.io.File)15