Java Code Examples for org.wso2.carbon.registry.core.Resource#setContentStream()

The following examples show how to use org.wso2.carbon.registry.core.Resource#setContentStream() . 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: AbstractAPIManager.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
public String addResourceFile(Identifier identifier, String resourcePath, ResourceFile resourceFile) throws APIManagementException {
    try {
        Resource thumb = registry.newResource();
        thumb.setContentStream(resourceFile.getContent());
        thumb.setMediaType(resourceFile.getContentType());
        registry.put(resourcePath, thumb);
        if (MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equalsIgnoreCase(tenantDomain)) {
            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) {
        String msg = "Error while adding the resource to the registry";
        throw new APIManagementException(msg, e);
    }
}
 
Example 2
Source File: TenantWorkflowConfigHolderTest.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
@Test
public void testLoadingDefaultTenantWorkflowConfig() throws FileNotFoundException, XMLStreamException,
        RegistryException {
    TenantWorkflowConfigHolder tenantWorkflowConfigHolder = new TenantWorkflowConfigHolder(tenantDomain, tenantID);
    File defaultWFConfigFile = new File(Thread.currentThread().getContextClassLoader().
            getResource("workflow-configs/default-workflow-extensions.xml").getFile());
    InputStream defaultWFConfigContent = new FileInputStream(defaultWFConfigFile);
    Resource defaultWFConfigResource = new ResourceImpl();
    defaultWFConfigResource.setContentStream(defaultWFConfigContent);
    Mockito.when(registry.get(APIConstants.WORKFLOW_EXECUTOR_LOCATION)).thenReturn(defaultWFConfigResource);
    try {
        tenantWorkflowConfigHolder.load();
        Assert.assertNotNull(tenantWorkflowConfigHolder.getWorkflowExecutor("AM_APPLICATION_CREATION"));
        Assert.assertNotNull(tenantWorkflowConfigHolder.getWorkflowExecutor
                ("AM_APPLICATION_REGISTRATION_PRODUCTION"));
        Assert.assertNotNull(tenantWorkflowConfigHolder.getWorkflowExecutor
                ("AM_APPLICATION_REGISTRATION_SANDBOX"));
        Assert.assertNotNull(tenantWorkflowConfigHolder.getWorkflowExecutor("AM_USER_SIGNUP"));
        Assert.assertNotNull(tenantWorkflowConfigHolder.getWorkflowExecutor("AM_SUBSCRIPTION_CREATION"));
        Assert.assertNotNull(tenantWorkflowConfigHolder.getWorkflowExecutor("AM_SUBSCRIPTION_DELETION"));
        Assert.assertNotNull(tenantWorkflowConfigHolder.getWorkflowExecutor("AM_API_STATE"));

    } catch (WorkflowException e) {
        Assert.fail("Unexpected WorkflowException occurred while loading default tenant workflow configuration");
    }
}
 
Example 3
Source File: TenantWorkflowConfigHolderTest.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
@Test
public void testLoadingExtendedTenantWorkflowConfig() throws FileNotFoundException, XMLStreamException,
        RegistryException {
    TenantWorkflowConfigHolder tenantWorkflowConfigHolder = new TenantWorkflowConfigHolder(tenantDomain, tenantID);
    File defaultWFConfigFile = new File(Thread.currentThread().getContextClassLoader().
            getResource("workflow-configs/workflow-extensions.xml").getFile());
    InputStream defaultWFConfigContent = new FileInputStream(defaultWFConfigFile);
    Resource defaultWFConfigResource = new ResourceImpl();
    defaultWFConfigResource.setContentStream(defaultWFConfigContent);
    Mockito.when(registry.get(APIConstants.WORKFLOW_EXECUTOR_LOCATION)).thenReturn(defaultWFConfigResource);
    try {
        tenantWorkflowConfigHolder.load();
        Assert.assertNotNull(tenantWorkflowConfigHolder.getWorkflowExecutor("AM_APPLICATION_CREATION"));
        Assert.assertNotNull(tenantWorkflowConfigHolder.getWorkflowExecutor
                ("AM_APPLICATION_REGISTRATION_PRODUCTION"));
        Assert.assertNotNull(tenantWorkflowConfigHolder.getWorkflowExecutor
                ("AM_APPLICATION_REGISTRATION_SANDBOX"));
        Assert.assertNotNull(tenantWorkflowConfigHolder.getWorkflowExecutor("AM_USER_SIGNUP"));
        Assert.assertNotNull(tenantWorkflowConfigHolder.getWorkflowExecutor("AM_SUBSCRIPTION_CREATION"));
        Assert.assertNotNull(tenantWorkflowConfigHolder.getWorkflowExecutor("AM_SUBSCRIPTION_DELETION"));
        Assert.assertNotNull(tenantWorkflowConfigHolder.getWorkflowExecutor("AM_API_STATE"));
    } catch (WorkflowException e) {
        Assert.fail("Unexpected WorkflowException occurred while loading extended tenant workflow configuration");
    }
}
 
Example 4
Source File: TenantWorkflowConfigHolderTest.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
@Test
public void testFailureToLoadTenantWFConfigWhenWFExecutorClassNotFound() throws Exception {
    //Workflow executor is an non existing class so that ClassNotFoundException will be thrown
    String invalidWFExecutor =
            "<WorkFlowExtensions>\n" +
                    "    <ApplicationCreation executor=\"org.wso2.carbon.apimgt.impl.workflow" +
                    ".TestExecutor\"/></WorkFlowExtensions>";
    InputStream invalidInputStream = new ByteArrayInputStream(invalidWFExecutor.getBytes("UTF-8"));
    TenantWorkflowConfigHolder tenantWorkflowConfigHolder = new TenantWorkflowConfigHolder(tenantDomain, tenantID);
    Resource defaultWFConfigResource = new ResourceImpl();
    defaultWFConfigResource.setContentStream(invalidInputStream);
    Mockito.when(registry.get(APIConstants.WORKFLOW_EXECUTOR_LOCATION)).thenReturn(defaultWFConfigResource);
    try {
        tenantWorkflowConfigHolder.load();
        Assert.fail("Expected WorkflowException has not been thrown when workflow executor class not found");
    } catch (WorkflowException e) {
        Assert.assertEquals(e.getMessage(), "Unable to find class");
    }
}
 
Example 5
Source File: TenantWorkflowConfigHolderTest.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
@Test
public void testFailureToLoadTenantWFConfigWhenWFExecutorClassCannotBeInstantiated() throws Exception {
    //Workflow executor is an abstract class so that InstantiationException will be thrown
    String invalidWFExecutor =
                    "<WorkFlowExtensions>\n" +
                    "    <ApplicationCreation executor=\"org.wso2.carbon.apimgt.impl.workflow" +
                    ".WorkflowExecutor\"/></WorkFlowExtensions>";
    InputStream invalidInputStream = new ByteArrayInputStream(invalidWFExecutor.getBytes("UTF-8"));
    TenantWorkflowConfigHolder tenantWorkflowConfigHolder = new TenantWorkflowConfigHolder(tenantDomain, tenantID);
    Resource defaultWFConfigResource = new ResourceImpl();
    defaultWFConfigResource.setContentStream(invalidInputStream);
    Mockito.when(registry.get(APIConstants.WORKFLOW_EXECUTOR_LOCATION)).thenReturn(defaultWFConfigResource);
    try {
        tenantWorkflowConfigHolder.load();
        Assert.fail("Expected WorkflowException has not been thrown when workflow executor class cannot be " +
                "instantiate");
    } catch (WorkflowException e) {
        Assert.assertEquals(e.getMessage(), "Unable to instantiate class");
    }
}
 
Example 6
Source File: TenantWorkflowConfigHolderTest.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
@Test
public void testFailureToLoadTenantWFConfigWhenWFExecutorClassCannotAccessible() throws Exception {
    //Workflow executor class is a singleton class with private constructor, so that IllegalAccessException will
    // be thrown while instantiation
    String invalidWFExecutor =
            "<WorkFlowExtensions>\n" +
                    "    <ApplicationCreation executor=\"org.wso2.carbon.apimgt.impl.workflow" +
                    ".InvalidWorkFlowExecutor1\"/></WorkFlowExtensions>";
    InputStream invalidInputStream = new ByteArrayInputStream(invalidWFExecutor.getBytes("UTF-8"));
    TenantWorkflowConfigHolder tenantWorkflowConfigHolder = new TenantWorkflowConfigHolder(tenantDomain, tenantID);
    Resource defaultWFConfigResource = new ResourceImpl();
    defaultWFConfigResource.setContentStream(invalidInputStream);
    Mockito.when(registry.get(APIConstants.WORKFLOW_EXECUTOR_LOCATION)).thenReturn(defaultWFConfigResource);
    try {
        tenantWorkflowConfigHolder.load();
        Assert.fail("Expected WorkflowException has not been thrown when workflow executor class cannot be " +
                "accessible");
    } catch (WorkflowException e) {
        Assert.assertEquals(e.getMessage(), "Illegal attempt to invoke class methods");
    }
}
 
Example 7
Source File: TenantWorkflowConfigHolderTest.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
@Test
public void testFailureToLoadTenantWFConfigWhenWFExecutorPropertyNameNotFound() throws Exception {
    //Workflow executor class is a singleton class with private constructor, so that IllegalAccessException will
    // be thrown while instantiation
    String invalidWFExecutor =
            "<WorkFlowExtensions>\n" +
                    "     <ApplicationCreation executor=\"org.wso2.carbon.apimgt.impl.workflow" +
                    ".ApplicationCreationWSWorkflowExecutor\">\n" +
                    "         <Property/>\n" +
                    "    </ApplicationCreation>\n" +
                    "</WorkFlowExtensions>\n";
    InputStream invalidInputStream = new ByteArrayInputStream(invalidWFExecutor.getBytes("UTF-8"));
    TenantWorkflowConfigHolder tenantWorkflowConfigHolder = new TenantWorkflowConfigHolder(tenantDomain, tenantID);
    Resource defaultWFConfigResource = new ResourceImpl();
    defaultWFConfigResource.setContentStream(invalidInputStream);
    Mockito.when(registry.get(APIConstants.WORKFLOW_EXECUTOR_LOCATION)).thenReturn(defaultWFConfigResource);
    try {
        tenantWorkflowConfigHolder.load();
        Assert.fail("Expected WorkflowException has not been thrown when workflow executor property 'name' " +
                "attribute not found");
    } catch (WorkflowException e) {
        Assert.assertEquals(e.getMessage(), "Unable to load workflow executor class");
    }
}
 
Example 8
Source File: TenantWorkflowConfigHolderTest.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
@Test
public void testFailureToLoadTenantWFConfigWhenWFExecutorPropertySetterNotDefined() throws Exception {
    //Workflow executor class does not have setter method for 'testParam'
    String invalidWFExecutor =
            "<WorkFlowExtensions>\n" +
                    "     <ApplicationCreation executor=\"org.wso2.carbon.apimgt.impl.workflow" +
                    ".ApplicationCreationWSWorkflowExecutor\">\n" +
                    "         <Property name=\"testParam\">test</Property>\n" +
                    "    </ApplicationCreation>\n" +
                    "</WorkFlowExtensions>\n";
    InputStream invalidInputStream = new ByteArrayInputStream(invalidWFExecutor.getBytes("UTF-8"));
    TenantWorkflowConfigHolder tenantWorkflowConfigHolder = new TenantWorkflowConfigHolder(tenantDomain, tenantID);
    Resource defaultWFConfigResource = new ResourceImpl();
    defaultWFConfigResource.setContentStream(invalidInputStream);
    Mockito.when(registry.get(APIConstants.WORKFLOW_EXECUTOR_LOCATION)).thenReturn(defaultWFConfigResource);
    try {
        tenantWorkflowConfigHolder.load();
        Assert.fail("Expected WorkflowException has not been thrown when workflow executor property setter method" +
                " cannot be found");
    } catch (WorkflowException e) {
        Assert.assertEquals(e.getMessage(), "Unable to load workflow executor class");
        Assert.assertEquals(e.getCause().getMessage(), "Error invoking setter method named : setTestParam() " +
                "that takes a single String, int, long, float, double or boolean parameter");
    }
}
 
Example 9
Source File: TenantWorkflowConfigHolderTest.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
@Test
public void testFailureToLoadTenantWFConfigWhenWFExecutorPropertySetterInInvalid() throws Exception {
    //Workflow executor class setter method is invalid since it has multiple parameter types
    String invalidWFExecutor =
            "<WorkFlowExtensions>\n" +
                    "     <ApplicationCreation executor=\"org.wso2.carbon.apimgt.impl.workflow" +
                    ".InvalidWorkFlowExecutor2\">\n" +
                    "         <Property name=\"username\">admin</Property>\n" +
                    "    </ApplicationCreation>\n" +
                    "</WorkFlowExtensions>\n";
    InputStream invalidInputStream = new ByteArrayInputStream(invalidWFExecutor.getBytes("UTF-8"));
    TenantWorkflowConfigHolder tenantWorkflowConfigHolder = new TenantWorkflowConfigHolder(tenantDomain, tenantID);
    Resource defaultWFConfigResource = new ResourceImpl();
    defaultWFConfigResource.setContentStream(invalidInputStream);
    Mockito.when(registry.get(APIConstants.WORKFLOW_EXECUTOR_LOCATION)).thenReturn(defaultWFConfigResource);
    try {
        tenantWorkflowConfigHolder.load();
        Assert.fail("Expected WorkflowException has not been thrown when workflow executor property setter method" +
                " is invalid");
    } catch (WorkflowException e) {
        Assert.assertEquals(e.getMessage(), "Unable to load workflow executor class");
        Assert.assertEquals(e.getCause().getMessage(), "Error invoking setter method named : setUsername() " +
                "that takes a single String, int, long, float, double or boolean parameter");
    }
}
 
Example 10
Source File: RegistryBasedTaskRepository.java    From carbon-commons with Apache License 2.0 6 votes vote down vote up
@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();
    }
}
 
