当前位置: 首页>>代码示例>>Java>>正文


Java Resource.setContentStream方法代码示例

本文整理汇总了Java中org.wso2.carbon.registry.core.Resource.setContentStream方法的典型用法代码示例。如果您正苦于以下问题:Java Resource.setContentStream方法的具体用法?Java Resource.setContentStream怎么用?Java Resource.setContentStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.wso2.carbon.registry.core.Resource的用法示例。


在下文中一共展示了Resource.setContentStream方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setup

import org.wso2.carbon.registry.core.Resource; //导入方法依赖的package包/类
@Before
public void setup() throws RegistryException {
    userRegistry = mock(UserRegistry.class);
    Collection resultCollection = new CollectionImpl();
    resultCollection.setContent(new String[]
            {"/_system/config/repository/components/org.wso2.carbon.governance/configuration/restservice"});
    when(userRegistry.executeQuery(anyString(), (Map) anyObject())).thenReturn(resultCollection);
    Resource rxtResource = new ResourceImpl();
    rxtResource.setMediaType("application/xml");
    InputStream is = null;
    try {
        is = RxtUnboundedDataLoadUtilsTest.class.getClassLoader().getResourceAsStream("restservice.rxt");
        rxtResource.setContentStream(is);
        when(userRegistry.get("/_system/config/repository/components/org.wso2.carbon" +
                ".governance/configuration/restservice")).thenReturn(rxtResource);
    } finally {
        if (is != null) {
            try {
                is.close();
            } catch (IOException ignore) {

            }
        }
    }
}
 
开发者ID:wso2,项目名称:carbon-registry,代码行数:26,代码来源:RxtUnboundedDataLoadUtilsTest.java

示例2: testBuildSearchCriteriaSubPart

import org.wso2.carbon.registry.core.Resource; //导入方法依赖的package包/类
public void testBuildSearchCriteriaSubPart() throws Exception {

        String val = getStringFromInputStream(this.getClass().getClassLoader().getResourceAsStream("uri.rxt"));
        Resource resource = registry.newResource();
        resource.setMediaType(GovernanceConstants.GOVERNANCE_ARTIFACT_CONFIGURATION_MEDIA_TYPE);
        resource.setContentStream(this.getClass().getClassLoader().getResourceAsStream("uri.rxt"));
        registry.put("/uri", resource);
        GovernanceArtifactConfiguration governanceArtifactConfiguration =
                GovernanceUtils.getGovernanceArtifactConfiguration(val);

        GovernanceUtils.loadGovernanceArtifacts((UserRegistry) registry);

        try {
            GovernanceUtils.findGovernanceArtifacts("overview:name=(SampleURI2 OR SampleURI1)", registry,
                                                    governanceArtifactConfiguration.getMediaType());
        } catch (GovernanceException e) {
            assertEquals("Attribute Search Service not Found", e.getMessage());
            assertNull(e.getCause());
        }

    }
 
开发者ID:wso2,项目名称:carbon-governance,代码行数:22,代码来源:TestBuildSearchCriteria.java

示例3: testSearchServiceWithNoServices

import org.wso2.carbon.registry.core.Resource; //导入方法依赖的package包/类
public void testSearchServiceWithNoServices() throws Exception {
    cleanData();
    Resource resource = registry.newResource();
    resource.setMediaType(GovernanceConstants.GOVERNANCE_ARTIFACT_CONFIGURATION_MEDIA_TYPE);
    resource.setContentStream(this.getClass().getClassLoader().getResourceAsStream("service.rxt"));
    registry.put("/service", resource);

    GovernanceUtils.loadGovernanceArtifacts((UserRegistry) registry);

    ServiceManager serviceManager = new ServiceManager(registry);
    Service[] allServices = serviceManager.getAllServices();
    for (Service s : allServices) {
        System.out.println(s.getPath());
    }

    assertEquals("invalid service count received", 0, allServices.length);

    cleanData();
}
 
