org.wso2.carbon.registry.core.Registry.newResource()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(16.3k)|赞(0)|评价(0)|浏览(128)

本文整理了Java中org.wso2.carbon.registry.core.Registry.newResource方法的一些代码示例,展示了Registry.newResource的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Registry.newResource方法的具体详情如下:
包路径:org.wso2.carbon.registry.core.Registry
类名称:Registry
方法名:newResource

Registry.newResource介绍

暂无

代码示例

代码示例来源:origin: org.wso2.carbon.identity/org.wso2.carbon.identity.oauth

public static void initiateOIDCScopes(int tenantId) {
  try {
    Map<String, String> scopes = loadScopeConfigFile();
    Registry registry = OAuth2ServiceComponentHolder.getRegistryService().getConfigSystemRegistry(tenantId);
    if (!registry
        .resourceExists(OAuthConstants.SCOPE_RESOURCE_PATH)) {
      Resource resource = registry.newResource();
      if (scopes.size() > 0) {
        for (Map.Entry<String, String> entry : scopes.entrySet()) {
          String valueStr = entry.getValue().toString();
          resource.setProperty(entry.getKey(), valueStr);
        }
      }
      registry.put(OAuthConstants.SCOPE_RESOURCE_PATH, resource);
    }
  } catch (RegistryException e) {
    log.error("Error while creating registry collection for :" + OAuthConstants.SCOPE_RESOURCE_PATH, e);
  }
}

代码示例来源:origin: org.wso2.carbon.registry/org.wso2.carbon.registry.extensions

private void loadRegistryResources(Registry registry, File directory, String workingDir,
                    String mountPoint) throws RegistryException {
    File[] files = directory.listFiles((FileFilter) new AndFileFilter(HiddenFileFilter.VISIBLE,
        new OrFileFilter(DirectoryFileFilter.INSTANCE, FileFileFilter.FILE)));
    if (files == null) {
      return;
    }
    for (File file : files) {
      if (file.isDirectory()) {
        loadRegistryResources(registry, file, workingDir, mountPoint);
      } else {
        // convert windows paths so that it fits into the Unix-like registry path structure.
        String path = mountPoint +
            file.getAbsolutePath().substring(workingDir.length()).replace("\\", "/");
        if (!registry.resourceExists(path)) {
          registry.put(path, registry.newResource());
        }
      }
    }
  }
}

代码示例来源:origin: org.wso2.carbon.registry/org.wso2.carbon.registry.extensions

private void loadRegistryResources(Registry registry, File directory, String workingDir,
                       String mountPoint) throws RegistryException {
    File[] files = directory.listFiles((FileFilter) new AndFileFilter(HiddenFileFilter.VISIBLE,
        new OrFileFilter(DirectoryFileFilter.INSTANCE, FileFileFilter.FILE)));
    if (files == null) {
      return;
    }
    for (File file : files) {
      if (file.isDirectory()) {
        loadRegistryResources(registry, file, workingDir, mountPoint);
      } else {
        // convert windows paths so that it fits into the Unix-like registry path structure.
        String path = mountPoint +
            file.getAbsolutePath().substring(workingDir.length()).replace("\\", "/");
        if (!registry.resourceExists(path)) {
          registry.put(path, registry.newResource());
        }
      }
    }
  }
}

代码示例来源:origin: org.wso2.carbon.identity.inbound.auth.oauth2/org.wso2.carbon.identity.oauth

/***
 * Read the configuration file at server start up.
 * @param tenantId
 * @deprecated due to UI implementation.
 */
@Deprecated
public static void initTokenExpiryTimesOfSps(int tenantId) {
  try {
    Registry registry = OAuth2ServiceComponentHolder.getRegistryService().getConfigSystemRegistry(tenantId);
    if (!registry.resourceExists(OAuthConstants.TOKEN_EXPIRE_TIME_RESOURCE_PATH)) {
      Resource resource = registry.newResource();
      registry.put(OAuthConstants.TOKEN_EXPIRE_TIME_RESOURCE_PATH, resource);
    }
  } catch (RegistryException e) {
    log.error("Error while creating registry collection for :" + OAuthConstants.TOKEN_EXPIRE_TIME_RESOURCE_PATH, e);
  }
}

代码示例来源:origin: org.wso2.carbon.business-process/org.wso2.carbon.bpel

private void addLatestArchiveToRegistryCollection(BPELDeploymentContext bpelDeploymentContext)
    throws FileNotFoundException, RegistryException {
  Resource latestBPELArchive = configRegistry.newResource();
  FileInputStream stream = new FileInputStream(bpelDeploymentContext.getBpelArchive());
  latestBPELArchive.setContent(stream);
  configRegistry.put(BPELPackageRepositoryUtils.
          getBPELPackageArchiveResourcePath(bpelDeploymentContext.getBpelPackageName()),
      latestBPELArchive);
}

