Java Code Examples for org.wso2.carbon.utils.ConfigurationContextService

The following examples show how to use org.wso2.carbon.utils.ConfigurationContextService. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Reference(
        name = "configuration.context.service",
        service = ConfigurationContextService.class,
        cardinality = ReferenceCardinality.MANDATORY,
        policy = ReferencePolicy.DYNAMIC,
        unbind = "unsetConfigurationContextService"
)
protected void setConfigurationContextService(ConfigurationContextService configurationContextService) {

    /*
     * ConfigurationManagerComponent checks for the database column, 'CREATED_TIME' in the IDN_CONFIG_RESOURCE
     * table. Database connection creation requires in this task depends on the ConfigurationContextService.
     * This reference will ensure that the ConfigurationContextService is activated before the
     * ConfigurationManagerComponent is activated.
     */
    log.debug("ConfigurationContextService Instance registered.");
}
 
Example 2
Source Project: carbon-apimgt   Source File: TenantLoadMessageSenderTest.java    License: Apache License 2.0 6 votes vote down vote up
@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();
}
 
Example 3
Source Project: carbon-apimgt   Source File: TestUtils.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * To initialize the (@link {@link ConfigurationContextService}} for testing.
 *
 * @return initialized configuration context service.
 */
public static ConfigurationContextService initConfigurationContextService(boolean initAPIMConfigurationService) {
    ConfigurationContextService configurationContextService = Mockito.mock(ConfigurationContextService.class);
    ConfigurationContext configurationContext = Mockito.mock(ConfigurationContext.class);
    AxisConfiguration axisConfiguration = Mockito.mock(AxisConfiguration.class);
    Mockito.doReturn(axisConfiguration).when(configurationContext).getAxisConfiguration();
    TransportInDescription transportInDescription = Mockito.mock(TransportInDescription.class);
    Mockito.doReturn(transportInDescription).when(axisConfiguration).getTransportIn(Mockito.anyString());
    Mockito.doReturn(configurationContext).when(configurationContextService).getServerConfigContext();

    if (initAPIMConfigurationService) {
        APIManagerConfigurationService apiManagerConfigurationService = Mockito
                .mock(APIManagerConfigurationService.class);
        APIManagerConfiguration apiManagerConfiguration = Mockito.mock(APIManagerConfiguration.class);
        Mockito.doReturn("true").when(apiManagerConfiguration).getFirstProperty(APIConstants.ENABLE_MTLS_FOR_APIS);
        Mockito.doReturn(apiManagerConfiguration).when(apiManagerConfigurationService).getAPIManagerConfiguration();
        ServiceReferenceHolder.getInstance().setAPIManagerConfigurationService(apiManagerConfigurationService);
    }
    ServiceReferenceHolder.setContextService(configurationContextService);
    System.setProperty("javax.net.ssl.trustStorePassword", "wso2carbon");
    System.setProperty("javax.net.ssl.trustStore", ".");
    return configurationContextService;
}
 
Example 4
Source Project: carbon-device-mgt   Source File: DeviceManagerUtil.java    License: Apache License 2.0 6 votes vote down vote up
public static String getServerBaseHttpsUrl() {
    String hostName = "localhost";
    try {
        hostName = NetworkUtils.getMgtHostName();
    } catch (Exception ignored) {
    }
    String mgtConsoleTransport = CarbonUtils.getManagementTransport();
    ConfigurationContextService configContextService =
            DeviceManagementDataHolder.getInstance().getConfigurationContextService();
    int port = CarbonUtils.getTransportPort(configContextService, mgtConsoleTransport);
    int httpsProxyPort =
            CarbonUtils.getTransportProxyPort(configContextService.getServerConfigContext(),
                    mgtConsoleTransport);
    if (httpsProxyPort > 0) {
        port = httpsProxyPort;
    }
    return "https://" + hostName + ":" + port;
}
 
