Examples of RegistryContext


Examples of org.wso2.carbon.registry.core.config.RegistryContext

     * @throws RegistryException if the operation failed.
     */
    public static String getCollectionMediaTypeMappings(Registry configSystemRegistry)
            throws RegistryException {

        RegistryContext registryContext = configSystemRegistry.getRegistryContext();

        if (getCollectionMediaTypeMappings(registryContext) != null) {
            return getCollectionMediaTypeMappings(registryContext);
        }

        Resource resource;
        String mediaTypeString = null;

        String resourcePath = MIME_TYPE_COLLECTION + RegistryConstants.PATH_SEPARATOR +
                RESOURCE_MIME_TYPE_INDEX;

        // TODO: Adding the media types should ideally be done by the handler associated with the
        // media type
        if (!configSystemRegistry.resourceExists(resourcePath)) {
            getResourceMediaTypeMappings(configSystemRegistry);
        }
        if (!configSystemRegistry.resourceExists(resourcePath + RegistryConstants.PATH_SEPARATOR +
                COLLECTION_MIME_TYPE_INDEX)) {
            resource = configSystemRegistry.newResource();
            resource.setProperty("synapse", "application/vnd.apache.synapse");
            resource.setProperty("esb", "application/vnd.wso2.esb");
            resource.setProperty("axis2", "application/vnd.apache.axis2");
            resource.setProperty("wsas", "application/vnd.wso2.wsas");
            resource.setDescription("This resource contains the media Types associated with " +
                    "collections on the Registry. Add, Edit or Delete properties to Manage Media " +
                    "Types.");
            configSystemRegistry.put(resourcePath + RegistryConstants.PATH_SEPARATOR +
                    COLLECTION_MIME_TYPE_INDEX, resource);
        } else {
            resource = configSystemRegistry.get(resourcePath + RegistryConstants.PATH_SEPARATOR +
                    COLLECTION_MIME_TYPE_INDEX);
        }
        Properties properties = resource.getProperties();
        if (properties.size() > 0) {
            Set<Object> keySet = properties.keySet();
            for (Object key : keySet) {
                if (key instanceof String) {
                    String ext = (String) key;
                    if (RegistryUtils.isHiddenProperty(ext)) {
                        continue;
                    }
                    String value = resource.getProperty(ext);
                    String mediaTypeMapping = ext + ":" + value;
                    if (mediaTypeString == null) {
                        mediaTypeString = mediaTypeMapping;
                    } else {
                        mediaTypeString = mediaTypeString + "," + mediaTypeMapping;
                    }
                }
            }
        }
        registryContext.setCollectionMediaTypes(mediaTypeString);
        return mediaTypeString;
    }
View Full Code Here

Examples of org.wso2.carbon.registry.core.config.RegistryContext

     * @throws RegistryException if the operation failed.
     */
    public static String getCustomUIMediaTypeMappings(Registry configSystemRegistry)
            throws RegistryException {

        RegistryContext registryContext = configSystemRegistry.getRegistryContext();

        if (getCustomUIMediaTypeMappings(registryContext) != null) {
            return getCustomUIMediaTypeMappings(registryContext);
        }

        Resource resource;
        String mediaTypeString = null;

        String resourcePath = MIME_TYPE_COLLECTION + RegistryConstants.PATH_SEPARATOR +
                RESOURCE_MIME_TYPE_INDEX;

        // TODO: Adding the media types should ideally be done by the handler associated with the
        // media type
        if (!configSystemRegistry.resourceExists(resourcePath)) {
            getResourceMediaTypeMappings(configSystemRegistry);
        }
        if (!configSystemRegistry.resourceExists(resourcePath + RegistryConstants.PATH_SEPARATOR +
                CUSTOM_UI_MIME_TYPE_INDEX)) {
            resource = configSystemRegistry.newResource();
            resource.setProperty("profiles", "application/vnd.wso2-profiles+xml");
            //resource.setProperty("service", "application/vnd.wso2-service+xml");
            resource.setDescription("This resource contains the media Types associated with " +
                    "custom user interfaces on the Registry. Add, Edit or Delete properties to " +
                    "Manage Media Types.");
            configSystemRegistry.put(resourcePath + RegistryConstants.PATH_SEPARATOR +
                    CUSTOM_UI_MIME_TYPE_INDEX, resource);
        } else {
            resource = configSystemRegistry.get(resourcePath + RegistryConstants.PATH_SEPARATOR +
                    CUSTOM_UI_MIME_TYPE_INDEX);
        }
        Properties properties = resource.getProperties();
        if (properties.size() > 0) {
            Set<Object> keySet = properties.keySet();
            for (Object key : keySet) {
                if (key instanceof String) {
                    String ext = (String) key;
                    if (RegistryUtils.isHiddenProperty(ext)) {
                        continue;
                    }
                    String value = resource.getProperty(ext);
                    String mediaTypeMapping = ext + ":" + value;
                    if (mediaTypeString == null) {
                        mediaTypeString = mediaTypeMapping;
                    } else {
                        mediaTypeString = mediaTypeString + "," + mediaTypeMapping;
                    }
                }
            }
        }
        registryContext.setCustomUIMediaTypes(mediaTypeString);
        return mediaTypeString;
    }