开发者ID:wso2,项目名称:carbon-governance,代码行数:20,代码来源:ServiceTest.java

示例4: testBuildSearchCriteria

import org.wso2.carbon.registry.core.Resource; //导入方法依赖的package包/类
public void testBuildSearchCriteria() throws Exception {

        String val = getStringFromInputStream(this.getClass().getClassLoader().getResourceAsStream("uri.rxt"));
        Resource resource = registry.newResource();
        resource.setMediaType(GovernanceConstants.GOVERNANCE_ARTIFACT_CONFIGURATION_MEDIA_TYPE);
        resource.setContentStream(this.getClass().getClassLoader().getResourceAsStream("uri.rxt"));
        registry.put("/uri", resource);
        GovernanceArtifactConfiguration governanceArtifactConfiguration =
                GovernanceUtils.getGovernanceArtifactConfiguration(val);

        GovernanceUtils.loadGovernanceArtifacts((UserRegistry) registry);

        try {
            GovernanceUtils.findGovernanceArtifacts(
                    "name=SampleURI2&version=1.2" +
                            ".3&tags=123&updater!=admin&author!=admin&mediaType!=admin&associationDest=admin&comments" +
                            "=123",
                    registry, governanceArtifactConfiguration.getMediaType());
        } catch (GovernanceException e) {
            assertEquals("Attribute Search Service not Found", e.getMessage());
            assertNull(e.getCause());
        }

    }
 
开发者ID:wso2,项目名称:carbon-governance,代码行数:25,代码来源:TestBuildSearchCriteria.java

示例5: addTask

import org.wso2.carbon.registry.core.Resource; //导入方法依赖的package包/类
@Override
public synchronized void addTask(TaskInfo taskInfo) throws TaskException {
    String tasksPath = this.getMyTasksPath();
    String currentTaskPath = tasksPath + "/" + taskInfo.getName();
    try {
        PrivilegedCarbonContext.startTenantFlow();
        PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(
                MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, true);
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        getTaskMarshaller().marshal(taskInfo, out);
        ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
        Resource resource = getRegistry().newResource();
        resource.setContentStream(in);
        getRegistry().put(currentTaskPath, resource);
    } catch (Exception e) {
        throw new TaskException("Error in adding task '" + taskInfo.getName()
                + "' to the repository: " + e.getMessage(), Code.CONFIG_ERROR, e);
    } finally {
        PrivilegedCarbonContext.endTenantFlow();
    }
}
 
开发者ID:wso2,项目名称:carbon-commons,代码行数:22,代码来源:RegistryBasedTaskRepository.java

示例6: testBuildSearchCriteriaTaxonomy

import org.wso2.carbon.registry.core.Resource; //导入方法依赖的package包/类
public void testBuildSearchCriteriaTaxonomy() throws Exception {

        String val = getStringFromInputStream(this.getClass().getClassLoader().getResourceAsStream("uri.rxt"));
        Resource resource = registry.newResource();
        resource.setMediaType(GovernanceConstants.GOVERNANCE_ARTIFACT_CONFIGURATION_MEDIA_TYPE);
        resource.setContentStream(this.getClass().getClassLoader().getResourceAsStream("uri.rxt"));
        registry.put("/uri", resource);
        GovernanceArtifactConfiguration governanceArtifactConfiguration =
                GovernanceUtils.getGovernanceArtifactConfiguration(val);

        GovernanceUtils.loadGovernanceArtifacts((UserRegistry) registry);

        try {
            GovernanceUtils.findGovernanceArtifacts("taxonomy=(SampleURI2 OR SampleURI1)", registry,
                                                    governanceArtifactConfiguration.getMediaType());
        } catch (GovernanceException e) {
            assertEquals("Attribute Search Service not Found", e.getMessage());
            assertNull(e.getCause());
        }

    }
 
