Search in sources :

Example 16 with AxisConfiguration

use of org.apache.axis2.engine.AxisConfiguration in project carbon-apimgt by wso2.

the class APIAuthenticationHandlerTestCase method testDestroy.

/*
    * This method will test for destroy()
    * */
@Test
public void testDestroy() {
    APIAuthenticationHandler apiAuthenticationHandler = new APIAuthenticationHandler();
    apiAuthenticationHandler.destroy();
    SynapseEnvironment synapseEnvironment = Mockito.mock(SynapseEnvironment.class);
    SynapseConfiguration synapseConfiguration = Mockito.mock(SynapseConfiguration.class);
    AxisConfiguration axisConfiguration = Mockito.mock(AxisConfiguration.class);
    Mockito.when(synapseEnvironment.getSynapseConfiguration()).thenReturn(synapseConfiguration);
    Mockito.when(synapseConfiguration.getAxisConfiguration()).thenReturn(axisConfiguration);
    PowerMockito.mockStatic(Util.class);
    PowerMockito.when(Util.getTenantDomain()).thenReturn("carbon.super");
    apiAuthenticationHandler.init(synapseEnvironment);
    apiAuthenticationHandler.destroy();
}
Also used : AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) SynapseEnvironment(org.apache.synapse.core.SynapseEnvironment) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 17 with AxisConfiguration

use of org.apache.axis2.engine.AxisConfiguration in project carbon-apimgt by wso2.

the class APIUtil method getManagementTransportPort.

public static int getManagementTransportPort(String mgtTransport) {
    if (StringUtils.isEmpty(mgtTransport)) {
        mgtTransport = APIConstants.HTTPS_PROTOCOL;
    }
    AxisConfiguration axisConfiguration = ServiceReferenceHolder.getContextService().getServerConfigContext().getAxisConfiguration();
    int mgtTransportPort = CarbonUtils.getTransportProxyPort(axisConfiguration, mgtTransport);
    if (mgtTransportPort <= 0) {
        mgtTransportPort = CarbonUtils.getTransportPort(axisConfiguration, mgtTransport);
    }
    return mgtTransportPort;
}
Also used : AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) Endpoint(org.wso2.carbon.governance.api.endpoints.dataobjects.Endpoint)

Example 18 with AxisConfiguration

use of org.apache.axis2.engine.AxisConfiguration in project carbon-apimgt by wso2.

the class APIUtil method isProxyPortEnabled.

/*
     * Checks whether the proxy port is configured.
     * @param transport  The transport
     * @return boolean proxyport is enabled
     * */
public static boolean isProxyPortEnabled(String mgtTransport) {
    AxisConfiguration axisConfiguration = ServiceReferenceHolder.getContextService().getServerConfigContext().getAxisConfiguration();
    int mgtTransportProxyPort = CarbonUtils.getTransportProxyPort(axisConfiguration, mgtTransport);
    return mgtTransportProxyPort > 0;
}
Also used : AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) Endpoint(org.wso2.carbon.governance.api.endpoints.dataobjects.Endpoint)

Example 19 with AxisConfiguration

use of org.apache.axis2.engine.AxisConfiguration in project carbon-apimgt by wso2.

the class TenantLoadMessageSenderTest method testGetClusteringAgent.

@Test
public void testGetClusteringAgent() {
    PowerMockito.mockStatic(ServiceReferenceHolder.class);
    ConfigurationContextService configurationContextService = PowerMockito.mock(ConfigurationContextService.class);
    PowerMockito.when(ServiceReferenceHolder.getContextService()).thenReturn(configurationContextService);
    ConfigurationContext serverConfigContext = PowerMockito.mock(ConfigurationContext.class);
    PowerMockito.when(ServiceReferenceHolder.getContextService().getServerConfigContext()).thenReturn(serverConfigContext);
    AxisConfiguration axisConfiguration = PowerMockito.mock(AxisConfiguration.class);
    PowerMockito.when(ServiceReferenceHolder.getContextService().getServerConfigContext().getAxisConfiguration()).thenReturn(axisConfiguration);
    ClusteringAgent clusteringAgent = PowerMockito.mock(ClusteringAgent.class);
    PowerMockito.when(ServiceReferenceHolder.getContextService().getServerConfigContext().getAxisConfiguration().getClusteringAgent()).thenReturn(clusteringAgent);
    tenantLoadMessageSender.getClusteringAgent();
}
Also used : ConfigurationContext(org.apache.axis2.context.ConfigurationContext) AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) ClusteringAgent(org.apache.axis2.clustering.ClusteringAgent) ConfigurationContextService(org.wso2.carbon.utils.ConfigurationContextService) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 20 with AxisConfiguration