Example 5
Source Project: attic-stratos   Source File: AbstractApi.java    License: Apache License 2.0 6 votes vote down vote up
protected ConfigurationContext getConfigContext() {

        // If a tenant has been set, then try to get the ConfigurationContext of that tenant
        PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
        ConfigurationContextService configurationContextService =
                (ConfigurationContextService) carbonContext.getOSGiService(ConfigurationContextService.class);
        ConfigurationContext mainConfigContext = configurationContextService.getServerConfigContext();
        String domain = carbonContext.getTenantDomain();
        if (domain != null && !MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(domain)) {
            return TenantAxisUtils.getTenantConfigurationContext(domain, mainConfigContext);
        } else if (carbonContext.getTenantId() == MultitenantConstants.SUPER_TENANT_ID) {
            return mainConfigContext;
        } else {
            throw new UnsupportedOperationException("Tenant domain unidentified. " +
                    "Upstream code needs to identify & set the tenant domain & tenant ID. " +
                    " The TenantDomain SOAP header could be set by the clients or " +
                    "tenant authentication should be carried out.");
        }
    }
 
Example 6
Source Project: product-private-paas   Source File: AbstractAdmin.java    License: Apache License 2.0 6 votes vote down vote up
protected ConfigurationContext getConfigContext() {

        // If a tenant has been set, then try to get the ConfigurationContext of that tenant
        PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
        ConfigurationContextService configurationContextService = (ConfigurationContextService) carbonContext
                .getOSGiService(ConfigurationContextService.class);
        ConfigurationContext mainConfigContext = configurationContextService.getServerConfigContext();
        String domain = carbonContext.getTenantDomain();
        if (domain != null && !MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(domain)) {
            return TenantAxisUtils.getTenantConfigurationContext(domain, mainConfigContext);
        } else if (carbonContext.getTenantId() == MultitenantConstants.SUPER_TENANT_ID) {
            return mainConfigContext;
        } else {
            throw new UnsupportedOperationException("Tenant domain unidentified. " +
                    "Upstream code needs to identify & set the tenant domain & tenant ID. " +
                    " The TenantDomain SOAP header could be set by the clients or " +
                    "tenant authentication should be carried out.");
        }
    }
 
Example 7
Source Project: product-private-paas   Source File: ServiceUtils.java    License: Apache License 2.0 6 votes vote down vote up
private static ConfigurationContext getConfigContext() {

        // If a tenant has been set, then try to get the ConfigurationContext of that tenant
        PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
        ConfigurationContextService configurationContextService = (ConfigurationContextService) carbonContext
                .getOSGiService(ConfigurationContextService.class);
        ConfigurationContext mainConfigContext = configurationContextService.getServerConfigContext();
        String domain = carbonContext.getTenantDomain();
        if (domain != null && !MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(domain)) {
            return TenantAxisUtils.getTenantConfigurationContext(domain, mainConfigContext);
        } else if (carbonContext.getTenantId() == MultitenantConstants.SUPER_TENANT_ID) {
            return mainConfigContext;
        } else {
            throw new UnsupportedOperationException("Tenant domain unidentified. " +
                    "Upstream code needs to identify & set the tenant domain & tenant ID. " +
                    " The TenantDomain SOAP header could be set by the clients or " +
                    "tenant authentication should be carried out.");
        }
    }
 
Example 8
@Reference(
        name = "configuration.context.service",
        service = ConfigurationContextService.class,
        cardinality = ReferenceCardinality.MANDATORY,
        policy = ReferencePolicy.DYNAMIC,
        unbind = "unsetConfigurationContextService"
)
protected void setConfigurationContextService(ConfigurationContextService configContextService) {
    if (log.isDebugEnabled()) {
        log.debug("Setting the Configuration Context Service");
    }
    ApplicationManagementServiceComponentHolder.getInstance().setConfigContextService(configContextService);
}
 
