Java Code Examples for org.wso2.carbon.registry.core.service.RegistryService#getConfigSystemRegistry()

The following examples show how to use org.wso2.carbon.registry.core.service.RegistryService#getConfigSystemRegistry() . 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
Source File: SecurityUIUtil.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
public static String getUrl() throws Exception {

        if (url == null) {
            ServiceHolder serviceHodler = ServiceHolder.getInstance();
            RegistryService regService = serviceHodler.getRegistryService();
            Registry systemRegistry = regService.getConfigSystemRegistry();
            Resource resource = systemRegistry.get("/carbon/connection/props");
            String servicePath = resource.getProperty("service-path");
            String contextRoot = resource.getProperty("context-root");

            String host = resource.getProperty("host-name");
            contextRoot = StringUtils.equals("/", contextRoot) ? "" : contextRoot;

            host = (host == null) ? "localhost" : host;
            String port = System.getProperty("carbon.https.port");
            StringBuilder urlValue = new StringBuilder();
            url = (urlValue.append("https://").append(host).append(":").append(port).append("/")
                    .append(contextRoot).append(servicePath).append("/")).toString();
        }

        return url;
    }
 
Example 2
Source File: JWTClientUtil.java    From carbon-device-mgt with Apache License 2.0 6 votes vote down vote up
/**
 * Get the jwt details from the registry for tenants.
 *
 * @param tenantId         for identify tenant space.
 * @param registryLocation retrive the config file from tenant space.
 * @return the config for tenant
 * @throws RegistryException
 */
public static Resource getConfigRegistryResourceContent(int tenantId, final String registryLocation)
		throws RegistryException {
	try {
		Resource resource = null;
		PrivilegedCarbonContext.startTenantFlow();
		PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenantId, true);
		RegistryService registryService = JWTClientExtensionDataHolder.getInstance().getRegistryService();
		if (registryService != null) {
			Registry registry = registryService.getConfigSystemRegistry(tenantId);
			JWTClientUtil.loadTenantRegistry(tenantId);
			if (registry.resourceExists(registryLocation)) {
				resource = registry.get(registryLocation);
			}
		}
		return resource;
	} finally {
		PrivilegedCarbonContext.endTenantFlow();
	}
}
 
Example 3
Source File: JWTClientUtil.java    From carbon-device-mgt with Apache License 2.0 6 votes vote down vote up
/**
 * Get the jwt details from the registry for tenants.
 *
 * @param tenantId for accesing tenant space.
 * @return the config for tenant
 * @throws RegistryException
 */
public static void addJWTConfigResourceToRegistry(int tenantId, String content)
		throws RegistryException {
	try {
		PrivilegedCarbonContext.startTenantFlow();
		PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenantId, true);
		RegistryService registryService = JWTClientExtensionDataHolder.getInstance().getRegistryService();
		if (registryService != null) {
			Registry registry = registryService.getConfigSystemRegistry(tenantId);
			JWTClientUtil.loadTenantRegistry(tenantId);
			if (!registry.resourceExists(TENANT_JWT_CONFIG_LOCATION)) {
				Resource resource = registry.newResource();
				resource.setContent(content.getBytes());
				registry.put(TENANT_JWT_CONFIG_LOCATION, resource);
			}
		}
	} finally {
		PrivilegedCarbonContext.endTenantFlow();
	}
}
 
Example 4
Source File: SecurityUIUtil.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
public static String getUrl() throws Exception {

        if (url == null) {
            ServiceHolder serviceHodler = ServiceHolder.getInstance();
            RegistryService regService = serviceHodler.getRegistryService();
            Registry systemRegistry = regService.getConfigSystemRegistry();
            Resource resource = systemRegistry.get("/carbon/connection/props");
            String servicePath = resource.getProperty("service-path");
            String contextRoot = resource.getProperty("context-root");

            String host = resource.getProperty("host-name");
            contextRoot = StringUtils.equals("/", contextRoot) ? "" : contextRoot;

            host = (host == null) ? "localhost" : host;
            String port = System.getProperty("carbon.https.port");
            StringBuilder urlValue = new StringBuilder();
            url = (urlValue.append("https://").append(host).append(":").append(port).append("/").append(contextRoot).append(servicePath).append("/")).toString();
        }

        return url;
    }
 