代码示例来源:origin: org.wso2.carbon.identity/org.wso2.carbon.security.mgt

private void persistPolicy(AxisService service, OMElement policy, String policyID) throws RegistryException {
  //Registry registryToLoad = SecurityServiceHolder.getRegistryService().getConfigSystemRegistry();
  Resource resource = registry.newResource();
  resource.setContent(policy.toString());
  String servicePath = getRegistryServicePath(service);
  String policyResourcePath = servicePath + RegistryResources.POLICIES + policyID;
  registry.put(policyResourcePath, resource);
}

代码示例来源:origin: org.wso2.carbon.identity.framework/org.wso2.carbon.security.mgt

private void persistPolicy(AxisService service, OMElement policy, String policyID) throws RegistryException {
  //Registry registryToLoad = SecurityServiceHolder.getRegistryService().getConfigSystemRegistry();
  Resource resource = registry.newResource();
  resource.setContent(policy.toString());
  String servicePath = getRegistryServicePath(service);
  String policyResourcePath = servicePath + RegistryResources.POLICIES + policyID;
  registry.put(policyResourcePath, resource);
}

代码示例来源:origin: wso2/carbon-identity-framework

private void persistPolicy(AxisService service, OMElement policy, String policyID) throws RegistryException {
  //Registry registryToLoad = SecurityServiceHolder.getRegistryService().getConfigSystemRegistry();
  Resource resource = registry.newResource();
  resource.setContent(policy.toString());
  String servicePath = getRegistryServicePath(service);
  String policyResourcePath = servicePath + RegistryResources.POLICIES + policyID;
  registry.put(policyResourcePath, resource);
}

代码示例来源:origin: org.wso2.carbon.governance/org.wso2.carbon.mashup.javascript.hostobjects.registry

public static Scriptable jsFunction_newResource(Context cx, Scriptable thisObj,
                        Object[] arguments,
                        Function funObj) throws CarbonException {
  RegistryHostObject registryHostObject = (RegistryHostObject) thisObj;
  if (arguments.length == 0) {
    if (registryHostObject.registry != null) {
      try {
        Resource resource = registryHostObject.registry.newResource();
        ResourceHostObject resourceHostobject = (ResourceHostObject) cx.newObject(
            registryHostObject, "Resource", new Object[]{resource});
        return resourceHostobject;
      } catch (RegistryException e) {
        throw new CarbonException("Error occurred while creating a new Resource.", e);
      }
    } else {
      throw new CarbonException("Registry has not initialized.");
    }
  } else {
    throw new CarbonException("newResource() Method doesn't accept arguments.");
  }
}

代码示例来源:origin: org.wso2.carbon.appmgt/org.wso2.carbon.appmgt.impl

public String addIcon(String resourcePath, Icon icon) throws AppManagementException {
  try {
    Resource thumb = registry.newResource();
    thumb.setContentStream(icon.getContent());
    thumb.setMediaType(icon.getContentType());
    registry.put(resourcePath, thumb);
    if(tenantDomain.equalsIgnoreCase(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)){
    return RegistryConstants.PATH_SEPARATOR + "registry"
        + RegistryConstants.PATH_SEPARATOR + "resource"
        + RegistryConstants.PATH_SEPARATOR + "_system"
        + RegistryConstants.PATH_SEPARATOR + "governance"
        + resourcePath;
    }
    else{
      return "/t/"+tenantDomain+ RegistryConstants.PATH_SEPARATOR + "registry"
          + RegistryConstants.PATH_SEPARATOR + "resource"
          + RegistryConstants.PATH_SEPARATOR + "_system"
          + RegistryConstants.PATH_SEPARATOR + "governance"
          + resourcePath;
    }
  } catch (RegistryException e) {
    handleException("Error while adding the icon image to the registry", e);
  }
  return null;
}

代码示例来源:origin: org.wso2.carbon.analytics/org.wso2.carbon.analytics.dashboard

public static void createRegistryResource(String url, Object content) throws RegistryException {
  int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
  Registry registry = ServiceHolder.getRegistryService().getConfigSystemRegistry(tenantId);
  Resource resource = registry.newResource();
  resource.setContent(content);
  resource.setMediaType("application/json");
  registry.put(url, resource);
}

代码示例来源:origin: org.apache.stratos/org.apache.stratos.adc.mgt