Example 11
Source File: IdentitySTSMgtServiceComponent.java    From carbon-identity with Apache License 2.0 4 votes vote down vote up
/**
 * This method is used to load custom security scenarios used inside Identity STS componsnts.
 *
 * @throws Exception
 */
private void loadSecurityScenarios() throws Exception {

    Registry registry = registryService.getConfigSystemRegistry();

    try {
        // Scenarios are listed in resources/scenario-config.xml
        URL resource = bundleContext.getBundle().getResource("scenario-config.xml");
        XmlConfiguration xmlConfiguration = new XmlConfiguration(resource.openStream(),
                                                                 SecurityConstants.SECURITY_NAMESPACE);

        OMElement[] elements = xmlConfiguration.getElements("//ns:Scenario");

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

            OMElement genPolicyElem = scenarioEle.getFirstChildWithName(SecurityConstants.IS_GEN_POLICY_QN);
            if (genPolicyElem != null && "false".equals(genPolicyElem.getText())) {
                scenario.setGeneralPolicy(false);
            }

            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(scenarioId + "-policy.xml").openStream());
                if (!registry.resourceExists(resourceUri)) {
                    registry.put(resourceUri, scenarioResource);
                }
            }

        }
        if (!transactionStarted) {
            registry.commitTransaction();
        }
    } catch (Exception e) {
        registry.rollbackTransaction();
        throw e;
    }
}
 