use of org.apache.axis2.engine.AxisConfiguration in project carbon-apimgt by wso2.

the class TenantServiceCreator method createdConfigurationContext.

public void createdConfigurationContext(ConfigurationContext configurationContext) {
    String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
    log.info("Initializing APIM TenantServiceCreator for the tenant domain : " + tenantDomain);
    try {
        // first check which configuration should be active
        org.wso2.carbon.registry.core.Registry registry = (org.wso2.carbon.registry.core.Registry) PrivilegedCarbonContext.getThreadLocalCarbonContext().getRegistry(RegistryType.SYSTEM_CONFIGURATION);
        AxisConfiguration axisConfig = configurationContext.getAxisConfiguration();
        // initialize the lock
        Lock lock = new ReentrantLock();
        axisConfig.addParameter("synapse.config.lock", lock);
        // creates the synapse configuration directory hierarchy if not exists
        // useful at the initial tenant creation
        File tenantAxis2Repo = new File(configurationContext.getAxisConfiguration().getRepository().getFile());
        File synapseConfigsDir = new File(tenantAxis2Repo, "synapse-configs");
        if (!synapseConfigsDir.exists()) {
            if (!synapseConfigsDir.mkdir()) {
                log.fatal("Couldn't create the synapse-config root on the file system " + "for the tenant domain : " + tenantDomain);
                return;
            }
        }
        String synapseConfigsDirLocation = synapseConfigsDir.getAbsolutePath();
        // set the required configuration parameters to initialize the ESB
        axisConfig.addParameter(SynapseConstants.Axis2Param.SYNAPSE_CONFIG_LOCATION, synapseConfigsDirLocation);
        // init the multiple configuration tracker
        ConfigurationManager manger = new ConfigurationManager((UserRegistry) registry, configurationContext);
        manger.init();
        File synapseConfigDir = new File(synapseConfigsDir, manger.getTracker().getCurrentConfigurationName());
        StringBuilder filepath = new StringBuilder();
        filepath.append(synapseConfigsDir).append('/').append(manger.getTracker().getCurrentConfigurationName()).append('/').append(MultiXMLConfigurationBuilder.SEQUENCES_DIR).append('/').append(authFailureHandlerSequenceName).append(".xml");
        File authFailureHandlerSequenceNameFile = new File(filepath.toString());
        // sequence synapse configurations by using resource artifacts
        if (!authFailureHandlerSequenceNameFile.exists()) {
            createTenantSynapseConfigHierarchy(synapseConfigDir, tenantDomain);
        }
        String graphqlFilepath = String.valueOf(synapseConfigsDir) + '/' + manger.getTracker().getCurrentConfigurationName() + '/' + MultiXMLConfigurationBuilder.SEQUENCES_DIR + '/' + graphqlAuthFailureHandlerSequenceName + ".xml";
        File graphqlFailureHandlerSequenceNameFile = new File(graphqlFilepath);
        if (!graphqlFailureHandlerSequenceNameFile.exists()) {
            createTenantSynapseConfigHierarchy(synapseConfigDir, tenantDomain);
        }
        String threatFaultConfigLocation = synapseConfigsDir.getAbsolutePath() + File.separator + manger.getTracker().getCurrentConfigurationName() + File.separator + MultiXMLConfigurationBuilder.SEQUENCES_DIR + File.separator + threatFaultSequenceName + ".xml";
        File threatFaultXml = new File(threatFaultConfigLocation);
        if (!threatFaultXml.exists()) {
            FileUtils.copyFile(new File(synapseConfigRootPath + threatFaultSequenceName + ".xml"), new File(synapseConfigDir.getAbsolutePath() + File.separator + MultiXMLConfigurationBuilder.SEQUENCES_DIR + File.separator + threatFaultSequenceName + ".xml"));
        }
        String blockingSequenceLocation = synapseConfigsDir.getAbsolutePath() + File.separator + manger.getTracker().getCurrentConfigurationName() + File.separator + MultiXMLConfigurationBuilder.SEQUENCES_DIR + File.separator + blockingSequence + ".xml";
        File blockingSequenceXml = new File(blockingSequenceLocation);
        if (!blockingSequenceXml.exists()) {
            FileUtils.copyFile(new File(synapseConfigRootPath + blockingSequence + ".xml"), new File(synapseConfigDir.getAbsolutePath() + File.separator + MultiXMLConfigurationBuilder.SEQUENCES_DIR + File.separator + blockingSequence + ".xml"));
        }
        String backEndFailureSequence = synapseConfigsDir.getAbsolutePath() + File.separator + manger.getTracker().getCurrentConfigurationName() + File.separator + MultiXMLConfigurationBuilder.SEQUENCES_DIR + File.separator + backendFailureSequenceName + ".xml";
        File backendSequenceXml = new File(backEndFailureSequence);
        if (!backendSequenceXml.exists()) {
            FileUtils.copyFile(new File(synapseConfigRootPath + backendFailureSequenceName + ".xml"), new File(synapseConfigDir.getAbsolutePath() + File.separator + MultiXMLConfigurationBuilder.SEQUENCES_DIR + File.separator + backendFailureSequenceName + ".xml"));
        }
        String opaPolicyFailureSequence = synapseConfigsDir.getAbsolutePath() + File.separator + manger.getTracker().getCurrentConfigurationName() + File.separator + MultiXMLConfigurationBuilder.SEQUENCES_DIR + File.separator + opaPolicyFailureHandlerSequenceName + ".xml";
        File opaPolicyFailureSequenceXml = new File(opaPolicyFailureSequence);
        if (!opaPolicyFailureSequenceXml.exists()) {
            FileUtils.copyFile(new File(synapseConfigRootPath + opaPolicyFailureHandlerSequenceName + ".xml"), new File(synapseConfigDir.getAbsolutePath() + File.separator + MultiXMLConfigurationBuilder.SEQUENCES_DIR + File.separator + opaPolicyFailureHandlerSequenceName + ".xml"));
        }
    } catch (RemoteException e) {
        log.error("Failed to create Tenant's synapse sequences.", e);
    } catch (Exception e) {
        log.error("Failed to create Tenant's synapse sequences.", e);
    }
    // Create caches for tenants
    CacheProvider.removeAllCaches();
    CacheProvider.createGatewayKeyCache();
    CacheProvider.createResourceCache();
    CacheProvider.createGatewayTokenCache();
    CacheProvider.createInvalidTokenCache();
    CacheProvider.createGatewayBasicAuthResourceCache();
    CacheProvider.createGatewayUsernameCache();
    CacheProvider.createInvalidUsernameCache();
    // Initialize product REST API token caches
    CacheProvider.createRESTAPITokenCache();
    CacheProvider.createRESTAPIInvalidTokenCache();
    CacheProvider.createGatewayJWTTokenCache();
    CacheProvider.createTenantConfigCache();
    CacheProvider.createRecommendationsCache();
    CacheProvider.createParsedSignJWTCache();
    CacheProvider.createInvalidGatewayApiKeyCache();
    CacheProvider.createGatewayInternalKeyCache();
    CacheProvider.createGatewayInternalKeyDataCache();
    CacheProvider.createInvalidInternalKeyCache();
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) UserRegistry(org.wso2.carbon.registry.core.session.UserRegistry) IOException(java.io.IOException) RemoteException(java.rmi.RemoteException) ReentrantLock(java.util.concurrent.locks.ReentrantLock) Lock(java.util.concurrent.locks.Lock) RemoteException(java.rmi.RemoteException) File(java.io.File) ConfigurationManager(org.wso2.carbon.mediation.initializer.configurations.ConfigurationManager)

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