Example 9
@Reference(
        name = "config.context.service",
        service = org.wso2.carbon.utils.ConfigurationContextService.class,
        cardinality = ReferenceCardinality.MANDATORY,
        policy = ReferencePolicy.DYNAMIC,
        unbind = "unsetConfigurationContextService")
protected void setConfigurationContextService(ConfigurationContextService ccService) {

    ConfigurationContext serverCtx = ccService.getServerConfigContext();
    AxisConfiguration serverConfig = serverCtx.getAxisConfiguration();
    LocalTransportReceiver.CONFIG_CONTEXT = new ConfigurationContext(serverConfig);
    LocalTransportReceiver.CONFIG_CONTEXT.setServicePath("services");
    LocalTransportReceiver.CONFIG_CONTEXT.setContextRoot("local:/");
    DataHolder.getInstance().setConfigurationContextService(ccService);
}
 
Example 10
@Reference(
        name = "config.context.service",
        service = ConfigurationContextService.class,
        cardinality = ReferenceCardinality.MANDATORY,
        policy = ReferencePolicy.DYNAMIC,
        unbind = "unsetConfigurationContextService"
)
protected void setConfigurationContextService(ConfigurationContextService configurationContextService) {

    ApplicationMgtServiceComponentHolder.getInstance().setConfigurationContextService(configurationContextService);
    if (log.isDebugEnabled()) {
        log.debug("ConfigurationContextService Instance was set.");
    }
}
 
Example 11
Source Project: carbon-apimgt   Source File: TestUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static ServiceReferenceHolder getServiceReferenceHolder() {
    PowerMockito.mockStatic(ServiceReferenceHolder.class);
    ServiceReferenceHolder sh = PowerMockito.mock(ServiceReferenceHolder.class);
    PowerMockito.when(ServiceReferenceHolder.getInstance()).thenReturn(sh);
    ConfigurationContextService configurationContextService = initConfigurationContextService(false);
    PowerMockito.when(ServiceReferenceHolder.getContextService()).thenReturn(configurationContextService);
    return sh;
}
 
Example 12
@Reference(
         name = "configuration.context", 
         service = org.wso2.carbon.utils.ConfigurationContextService.class, 
         cardinality = ReferenceCardinality.MANDATORY, 
         policy = ReferencePolicy.DYNAMIC, 
         unbind = "unsetConfigurationContext")
protected void setConfigurationContext(ConfigurationContextService configurationContext) {
    this.configurationContext = configurationContext;
}
 
Example 13
Source Project: carbon-commons   Source File: WSEventBrokerDS.java    License: Apache License 2.0 5 votes vote down vote up
@Reference(
        name = "configurationcontext.service",
        service = org.wso2.carbon.utils.ConfigurationContextService.class,
        cardinality = ReferenceCardinality.MANDATORY,
        policy = ReferencePolicy.DYNAMIC,
        unbind = "unsetConfigurationContextService")
protected void setConfigurationContextService(ConfigurationContextService configurationContextService) {

    WSEventBrokerHolder.getInstance().registerConfigurationContextService(configurationContextService);
}
 
Example 14
protected void unsetConfigurationContextService(ConfigurationContextService contextService) {
    if (log.isDebugEnabled()) {
        log.debug("Unsetting the ConfigurationContext");
    }
    this.configContextService = null;
    SecurityServiceHolder.setConfigurationContextService(contextService);
}
 
Example 15
Source Project: carbon-commons   Source File: UrlMapperServerComponent.java    License: Apache License 2.0 5 votes vote down vote up
@Reference(
         name = "config.context.service",
         service = org.wso2.carbon.utils.ConfigurationContextService.class,
         cardinality = ReferenceCardinality.MANDATORY,
         policy = ReferencePolicy.DYNAMIC,
         unbind = "unsetConfigurationContextService")
protected void setConfigurationContextService(ConfigurationContextService contextService) {
    DataHolder.getInstance().setServerConfigContext(contextService.getServerConfigContext());
}
 