/**
*
*/
public void addDomainMappingToRegistry(String hostName, String actualHost)
    throws ADCException, RegistryException, DomainMappingExistsException {
  try {
    registry.beginTransaction();
    Resource hostResource = registry.newResource();
    hostResource.addProperty(CartridgeConstants.DomainMappingInfo.ACTUAL_HOST, actualHost);
    if (!registry.resourceExists(CartridgeConstants.DomainMappingInfo.HOSTINFO +
                      hostName)) {
      registry.put(CartridgeConstants.DomainMappingInfo.HOSTINFO + hostName,
                hostResource);
    } else {
      registry.rollbackTransaction();
      String msg = "Requested domain is already taken!";
      log.error(msg);
      throw new DomainMappingExistsException(msg, hostName);
    }
    registry.commitTransaction();
  } catch (RegistryException e) {
    registry.rollbackTransaction();
    throw e; 
  }
}

代码示例来源:origin: org.wso2.carbon.identity/org.wso2.carbon.security.mgt

private void persistTrustedService(String groupName, String serviceName, String trustedService,
                  String certAlias) throws SecurityConfigException {
  Registry registry;
  String resourcePath;
  Resource resource;
  try {
    resourcePath = RegistryResources.SERVICE_GROUPS + groupName
        + RegistryResources.SERVICES + serviceName + "/trustedServices";
    registry = getConfigSystemRegistry(); //TODO: Multitenancy
    if (registry != null) {
      if (registry.resourceExists(resourcePath)) {
        resource = registry.get(resourcePath);
      } else {
        resource = registry.newResource();
      }
      if (resource.getProperty(trustedService) != null) {
        resource.removeProperty(trustedService);
      }
      resource.addProperty(trustedService, certAlias);
      registry.put(resourcePath, resource);
    }
  } catch (Exception e) {
    log.error("Error occured while adding trusted service for STS", e);
    throw new SecurityConfigException("Error occured while adding trusted service for STS",
        e);
  }
}

代码示例来源:origin: org.wso2.carbon/org.wso2.carbon.bam.lwevent.core

public String subscribe(Subscription subscription) throws RegistryException {
  Registry registry = getRegistry();
  int topicHash = subscription.getTopicName().hashCode();
  String subscriptionPath = registryPath + topicHash;
  if (registry.resourceExists(subscriptionPath)) {
    Collection subscriptionCollection = (Collection) registry.get(subscriptionPath);
    String[] subscriptonPaths = subscriptionCollection.getChildren();
    for (String registrySubscriptionPath : subscriptonPaths) {
      Resource regSubscription = registry.get(registrySubscriptionPath);
      String eventSinkURL = regSubscription.getProperty(ServiceStatisticsPublisherConstants.EVENT_SINK_URL_PROPERTY_NAME);
      if (subscription.getEventSinkURL().equals(eventSinkURL))  {
        return regSubscription.getProperty(ServiceStatisticsPublisherConstants.UUID_PROPERTY_NAME);
      }
    }
  }
  Resource resource = registry.newResource();
  resource.setProperty(ServiceStatisticsPublisherConstants.TOPIC_REGISTRY_PROPERTY_NAME, subscription.getTopicName());
  resource.setProperty(ServiceStatisticsPublisherConstants.EVENT_SINK_URL_PROPERTY_NAME, subscription.getEventSinkURL());
  String uuid = UUID.randomUUID().toString();
  resource.setProperty(ServiceStatisticsPublisherConstants.UUID_PROPERTY_NAME, uuid);
  registry.put(constructRegistryPath(subscription.getTopicName(), uuid), resource);
  log.info("Subscription added for topic : " + subscription.getTopicName() + " for subscriber URL : " + subscription.getEventSinkURL());
  return uuid;
}

代码示例来源:origin: org.wso2.carbon.commons/org.wso2.carbon.reporting.template.core

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);
  }
}

代码示例来源:origin: org.wso2.carbon.identity/org.wso2.carbon.security.mgt

private void addKeystores() throws RegistryException {
  Registry registry = SecurityServiceHolder.getRegistryService().getGovernanceSystemRegistry();
  try {
    boolean transactionStarted = Transaction.isStarted();
    if (!transactionStarted) {
      registry.beginTransaction();
    }
    if (!registry.resourceExists(SecurityConstants.KEY_STORES)) {
      Collection kstores = registry.newCollection();
      registry.put(SecurityConstants.KEY_STORES, kstores);
      Resource primResource = registry.newResource();
      if (!registry.resourceExists(RegistryResources.SecurityManagement.PRIMARY_KEYSTORE_PHANTOM_RESOURCE)) {
        registry.put(RegistryResources.SecurityManagement.PRIMARY_KEYSTORE_PHANTOM_RESOURCE,
            primResource);
      }
    }
    if (!transactionStarted) {
      registry.commitTransaction();
    }
  } catch (Exception e) {
    registry.rollbackTransaction();
    throw e;
  }
}

代码示例来源:origin: org.wso2.carbon.identity.framework/org.wso2.carbon.security.mgt