开发者ID:wso2,项目名称:carbon-governance,代码行数:22,代码来源:TestBuildSearchCriteria.java

示例7: testUpdateService

import org.wso2.carbon.registry.core.Resource; //导入方法依赖的package包/类
public void testUpdateService() throws Exception {

        Resource resource = registry.newResource();
        resource.setMediaType(GovernanceConstants.GOVERNANCE_ARTIFACT_CONFIGURATION_MEDIA_TYPE);
        resource.setContentStream(this.getClass().getClassLoader().getResourceAsStream("service.rxt"));
        registry.put("/service", resource);

        GovernanceUtils.loadGovernanceArtifacts((UserRegistry) registry);
        ServiceManager serviceManager = new ServiceManager(registry);
        QName qName = new QName("Sample");
        Service service = serviceManager.newService(qName);
        service.setAttribute("overview_name", "Sample");
        service.setAttribute("overview_version", "1.0.0");
        service.setAttribute("overview_custom", "oldValue");
        serviceManager.addService(service);

        service.setAttribute("overview_custom", "newValue");
        serviceManager.updateService(service);
        service = serviceManager.getService(service.getId());

        assertEquals("newValue", service.getAttribute("overview_custom"));

        serviceManager.removeService(service.getId());
        clean();
    }
 
开发者ID:wso2,项目名称:carbon-governance,代码行数:26,代码来源:ServiceManagerTest.java

示例8: testGetAllServicePaths

import org.wso2.carbon.registry.core.Resource; //导入方法依赖的package包/类
public void testGetAllServicePaths() throws Exception {

        Resource resource = registry.newResource();
        resource.setMediaType(GovernanceConstants.GOVERNANCE_ARTIFACT_CONFIGURATION_MEDIA_TYPE);
        resource.setContentStream(this.getClass().getClassLoader().getResourceAsStream("service.rxt"));
        registry.put("/service", resource);

        GovernanceUtils.loadGovernanceArtifacts((UserRegistry) registry);
        ServiceManager serviceManager = new ServiceManager(registry);
        QName qName = new QName("Sample");
        Service service = serviceManager.newService(qName);
        service.setAttribute("overview_name", "Sample");
        service.setAttribute("overview_version", "1.0.0");
        service.setAttribute("overview_custom", "oldValue");
        serviceManager.addService(service);

        assertEquals(1, serviceManager.getAllServicePaths().length);

        serviceManager.removeService(service.getId());
        clean();
    }
 
开发者ID:wso2,项目名称:carbon-governance,代码行数:22,代码来源:ServiceManagerTest.java

示例9: testGetAllServiceIds

import org.wso2.carbon.registry.core.Resource; //导入方法依赖的package包/类
public void testGetAllServiceIds() throws Exception {

        Resource resource = registry.newResource();
        resource.setMediaType(GovernanceConstants.GOVERNANCE_ARTIFACT_CONFIGURATION_MEDIA_TYPE);
        resource.setContentStream(this.getClass().getClassLoader().getResourceAsStream("service.rxt"));
        registry.put("/service", resource);

        GovernanceUtils.loadGovernanceArtifacts((UserRegistry) registry);
        ServiceManager serviceManager = new ServiceManager(registry);
        QName qName = new QName("Sample");
        Service service = serviceManager.newService(qName);
        service.setAttribute("overview_name", "Sample");
        service.setAttribute("overview_version", "1.0.0");
        service.setAttribute("overview_custom", "oldValue");
        serviceManager.addService(service);

        Service service2 = serviceManager.newService(qName);
        service2.setAttribute("overview_name", "Sample2");
        service2.setAttribute("overview_version", "2.0.0");
        service2.setAttribute("overview_custom", "oldValue");
        serviceManager.addService(service2);

        assertEquals(2, serviceManager.getAllServiceIds().length);

        serviceManager.removeService(service.getId());
        serviceManager.removeService(service2.getId());
        clean();
    }
 