Example 16
Source Project: carbon-apimgt   Source File: APIManagerComponent.java    License: Apache License 2.0 5 votes vote down vote up
@Reference(
         name = "config.context.service",
         service = org.wso2.carbon.utils.ConfigurationContextService.class,
         cardinality = ReferenceCardinality.MANDATORY,
         policy = ReferencePolicy.DYNAMIC,
         unbind = "unsetConfigurationContextService")
protected void setConfigurationContextService(ConfigurationContextService contextService) {
    ServiceReferenceHolder.setContextService(contextService);
}
 
Example 17
@Reference(
        name = "config.context.service",
        service = ConfigurationContextService.class,
        cardinality = ReferenceCardinality.MANDATORY,
        policy = ReferencePolicy.DYNAMIC,
        unbind = "unsetConfigurationContextService"
)
protected void setConfigurationContextService(ConfigurationContextService contextService) {
    if (log.isDebugEnabled()) {
        log.info("Setting the ConfigurationContextService");
    }
}
 
Example 18
Source Project: carbon-apimgt   Source File: HostObjectComponentTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testUnsetConfigurationContextService() {
    AxisConfiguration axisConfiguration = new AxisConfiguration();
    ConfigurationContextService configurationContextService = Mockito.mock(ConfigurationContextService.class);
    hostObjectComponent.unsetConfigurationContextService(configurationContextService);
    // Nothing to assert
}
 
Example 19
Source Project: carbon-commons   Source File: EventBrokerBuilderDS.java    License: Apache License 2.0 5 votes vote down vote up
@Reference(
        name = "configurationcontext.service",
        service = org.wso2.carbon.utils.ConfigurationContextService.class,
        cardinality = ReferenceCardinality.MANDATORY,
        policy = ReferencePolicy.DYNAMIC,
        unbind = "unsetConfigurationContextService")
protected void setConfigurationContextService(ConfigurationContextService configurationContextService) {

    EventBrokerHolder.getInstance().registerConfigurationContextService(configurationContextService);
}
 
Example 20
@Reference(
         name = "config.context.service", 
         service = org.wso2.carbon.utils.ConfigurationContextService.class, 
         cardinality = ReferenceCardinality.MANDATORY, 
         policy = ReferencePolicy.DYNAMIC, 
         unbind = "unsetConfigurationContextService")
protected void setConfigurationContextService(ConfigurationContextService configCtxtService) {
    OIDCAuthFEDataHolder.getInstance().setConfigurationContextService(configCtxtService);
}
 
Example 21
protected void setConfigurationContextService(ConfigurationContextService configurationContextService) {
    if (log.isDebugEnabled()) {
        log.debug("Setting ConfigurationContextService");
    }

    UrlPrinterDataHolder.getInstance().setConfigurationContextService(configurationContextService);

}
 
Example 22
Source Project: carbon-commons   Source File: StatisticsServiceComponent.java    License: Apache License 2.0 5 votes vote down vote up
@Reference(
        name = "config.context.service",
        service = org.wso2.carbon.utils.ConfigurationContextService.class,
        cardinality = ReferenceCardinality.MANDATORY,
        policy = ReferencePolicy.DYNAMIC,
        unbind = "unsetConfigurationContextService")
protected void setConfigurationContextService(ConfigurationContextService contextService) {

    this.configContext = contextService.getServerConfigContext();
}
 
Example 23
Source Project: carbon-commons   Source File: TasksDSComponent.java    License: Apache License 2.0 5 votes vote down vote up
@Reference(
        name = "config.context.service",
        service = org.wso2.carbon.utils.ConfigurationContextService.class,
        cardinality = ReferenceCardinality.MANDATORY,
        policy = ReferencePolicy.DYNAMIC,
        unbind = "unsetConfigurationContextService")
protected void setConfigurationContextService(ConfigurationContextService configCtxService) {

    TasksDSComponent.configCtxService = configCtxService;
}
 