View Full Code Here

Examples of org.wso2.carbon.registry.core.config.RegistryContext

     * @throws RegistryException if the operation failed.
     */
    public static String getResourceMediaTypeMappings(Registry configSystemRegistry)
            throws RegistryException {

        RegistryContext registryContext = configSystemRegistry.getRegistryContext();

        if (getResourceMediaTypeMappings(registryContext) != null) {
            return getResourceMediaTypeMappings(registryContext);
        }

        Resource resource;
        String mediaTypeString = null;

        String resourcePath = MIME_TYPE_COLLECTION + RegistryConstants.PATH_SEPARATOR +
                RESOURCE_MIME_TYPE_INDEX;

        if (!configSystemRegistry.resourceExists(resourcePath)) {
            resource = configSystemRegistry.newCollection();
        } else {
            resource = configSystemRegistry.get(resourcePath);
            Properties properties = resource.getProperties();
            if (properties.size() > 0) {
                Set<Object> keySet = properties.keySet();
                for (Object key : keySet) {
                    if (key instanceof String) {
                        String ext = (String) key;
                        if (RegistryUtils.isHiddenProperty(ext)) {
                            continue;
                        }
                        String value = resource.getProperty(ext);
                        String mediaTypeMapping = ext + ":" + value;
                        if (mediaTypeString == null) {
                            mediaTypeString = mediaTypeMapping;
                        } else {
                            mediaTypeString = mediaTypeString + "," + mediaTypeMapping;
                        }
                    }
                }
            }
            registryContext.setResourceMediaTypes(mediaTypeString);
            return mediaTypeString;
        }

        BufferedReader reader;
        try {
            File mimeFile = getMediaTypesFile();
            reader = new BufferedReader(new InputStreamReader(new FileInputStream(mimeFile)));
        } catch (Exception e) {
            String msg = "Failed to read the the media type definitions file. Only a limited " +
                    "set of media type definitions will be populated. ";
            log.error(msg, e);
            mediaTypeString = "txt:text/plain,jpg:image/jpeg,gif:image/gif";
            registryContext.setResourceMediaTypes(mediaTypeString);
            return mediaTypeString;
        }


        try {
            while (reader.ready()) {
                String mediaTypeData = reader.readLine().trim();
                if (mediaTypeData.startsWith("#")) {
                    // ignore the comments
                    continue;
                }

                if (mediaTypeData.length() == 0) {
                    // ignore the blank lines
                    continue;
                }

                // mime.type file delimits media types:extensions by tabs. if there is no
                // extension associated with a media type, there are no tabs in the line. so we
                // don't need such lines.
                if (mediaTypeData.indexOf("\t") > 0) {

                    String[] parts = mediaTypeData.split("\t+");
                    if (parts.length == 2 && parts[0].length() > 0 && parts[1].length() > 0) {

                        // there can multiple extensions associated with a single media type. in
                        // that case, extensions are delimited by a space.
                        String[] extensions = parts[1].trim().split(" ");
                        for (String extension : extensions) {
                            if (extension.length() > 0) {
                                String mediaTypeMapping = extension + ":" + parts[0];
                                resource.setProperty(extension, parts[0]);
                                if (mediaTypeString == null) {
                                    mediaTypeString = mediaTypeMapping;
                                } else {
                                    mediaTypeString = mediaTypeString + "," + mediaTypeMapping;
                                }
                            }
                        }
                    }
                }
            }
            resource.setDescription("This collection contains the media Types available for " +
                    "resources on the Registry. Add, Edit or Delete properties to Manage Media " +
                    "Types.");
            Resource collection = configSystemRegistry.newCollection();
            collection.setDescription("This collection lists the media types available on the " +
                    "Registry Server. Before changing an existing media type, please make sure " +
                    "to alter existing resources/collections and related configuration details.");
            configSystemRegistry.put(MIME_TYPE_COLLECTION, collection);
            configSystemRegistry.put(resourcePath, resource);

        } catch (IOException e) {
            String msg = "Could not read the media type mappings file from the location: ";
            throw new RegistryException(msg);

        } finally {
            try {
                reader.close();
            } catch (IOException ignore) {
            }
        }
        registryContext.setResourceMediaTypes(mediaTypeString);
        return mediaTypeString;
    }