开发者ID:wso2,项目名称:carbon-governance,代码行数:29,代码来源:ServiceManagerTest.java

示例10: testServiceOperation

import org.wso2.carbon.registry.core.Resource; //导入方法依赖的package包/类
public void testServiceOperation() throws Exception {

        Resource resource = registry.newResource();
        resource.setMediaType(GovernanceConstants.GOVERNANCE_ARTIFACT_CONFIGURATION_MEDIA_TYPE);
        resource.setContentStream(this.getClass().getClassLoader().getResourceAsStream("service.rxt"));
        registry.put("/service", resource);

        GovernanceUtils.loadGovernanceArtifacts((UserRegistry) registry);
        ServiceManager serviceManager = new ServiceManager(registry);
        QName qName = new QName("Sample");
        Service service = serviceManager.newService(qName);
        service.setAttribute("overview_name", "Sample");
        service.setAttribute("overview_version", "1.0.0");
        service.setAttribute("overview_custom", "oldValue");
        serviceManager.addService(service);

        service.activate();
        assertTrue(service.isActive());
        service.deactivate();
        assertFalse(service.isActive());

        assertEquals(0, service.getAttachedEndpoints().length);
        assertEquals(0, service.getAttachedSchemas().length);

        assertEquals(1, serviceManager.getAllServiceIds().length);

        serviceManager.removeService(service.getId());
        clean();
    }
 
开发者ID:wso2,项目名称:carbon-governance,代码行数:30,代码来源:ServiceManagerTest.java

示例11: testNewService

import org.wso2.carbon.registry.core.Resource; //导入方法依赖的package包/类
public void testNewService() throws Exception {

        Resource resource = registry.newResource();
        resource.setMediaType(GovernanceConstants.GOVERNANCE_ARTIFACT_CONFIGURATION_MEDIA_TYPE);
        resource.setContentStream(this.getClass().getClassLoader().getResourceAsStream("service.rxt"));
        registry.put("/service", resource);

        GovernanceUtils.loadGovernanceArtifacts((UserRegistry) registry);
        ServiceManager serviceManager = new ServiceManager(registry);
        QName qName = new QName("Sample");
        Service service = serviceManager.newService(qName);
        assertEquals(qName, service.getQName());

        clean();
    }
 
开发者ID:wso2,项目名称:carbon-governance,代码行数:16,代码来源:ServiceManagerTest.java

示例12: testNewService1

import org.wso2.carbon.registry.core.Resource; //导入方法依赖的package包/类
public void testNewService1() throws Exception {
    Resource resource = registry.newResource();
    resource.setMediaType(GovernanceConstants.GOVERNANCE_ARTIFACT_CONFIGURATION_MEDIA_TYPE);
    resource.setContentStream(this.getClass().getClassLoader().getResourceAsStream("service.rxt"));
    registry.put("/service", resource);

    ServiceManager serviceManager = new ServiceManager(registry);
    String content =
            "<metadata xmlns=\"http://www.wso2.org/governance/metadata\"><overview><name>Sample</name><version>1" +
                    ".0.0</version><namespace>UserA</namespace></overview></metadata>";
    OMElement XMLContent = AXIOMUtil.stringToOM(content);
    serviceManager.newService(XMLContent);

    clean();
}
 
开发者ID:wso2,项目名称:carbon-governance,代码行数:16,代码来源:ServiceManagerTest.java

示例13: testNewServiceContentXMLInvalid