Example 12
Source File: SecurityDeploymentInterceptor.java    From carbon-identity with Apache License 2.0 4 votes vote down vote up
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;
    }
}
 
Example 13
Source File: TenantWorkflowConfigHolderTest.java    From carbon-apimgt with Apache License 2.0 4 votes vote down vote up
@Test
public void testFailureToLoadTenantWFConfigWhenWFExecutorHasMultipleParamTypes() throws Exception {
    //Workflow executor class setter methods are available for different parameter types
    String invalidWFExecutor =
            "<WorkFlowExtensions>\n" +
                    "     <ApplicationCreation executor=\"org.wso2.carbon.apimgt.impl.workflow" +
                    ".WorkflowExecutorWithMultipleParamTypes\">\n" +
                    "         <Property name=\"stringParam\">admin</Property>\n" +
                    "         <Property name=\"intParam\">1</Property>\n" +
                    "         <Property name=\"booleanParam\">true</Property>\n" +
                    "         <Property name=\"longParam\">10000000</Property>\n" +
                    "         <Property name=\"doubleParam\">10.1000000000</Property>\n" +
                    "         <Property name=\"floatParam\">10.1</Property>\n" +
                    "         <Property name=\"omElement\">" +
                    "            <omElement>test</omElement>" +
                    "         </Property>\n" +
                    "    </ApplicationCreation>\n" +
                    "    <ProductionApplicationRegistration executor=\"org.wso2.carbon.apimgt.impl.workflow" +
                    ".ApplicationRegistrationSimpleWorkflowExecutor\"/>" +
                    "    <SandboxApplicationRegistration executor=\"org.wso2.carbon.apimgt.impl.workflow" +
                    ".ApplicationRegistrationSimpleWorkflowExecutor\"/>\n" +
                    "    <SubscriptionCreation executor=\"org.wso2.carbon.apimgt.impl.workflow" +
                    ".SubscriptionCreationSimpleWorkflowExecutor\"/>\n"+
                    "   <SubscriptionUpdate executor=\"org.wso2.carbon.apimgt.impl.workflow" +
                    ".SubscriptionUpdateSimpleWorkflowExecutor\"/>\n"+
                    "    <UserSignUp executor=\"org.wso2.carbon.apimgt.impl.workflow" +
                    ".UserSignUpSimpleWorkflowExecutor\"/>\n"+
                    "    <SubscriptionDeletion executor=\"org.wso2.carbon.apimgt.impl.workflow" +
                    ".SubscriptionDeletionSimpleWorkflowExecutor\"/>\n"+
                    "    <ApplicationDeletion executor=\"org.wso2.carbon.apimgt.impl.workflow" +
                    ".ApplicationDeletionSimpleWorkflowExecutor\"/>\n"+
                    "</WorkFlowExtensions>\n";
    InputStream invalidInputStream = new ByteArrayInputStream(invalidWFExecutor.getBytes("UTF-8"));
    TenantWorkflowConfigHolder tenantWorkflowConfigHolder = new TenantWorkflowConfigHolder(tenantDomain, tenantID);
    Resource defaultWFConfigResource = new ResourceImpl();
    defaultWFConfigResource.setContentStream(invalidInputStream);
    Mockito.when(registry.get(APIConstants.WORKFLOW_EXECUTOR_LOCATION)).thenReturn(defaultWFConfigResource);
    try {
        tenantWorkflowConfigHolder.load();
        Assert.assertNotNull(tenantWorkflowConfigHolder.getWorkflowExecutor("AM_APPLICATION_CREATION"));
    } catch (WorkflowException e) {
        Assert.fail("Unexpected WorkflowException has been thrown while loading workflow executor for different " +
                "param types");
    }
}
 
Example 14
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);
    }

}