Example 24
@Reference(
        name = "configuration.context.service",
        service = org.wso2.carbon.utils.ConfigurationContextService.class,
        cardinality = ReferenceCardinality.MANDATORY,
        policy = ReferencePolicy.DYNAMIC,
        unbind = "unsetConfigurationContextService")
protected void setConfigurationContextService(ConfigurationContextService configurationContextService) {

    log.debug("Recieving ConfigurationContext Service");
    this.configurationContextService = configurationContextService;
}
 
Example 25
Source Project: carbon-apimgt   Source File: APIHandlerServiceComponent.java    License: Apache License 2.0 5 votes vote down vote up
protected void unsetConfigurationContextService(ConfigurationContextService cfgCtxService) {

        if (log.isDebugEnabled()) {
            log.debug("Configuration context service unbound from the API handlers");
        }
        ServiceReferenceHolder.getInstance().setConfigurationContextService(null);
    }
 
Example 26
@Test
public void testServiceReferenceHolder() {
    ServiceReferenceHolder serviceReferenceHolder = ServiceReferenceHolder.getInstance();
    Assert.assertTrue(serviceReferenceHolder instanceof ServiceReferenceHolder);

    serviceReferenceHolder.getThrottleDataHolder();
    ThrottleDataHolder throttleDataHolder = Mockito.mock(ThrottleDataHolder.class);
    serviceReferenceHolder.setThrottleDataHolder(throttleDataHolder);

    ConfigurationContextService cfgCtxService = Mockito.mock(ConfigurationContextService.class);
    serviceReferenceHolder.setConfigurationContextService(cfgCtxService);
    cfgCtxService = serviceReferenceHolder.getConfigurationContextService();
    Assert.assertNotNull(cfgCtxService);


    APIManagerConfigurationService apiManagerConfigurationService = Mockito.mock(APIManagerConfigurationService.class);
    serviceReferenceHolder.setAPIManagerConfigurationService(apiManagerConfigurationService);
    apiManagerConfigurationService = serviceReferenceHolder.getApiManagerConfigurationService();
    Assert.assertNotNull(apiManagerConfigurationService);

    Assert.assertNull(serviceReferenceHolder.getAPIManagerConfiguration());

    Assert.assertNull(serviceReferenceHolder.getServerConfigurationContext());
    ThrottleProperties throttleProperties = Mockito.mock(ThrottleProperties.class);
    serviceReferenceHolder.setThrottleProperties(throttleProperties);
    Assert.assertNotNull(serviceReferenceHolder.getThrottleProperties());
}
 
Example 27
/**
 * @param contextService
 */
protected void unsetConfigurationContextService(ConfigurationContextService contextService) {
    if (log.isDebugEnabled()) {
        log.info("ConfigurationContextService unset in Identity STS Mgt bundle");
    }
    this.configContext = null;
}
 
Example 28
protected void unsetConfigurationContextService(ConfigurationContextService service) {

        if (log.isDebugEnabled()) {
            log.debug("Deployment synchronizer component unbound from the " + "configuration context service");
        }
        ServiceReferenceHolder.setConfigurationContextService(null);
    }
 
Example 29
@Reference(
         name = "config.context.service", 
         service = org.wso2.carbon.utils.ConfigurationContextService.class, 
         cardinality = ReferenceCardinality.MANDATORY, 
         policy = ReferencePolicy.DYNAMIC, 
         unbind = "unsetConfigurationContextService")
protected void setConfigurationContextService(ConfigurationContextService configCtxtService) {
    SSOHostObjectDataHolder.getInstance().setConfigurationContextService(configCtxtService);
}
 
Example 30
protected void unsetConfigurationContextService(ConfigurationContextService configCtxtService) {
    if (log.isDebugEnabled()) {
        log.debug("ConfigurationContextService unset in EntitlementServiceComponent bundle.");
    }
    EntitlementConfigHolder.getInstance().setConfigurationContextService(null);
}