Example 5
Source File: AbstractMetaDataHandler.java    From carbon-commons with Apache License 2.0 6 votes vote down vote up
private void loadMetaData() throws ReportingException {
    try {
        RegistryService registryService = ReportingTemplateComponent.getRegistryService();
        Registry registry = registryService.getConfigSystemRegistry();
        registry.beginTransaction();
        String location = ReportConstants.REPORT_META_DATA_PATH + ReportConstants.METADATA_FILE_NAME;
        Resource resource = null;
        if (registry.resourceExists(location)) {
            resource = registry.get(location);
            loadXML(resource);
            registry.commitTransaction();
        } else {
            createNewMetaData();
            registry.commitTransaction();
        }
    } catch (RegistryException e) {
        throw new ReportingException("Exception occured in loading the mete-data of reports", e);
    }

}
 
Example 6
Source File: MetadataFinder.java    From carbon-commons with Apache License 2.0 6 votes vote down vote up
private static boolean loadMetaData() throws ReportingException {
    try {
        RegistryService registryService = ReportingTemplateComponent.getRegistryService();
        Registry registry = registryService.getConfigSystemRegistry();
        registry.beginTransaction();
        String location = ReportConstants.REPORT_META_DATA_PATH + ReportConstants.METADATA_FILE_NAME;
        Resource resource = null;
        if (registry.resourceExists(location)) {
            resource = registry.get(location);
            loadXML(resource);
            registry.commitTransaction();
            return true;
        } else {
            registry.commitTransaction();
            return false;
        }
    } catch (RegistryException e) {
        log.error("Exception occurred in loading the mete-data of reports", e);
        throw new ReportingException("Exception occurred in loading the mete-data of reports", e);
    }

}
 
Example 7
Source File: Util.java    From carbon-commons with Apache License 2.0 6 votes vote down vote up
public static String getRelativeUrl() {
    BundleContext context = CarbonUIUtil.getBundleContext();
    ServiceReference reference = context.getServiceReference(RegistryService.class
            .getName());
    RegistryService registryService = (RegistryService) context.getService(reference);
    String url = null;
    try {
        Registry systemRegistry = registryService.getConfigSystemRegistry();
        Resource resource = systemRegistry.get("/carbon/connection/props");
        String servicePath = resource.getProperty("service-path");
        String contextRoot = resource.getProperty("context-root");
        contextRoot = contextRoot.equals("/") ? "" : contextRoot;
        url = contextRoot + servicePath + "/Java2WSDLService";
    } catch (Exception e) {
        log.error(e);
    }
    return url;
}
 
Example 8
Source File: Util.java    From carbon-commons with Apache License 2.0 6 votes vote down vote up
public static String getRelativeUrl() {
    BundleContext context = CarbonUIUtil.getBundleContext();
    ServiceReference reference =
            context.getServiceReference(RegistryService.class.getName());
    RegistryService registryService = (RegistryService) context.getService(reference);
    String url = null;
    try {
        Registry systemRegistry = registryService.getConfigSystemRegistry();
        Resource resource = systemRegistry.get(RegistryResources.CONNECTION_PROPS);
        String servicePath = resource.getProperty("service-path");
        String contextRoot = resource.getProperty("context-root");
        contextRoot = contextRoot.equals("/") ? "" : contextRoot;
        url = contextRoot + servicePath + "/WSDL2CodeService";
    } catch (Exception e) {
        log.error(e);
    }
    return url;
}
 
Example 9
Source File: Util.java    From carbon-commons with Apache License 2.0 6 votes vote down vote up
public static String getRelativeUrl() {
    BundleContext context = CarbonUIUtil.getBundleContext();
    ServiceReference reference =
            context.getServiceReference(RegistryService.class.getName());
    RegistryService registryService = (RegistryService) context.getService(reference);
    String url = null;
    try {
        Registry systemRegistry = registryService.getConfigSystemRegistry();
        Resource resource = systemRegistry.get(RegistryResources.CONNECTION_PROPS);
        String servicePath = resource.getProperty("service-path");
        String contextRoot = resource.getProperty("context-root");
        contextRoot = contextRoot.equals("/") ? "" : contextRoot;
        url = contextRoot + servicePath + "/WSDL2CodeService";
    } catch (Exception e) {
        log.error(e);
    }
    return url;
}
 