import org.wso2.carbon.registry.core.Resource; //导入方法依赖的package包/类
public void testNewServiceContentXMLInvalid() throws RegistryException,
                                                     XMLStreamException {
    cleanData();
    String val = GenericArtifactTest.getStringFromInputStream(
            this.getClass().getClassLoader().getResourceAsStream("service.rxt"));
    Resource resource = registry.newResource();
    resource.setMediaType(GovernanceConstants.GOVERNANCE_ARTIFACT_CONFIGURATION_MEDIA_TYPE);
    resource.setContentStream(this.getClass().getClassLoader().getResourceAsStream("service.rxt"));
    registry.put("/service", resource);

    GovernanceUtils.loadGovernanceArtifacts((UserRegistry) registry);

    ServiceManager serviceManager = new ServiceManager(registry);
    String content =
            "<metadata xmlns=\"http://www.wso2" +
                    ".org/governance/metadata\"><overview><namespace>UserA</namespace></overview></metadata>";
    OMElement XMLContent = AXIOMUtil.stringToOM(content);
    try {
        serviceManager.newService(XMLContent);
    } catch (GovernanceException e) {
        assertEquals("Unable to compute QName from given XML payload, " +
                             "please ensure that the content passed in matches the configuration.",
                     e.getMessage());
        cleanData();
        return;
    }
    cleanData();
    fail("An exception was expected to be thrown, but did not.");
}
 
开发者ID:wso2,项目名称:carbon-governance,代码行数:30,代码来源:ServiceTest.java

示例14: loadSecurityScenarios

import org.wso2.carbon.registry.core.Resource; //导入方法依赖的package包/类
private void loadSecurityScenarios(Registry registry,
                                   BundleContext bundleContext) throws CarbonException, IOException, RegistryException {

    // TODO: Load into all tenant DBs
    // Load security scenarios
    URL resource = bundleContext.getBundle().getResource("/scenarios/scenario-config.xml");
    if (resource != null) {
        XmlConfiguration xmlConfiguration = new XmlConfiguration(resource.openStream(),
                SecurityConstants.SECURITY_NAMESPACE);

        OMElement[] elements = xmlConfiguration.getElements("//ns:Scenario");
        try {
            boolean transactionStarted = Transaction.isStarted();
            if (!transactionStarted) {
                registry.beginTransaction();
            }

            for (OMElement scenarioEle : elements) {
                SecurityScenario scenario = new SecurityScenario();
                String scenarioId = scenarioEle.getAttribute(SecurityConstants.ID_QN)
                        .getAttributeValue();

                scenario.setScenarioId(scenarioId);
                scenario.setSummary(scenarioEle.getFirstChildWithName(SecurityConstants.SUMMARY_QN)
                        .getText());
                scenario.setDescription(scenarioEle.getFirstChildWithName(
                        SecurityConstants.DESCRIPTION_QN).getText());
                scenario.setCategory(scenarioEle.getFirstChildWithName(SecurityConstants.CATEGORY_QN)
                        .getText());
                scenario.setWsuId(scenarioEle.getFirstChildWithName(SecurityConstants.WSUID_QN)
                        .getText());
                scenario.setType(scenarioEle.getFirstChildWithName(SecurityConstants.TYPE_QN).getText());

                String resourceUri = SecurityConstants.SECURITY_POLICY + "/" + scenarioId;

                for (Iterator modules = scenarioEle.getFirstChildWithName(SecurityConstants.MODULES_QN)
                        .getChildElements(); modules.hasNext(); ) {
                    String module = ((OMElement) modules.next()).getText();
                    scenario.addModule(module);
                }

                // Save it in the DB
                SecurityScenarioDatabase.put(scenarioId, scenario);

                // Store the scenario in the Registry
                if (!scenarioId.equals(SecurityConstants.SCENARIO_DISABLE_SECURITY) &&
                        !scenarioId.equals(SecurityConstants.POLICY_FROM_REG_SCENARIO)) {
                    Resource scenarioResource = new ResourceImpl();
                    scenarioResource.
                            setContentStream(bundleContext.getBundle().
                                    getResource("scenarios/" + scenarioId + "-policy.xml").openStream());
                    scenarioResource.setMediaType("application/policy+xml");
                    if (!registry.resourceExists(resourceUri)) {
                        registry.put(resourceUri, scenarioResource);
                    }

                    // Cache the resource in-memory in order to add it to the newly created tenants
                    SecurityServiceHolder.addPolicyResource(resourceUri, scenarioResource);
                }
            }
            if (!transactionStarted) {
                registry.commitTransaction();
            }
        } catch (Exception e) {
            registry.rollbackTransaction();
            throw e;
        }
    } else {
        throw new CarbonException("Can't find the resource url");
    }
}
 