private void addKeystores() throws RegistryException {
  Registry registry = SecurityServiceHolder.getRegistryService().getGovernanceSystemRegistry();
  try {
    boolean transactionStarted = Transaction.isStarted();
    if (!transactionStarted) {
      registry.beginTransaction();
    }
    if (!registry.resourceExists(SecurityConstants.KEY_STORES)) {
      Collection kstores = registry.newCollection();
      registry.put(SecurityConstants.KEY_STORES, kstores);
      Resource primResource = registry.newResource();
      if (!registry.resourceExists(RegistryResources.SecurityManagement.PRIMARY_KEYSTORE_PHANTOM_RESOURCE)) {
        registry.put(RegistryResources.SecurityManagement.PRIMARY_KEYSTORE_PHANTOM_RESOURCE,
            primResource);
      }
    }
    if (!transactionStarted) {
      registry.commitTransaction();
    }
  } catch (Exception e) {
    registry.rollbackTransaction();
    throw e;
  }
}

代码示例来源:origin: wso2/carbon-identity-framework

private void addKeystores() throws RegistryException {
  Registry registry = SecurityServiceHolder.getRegistryService().getGovernanceSystemRegistry();
  try {
    boolean transactionStarted = Transaction.isStarted();
    if (!transactionStarted) {
      registry.beginTransaction();
    }
    if (!registry.resourceExists(SecurityConstants.KEY_STORES)) {
      Collection kstores = registry.newCollection();
      registry.put(SecurityConstants.KEY_STORES, kstores);
      Resource primResource = registry.newResource();
      if (!registry.resourceExists(RegistryResources.SecurityManagement.PRIMARY_KEYSTORE_PHANTOM_RESOURCE)) {
        registry.put(RegistryResources.SecurityManagement.PRIMARY_KEYSTORE_PHANTOM_RESOURCE,
            primResource);
      }
    }
    if (!transactionStarted) {
      registry.commitTransaction();
    }
  } catch (Exception e) {
    registry.rollbackTransaction();
    throw e;
  }
}

代码示例来源:origin: org.wso2.carbon.governance/org.wso2.carbon.governance.registry.extensions

private void addService(OMElement service, RequestContext context)throws RegistryException {
  Resource resource = registry.newResource();
  String tempNamespace = CommonUtil.derivePathFragmentFromNamespace(
      CommonUtil.getServiceNamespace(service));
  String path = getChrootedServiceLocation(registry, context.getRegistryContext()) + tempNamespace +
      CommonUtil.getServiceName(service);
  String artifactId = UUID.randomUUID().toString();
  resource.setUUID(artifactId);
  String content = service.toString();
  resource.setContent(RegistryUtils.encodeString(content));
  resource.setMediaType(RegistryConstants.SERVICE_MEDIA_TYPE);
  // when saving the resource we are expecting to call the service media type handler, so
  // we intentionally release the lock here.
  boolean lockAlreadyAcquired = !CommonUtil.isUpdateLockAvailable();
  CommonUtil.releaseUpdateLock();
  try {
    registry.put(path, resource);
  } finally {
    if (lockAlreadyAcquired) {
      CommonUtil.acquireUpdateLock();
    }
  }
  registry.addAssociation(path, RegistryUtils.getAbsolutePath(registry.getRegistryContext(),
      CommonUtil.getDefinitionURL(service)), CommonConstants.DEPENDS);
  registry.addAssociation(RegistryUtils.getAbsolutePath(registry.getRegistryContext(),
      CommonUtil.getDefinitionURL(service)),path, CommonConstants.USED_BY);
}

代码示例来源:origin: org.wso2.carbon.appmgt/org.wso2.carbon.appmgt.impl

/**
 * Create WebApp Definition in JSON and save in the registry
 *
 * @param api WebApp
 * @throws org.wso2.carbon.apimgt.api.APIManagementException
 *          if failed to generate the content and save
 */
private void createUpdateAPIDefinition(WebApp api) throws AppManagementException {
  APIIdentifier identifier = api.getId();
  try{
    String jsonText = AppManagerUtil.createSwaggerJSONContent(api);
    String resourcePath = AppManagerUtil.getAPIDefinitionFilePath(identifier.getApiName(), identifier.getVersion());
    Resource resource = registry.newResource();
    resource.setContent(jsonText);
    resource.setMediaType("application/json");
    registry.put(resourcePath, resource);
    /*Set permissions to anonymous role */
    AppManagerUtil.setResourcePermissions(api.getId().getProviderName(), null, null, resourcePath);
  } catch (RegistryException e) {
    handleException("Error while adding WebApp Definition for " + identifier.getApiName() + "-" + identifier.getVersion(), e);
  } catch (AppManagementException e) {
    handleException("Error while adding WebApp Definition for " + identifier.getApiName() + "-" + identifier.getVersion(), e);
  }
}

相关文章