Example 10
Source File: RegistryConfigWriter.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
@Override
public void write(int tenantId, Properties props, String resourcePath)
        throws IdentityMgtConfigException {

    if(log.isDebugEnabled()) {
        log.debug("Writing data to registry path : " + resourcePath);
    }
    
    RegistryService registry = IdentityMgtServiceComponent.getRegistryService();
    try {
        UserRegistry userReg = registry.getConfigSystemRegistry(tenantId);
        Resource resource = userReg.newResource();
        Set<String> names = props.stringPropertyNames();
        // Only key value pairs exists and no multiple values exists a key.
        for (String keyName : names) {
            List<String> value = new ArrayList<String>();
            String valueStr = props.getProperty(keyName);
            
            if(log.isDebugEnabled()) {
                log.debug("Write key : " + keyName + " value : " + value);
            }
            
            // This is done due to casting to List in JDBCRegistryDao
            value.add(valueStr);
            resource.setProperty(keyName, value);
        }
        userReg.put(resourcePath, resource);

    } catch (RegistryException e) {
        throw new IdentityMgtConfigException(
                "Error occurred while writing data to registry path : " + resourcePath, e);
    }

}
 
Example 11
Source File: RegistryConfigWriter.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
@Override
public void write(int tenantId, Properties props, String resourcePath)
        throws IdentityMgtConfigException {

    if(log.isDebugEnabled()) {
        log.debug("Writing data to registry path : " + resourcePath);
    }
    
    RegistryService registry = IdentityMgtServiceComponent.getRegistryService();
    try {
        UserRegistry userReg = registry.getConfigSystemRegistry(tenantId);
        Resource resource = userReg.newResource();
        Set<String> names = props.stringPropertyNames();
        // Only key value pairs exists and no multiple values exists a key.
        for (String keyName : names) {
            List<String> value = new ArrayList<String>();
            String valueStr = props.getProperty(keyName);
            
            if(log.isDebugEnabled()) {
                log.debug("Write key : " + keyName + " value : " + value);
            }
            
            // This is done due to casting to List in JDBCRegistryDao
            value.add(valueStr);
            resource.setProperty(keyName, value);
        }
        userReg.put(resourcePath, resource);

    } catch (RegistryException e) {
        throw new IdentityMgtConfigException(
                "Error occurred while writing data to registry path : " + resourcePath, e);
    }

}
 
Example 12
Source File: AbstractMetaDataHandler.java    From carbon-commons with Apache License 2.0 5 votes vote down vote up
public void saveMetadata
        () throws ReportingException {
    try {
        RegistryService registryService = ReportingTemplateComponent.getRegistryService();
        Registry registry = registryService.getConfigSystemRegistry();
        registry.beginTransaction();
        Resource reportFilesResource = registry.newResource();
        reportFilesResource.setContent(reportsElement.toString());
        String location = ReportConstants.REPORT_META_DATA_PATH + ReportConstants.METADATA_FILE_NAME;
        registry.put(location, reportFilesResource);
        registry.commitTransaction();
    } catch (RegistryException e) {
        throw new ReportingException("Exception occured in loading the meta-data of reports", e);
    }
}
 
Example 13
Source File: JRxmlFileBundleListener.java    From carbon-commons with Apache License 2.0 4 votes vote down vote up
/**
 * used to add .jrxml files to registry at bundle deployment time
 *
 * @param bundle Bundle
 * @throws ReportingException error occurred adding .jrxml file to registry
 */
public void addJrXmlToRegistry(Bundle bundle) throws ReportingException {

    BundleContext bundleContext = bundle.getBundleContext();
    String reportResource = "/reports/";
    Enumeration enumeration = bundleContext.getBundle().getEntryPaths(reportResource);
    if (enumeration == null) {
        return;
    }
    try {
        RegistryService registryService = ReportingComponent.getRegistryService();
        Registry registry = registryService.getConfigSystemRegistry();
        registry.beginTransaction();
        Resource reportFilesResource = registry.newResource();
        InputStream xmlStream = null;
        try{
        while (enumeration.hasMoreElements()) {
            String path = enumeration.nextElement().toString();
            URL url = bundleContext.getBundle().getResource(path);
            if (url == null) {
                return;
            }
             xmlStream = url.openStream();
            if (xmlStream == null) {
                return;
            }
            reportFilesResource.setContentStream(xmlStream);
            String location = ReportConstants.REPORT_BASE_PATH + bundle.getSymbolicName() + "/" + path.split("/")[1];
            if (!registry.resourceExists(location)) {
                registry.put(location, reportFilesResource);
            }
        }
        }finally {
          xmlStream.close();
        }
        registry.commitTransaction();
    } catch (Exception e) {
        String msg = "Error occurred adding .jrxml file from " +
                bundle.getSymbolicName() + " to registry";
        throw new ReportingException(msg, e);
    }

}