开发者ID:wso2,项目名称:carbon-identity-framework,代码行数:72,代码来源:SecurityDeploymentInterceptor.java

示例15: loadSecurityScenarios

import org.wso2.carbon.registry.core.Resource; //导入方法依赖的package包/类
private void loadSecurityScenarios(Registry registry,
                                   BundleContext bundleContext) throws CarbonException, IOException, RegistryException {

    // TODO: Load into all tenant DBs
    // Load security scenarios
    URL resource = bundleContext.getBundle().getResource("/scenarios/scenario-config.xml");
    XmlConfiguration xmlConfiguration = new XmlConfiguration(resource.openStream(),
            SecurityConstants.SECURITY_NAMESPACE);

    OMElement[] elements = xmlConfiguration.getElements("//ns:Scenario");
    try {
        boolean transactionStarted = Transaction.isStarted();
        if (!transactionStarted) {
            registry.beginTransaction();
        }

        for (OMElement scenarioEle : elements) {
            SecurityScenario scenario = new SecurityScenario();
            String scenarioId = scenarioEle.getAttribute(SecurityConstants.ID_QN)
                    .getAttributeValue();

            scenario.setScenarioId(scenarioId);
            scenario.setSummary(scenarioEle.getFirstChildWithName(SecurityConstants.SUMMARY_QN)
                    .getText());
            scenario.setDescription(scenarioEle.getFirstChildWithName(
                    SecurityConstants.DESCRIPTION_QN).getText());
            scenario.setCategory(scenarioEle.getFirstChildWithName(SecurityConstants.CATEGORY_QN)
                    .getText());
            scenario.setWsuId(scenarioEle.getFirstChildWithName(SecurityConstants.WSUID_QN)
                    .getText());
            scenario.setType(scenarioEle.getFirstChildWithName(SecurityConstants.TYPE_QN).getText());

            String resourceUri = SecurityConstants.SECURITY_POLICY + "/" + scenarioId;

            for (Iterator modules = scenarioEle.getFirstChildWithName(SecurityConstants.MODULES_QN)
                    .getChildElements(); modules.hasNext(); ) {
                String module = ((OMElement) modules.next()).getText();
                scenario.addModule(module);
            }

            // Save it in the DB
            SecurityScenarioDatabase.put(scenarioId, scenario);

            // Store the scenario in the Registry
            if (!scenarioId.equals(SecurityConstants.SCENARIO_DISABLE_SECURITY) &&
                    !scenarioId.equals(SecurityConstants.POLICY_FROM_REG_SCENARIO)) {
                Resource scenarioResource = new ResourceImpl();
                scenarioResource.
                        setContentStream(bundleContext.getBundle().
                                getResource("scenarios/" + scenarioId + "-policy.xml").openStream());
                scenarioResource.setMediaType("application/policy+xml");
                if (!registry.resourceExists(resourceUri)) {
                    registry.put(resourceUri, scenarioResource);
                }

                // Cache the resource in-memory in order to add it to the newly created tenants
                SecurityServiceHolder.addPolicyResource(resourceUri, scenarioResource);
            }
        }
        if (!transactionStarted) {
            registry.commitTransaction();
        }
    } catch (Exception e) {
        registry.rollbackTransaction();
        throw e;
    }
}
 
开发者ID:wso2-attic,项目名称:carbon-identity,代码行数:68,代码来源:SecurityDeploymentInterceptor.java


注:本文中的org.wso2.carbon.registry.core.Resource.setContentStream方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。