View Full Code Here

Examples of org.wso2.carbon.registry.core.config.RegistryContext

        // get the realm config to retrieve admin username, password
        realmConfig = ctx.getRealmService().getBootstrapRealmConfiguration();
        Registry adminRegistry = embeddedRegistryService.getUserRegistry(
            realmConfig.getAdminUserName(), realmConfig.getAdminPassword());
        RegistryContext registryContext = adminRegistry.getRegistryContext();
        MyPrivateHandler myPrivateHandler = new MyPrivateHandler();

        HandlerManager handlerManager = registryContext.getHandlerManager();

        URLMatcher myPrivateHandlerMatcher = new URLMatcher();
        myPrivateHandlerMatcher.setGetPattern(".*/to/my/private/handler");
        myPrivateHandlerMatcher.setPutPattern(".*/to/my/private/handler");
        handlerManager.addHandler(
View Full Code Here

Examples of org.wso2.carbon.registry.core.config.RegistryContext

        UserRegistry userRegistry =
                (UserRegistry) request.getSession()
                        .getAttribute(RegistryConstants.ROOT_REGISTRY_INSTANCE);

        String anonymousUser;
        RegistryContext registryContext = RegistryContext.getBaseInstance();
        if (registryContext != null) {
            anonymousUser = CarbonConstants.REGISTRY_ANONNYMOUS_USERNAME;
        } else {
            return false;
        }
View Full Code Here

Examples of org.wso2.carbon.registry.core.config.RegistryContext

        tenantId = CurrentSession.getTenantId();
        if (tenantId < 0) {
            tenantId = CarbonContextHolder.getCurrentCarbonContextHolder().getTenantId();
        }
        String resourceCachePath;
        RegistryContext registryContext = registry.getRegistryContext();
        if (registryContext == null) {
            registryContext = RegistryContext.getBaseInstance();
        }
        if (registry instanceof EmbeddedRegistry) {
            resourceCachePath = path;
        } else {
            resourceCachePath = RegistryUtils.getAbsolutePath(registryContext, path);
        }
        DataBaseConfiguration dataBaseConfiguration =
                registryContext.getDefaultDataBaseConfiguration();
        if (dataBaseConfiguration != null) {
            connectionId = dataBaseConfiguration.getUserName() + "@" +
                    dataBaseConfiguration.getDbUrl();
        }
View Full Code Here

Examples of org.wso2.carbon.registry.core.config.RegistryContext

     * @param cachePath      cached resource path
     * @param recursive      whether this operation must be recursively applied on child resources
     */
    private void clearCache(RequestContext requestContext, String cachePath, boolean recursive) {
        String connectionId = "";
        RegistryContext registryContext = requestContext.getRegistryContext();
        if (registryContext == null) {
            registryContext = RegistryContext.getBaseInstance();
        }
        DataBaseConfiguration dataBaseConfiguration =
                registryContext.getDefaultDataBaseConfiguration();
        if (dataBaseConfiguration != null) {
            connectionId = dataBaseConfiguration.getUserName() + "@" +
                    dataBaseConfiguration.getDbUrl();
        }
        RegistryCacheKey registryCacheKey =
View Full Code Here

Examples of org.wso2.carbon.registry.core.config.RegistryContext

    // Initializes the user registry.
    private void init(
            String userName, int tenantId, Registry registry,
            RealmService realmService, String chroot) throws RegistryException {

        RegistryContext registryContext = registry.getRegistryContext();

        if (registryContext.isCacheEnabled() && registry instanceof EmbeddedRegistry) {
            this.coreRegistry = new CacheBackedRegistry(registry);
        } else {
            this.coreRegistry = registry;
        }
        this.isAPPRemoteRegistry = registry instanceof RemoteRegistry;
        this.chrootWrapper = new ChrootWrapper(chroot);
        this.callerTenantId = tenantId;
        this.tenantId = tenantId;
        this.realmService = realmService;

        // TODO : This code needs some careful thought, and fixing.
        this.userName = CarbonConstants.REGISTRY_SYSTEM_USERNAME;
        if (realmService != null) {
            try {
                this.userRealm = new RegistryRealm(realmService.getBootstrapRealm());
            } catch (Exception e) {
                String msg = "Failed in getting the bootstrap realm for the tenantId: " + tenantId
                        + ".";
                log.error(msg);
                throw new RegistryException(msg, e);
            }
        }
       
        if (tenantId != MultitenantConstants.SUPER_TENANT_ID) {
            try {
                UserRealm realm = null;
                if (realmService != null) {
                    realm = (UserRealm) realmService.getTenantUserRealm(tenantId);
                }
                if (realm == null) {
                    String msg = "Failed to obtain the user realm for tenant: " + tenantId + ".";
                    throw new RegistryException(msg);
                }
                this.userRealm = new RegistryRealm(realm);
            } catch (UserStoreException e) {
                String msg = "An error occurred while obtaining the user realm for the tenant: " +
                        tenantId + ".";
                log.error(msg);
                throw new RegistryException(msg, e);
            }
        }
       

        // this is to get a system registry
        try {
            setSessionInformation();
            // The root must be setup, in case the remote registry does not have it.
            if (registryContext.isClone()) {
                try {
                    addRootCollection();
                } catch (Exception ignored) {
                    // There can be situations where the remote instance doesn't like creating the
                    // root collection, if it is already there. Hence, we can simply ignore this.
                }
            } else {
                addRootCollection();
            }
            if (!registryContext.isClone()) {
                addSystemCollections();
            }
        } finally {
            clearSessionInformation();
        }
View Full Code Here

Examples of org.wso2.carbon.registry.core.config.RegistryContext

            return;
        }
        if (log.isTraceEnabled()) {
            log.trace("adding system collections.");
        }
        RegistryContext registryContext = coreRegistry.getRegistryContext();

        try {
            setSessionInformation();

            // Adding base collection structure.
            RegistryUtils.addBaseCollectionStructure(coreRegistry, this.userRealm);

            // Adding collection to store user profile information.
            RegistryUtils.addUserProfileCollection(this.coreRegistry, RegistryUtils.getAbsolutePath(
                    registryContext, registryContext.getProfilesPath()));

            // Adding collection to store services.
            RegistryUtils
                    .addServiceStoreCollection(this.coreRegistry, RegistryUtils.getAbsolutePath(
                            registryContext, registryContext.getServicePath()));

            // bootstrap configuration is created
            // RegistryUtils.addDefaultRealmConfiguration(this.coreRegistry, this.userRealm,
            // this.tenantId);
View Full Code Here

Examples of org.wso2.carbon.registry.core.config.RegistryContext

    // Creates a queue service for logging events
    private void startLogWriter(RegistryService registryService) throws RegistryException {

        Registry registry = registryService.getRegistry(
                CarbonConstants.REGISTRY_SYSTEM_USERNAME);
        RegistryContext registryContext = registry.getRegistryContext();
        if (bundleContext != null) {
            bundleContext.registerService(LogQueue.class.getName(),
                    registryContext.getLogWriter().getLogQueue(), null);
        }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.