Search in sources :

Example 71 with Resource

use of org.wso2.carbon.registry.api.Resource in project carbon-business-process by wso2.

the class TenantProcessStoreImpl method findBPELPackageInFileSystem.

private File findBPELPackageInFileSystem(DeploymentUnitDAO dudao) {
    String duName = dudao.getName();
    // Done: Fix the logic to handle registry
    log.info("Looking for BPEL package in file system for deployment unit " + duName);
    File bpelDUDirectory = new File(bpelDURepo, duName);
    if (bpelDUDirectory.exists()) {
        return bpelDUDirectory;
    } else {
        String registryCollectionPath = dudao.getDeploymentUnitDir();
        try {
            if (tenantConfigRegistry.resourceExists(registryCollectionPath)) {
                if (!bpelDUDirectory.exists() && !bpelDUDirectory.mkdirs()) {
                    String errMsg = "Error creating BPEL deployment unit repository for " + "tenant " + tenantId;
                    log.error(errMsg);
                    log.error("Failed to load BPEL deployment unit " + duName + " due to above error.");
                    throw new BPELDeploymentException(errMsg);
                }
                boolean deployedOnCarbon310 = false;
                // Check whether the registry repo is of type carbon 3.1.0
                if (tenantConfigRegistry.resourceExists(registryCollectionPath + RegistryConstants.PATH_SEPARATOR + duName)) {
                    registryCollectionPath += RegistryConstants.PATH_SEPARATOR + duName;
                    deployedOnCarbon310 = true;
                    if (log.isDebugEnabled()) {
                        log.debug("Found a carbon 3.1.0 compatible deployment unit at " + registryCollectionPath);
                    }
                }
                RegistryClientUtils.exportFromRegistry(bpelDUDirectory, registryCollectionPath, tenantConfigRegistry);
                if (deployedOnCarbon310) {
                    if (log.isDebugEnabled()) {
                        log.debug("Recompiling the carbon 3.1.0 compatible deployment unit at " + bpelDUDirectory);
                    }
                    // Re-compiling to get rid of binary compatibility issues.
                    DeploymentUnitDir du = new DeploymentUnitDir(bpelDUDirectory);
                    for (File file : du.allFiles()) {
                        if (file.getAbsolutePath().endsWith(".cbp") && !file.delete()) {
                            log.warn("Unable to delete " + file);
                        }
                    }
                    du.compile();
                }
                return bpelDUDirectory;
            } else {
                String errMsg = "Expected resource: " + registryCollectionPath + " not found in the registry";
                log.error(errMsg);
                throw new BPELDeploymentException(errMsg);
            }
        } catch (RegistryException re) {
            String errMsg = "Error while exporting deployment unit: " + duName + " to file system from the registry.";
            log.error(errMsg, re);
            throw new BPELDeploymentException(errMsg, re);
        }
    }
}
Also used : DeploymentUnitDir(org.apache.ode.store.DeploymentUnitDir) File(java.io.File) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException)

Example 72 with Resource

use of org.wso2.carbon.registry.api.Resource in project carbon-business-process by wso2.

the class EndpointConfiguration method loadUEPOMFromRegistry.

private OMElement loadUEPOMFromRegistry(Registry registry, String location) throws AxisFault {
    OMElement uepOMElement = null;
    try {
        if (registry.resourceExists(location)) {
            Resource resource = registry.get(location);
            String resourceContent = new String((byte[]) resource.getContent());
            uepOMElement = new StAXOMBuilder(new ByteArrayInputStream(resourceContent.getBytes())).getDocumentElement();
        } else {
            String errMsg = "The resource: " + location + " does not exist.";
            handleError(errMsg);
        }
    } catch (org.wso2.carbon.registry.api.RegistryException e) {
        String errMsg = "Error occurred while reading the resource from registry: " + location + " to build the Unified End Point: " + location;
        handleError(errMsg, e);
    } catch (XMLStreamException e) {
        String errMsg = "Error occurred while creating the OMElement out of Unified End Point " + "profile: " + location;
        handleError(errMsg, e);
    }
    return uepOMElement;
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) ByteArrayInputStream(java.io.ByteArrayInputStream) Resource(org.wso2.carbon.registry.api.Resource) OMElement(org.apache.axiom.om.OMElement) StAXOMBuilder(org.apache.axiom.om.impl.builder.StAXOMBuilder)

Example 73 with Resource

use of org.wso2.carbon.registry.api.Resource in project carbon-business-process by wso2.

the class AnalyticsServerProfileBuilder method loadAnalyticsProfileFromRegistry.

/**
 * Load Analytics profile from given registry and registry path.
 *
 * @param analyticsServerProfile AnalyticsServerProfile instance
 * @param registry               Registry space where file is located
 * @param location               Registry path of the profile file
 */
private void loadAnalyticsProfileFromRegistry(AnalyticsServerProfile analyticsServerProfile, Registry registry, String location) {
    try {
        if (registry.resourceExists(location)) {
            Resource resource = registry.get(location);
            String resourceContent = new String((byte[]) resource.getContent());
            parseAnalyticsProfile(resourceContent, analyticsServerProfile);
        } else {
            String errMsg = "The resource: " + location + " does not exist.";
            handleError(errMsg);
        }
    } catch (RegistryException e) {
        String errMsg = "Error occurred while reading the resource from registry: " + location + " to build the Analytics server profile: " + profileLocation;
        handleError(errMsg, e);
    }
}
Also used : Resource(org.wso2.carbon.registry.api.Resource) RegistryException(org.wso2.carbon.registry.api.RegistryException)

Example 74 with Resource

use of org.wso2.carbon.registry.api.Resource in project carbon-business-process by wso2.

the class HumanTaskPackageRepository method addLatestArchiveToRegistryCollection.

/**
 * Add latest human task package zip to the registry
 *
 * @param humanTaskDeploymentUnit
 * @param humanTaskFile
 * @throws HumanTaskStoreException
 * @throws RegistryException
 */
private void addLatestArchiveToRegistryCollection(HumanTaskDeploymentUnit humanTaskDeploymentUnit, File humanTaskFile) throws HumanTaskStoreException, RegistryException {
    FileInputStream fileInputStream = null;
    try {
        Resource latestHumanTaskArchive = configRegistry.newResource();
        fileInputStream = new FileInputStream(humanTaskFile);
        latestHumanTaskArchive.setContent(fileInputStream);
        configRegistry.put(HumanTaskPackageRepositoryUtils.getHumanTaskPackageArchiveResourcePath(humanTaskDeploymentUnit.getPackageName()), latestHumanTaskArchive);
    } catch (FileNotFoundException ex) {
        String errMsg = "HumanTask package zip file couldn't found on given location " + humanTaskFile.getAbsolutePath();
        throw new HumanTaskStoreException(errMsg, ex);
    } catch (RegistryException ex) {
        String errMsg = "Exception occurred while adding latest archive to registry collection";
        throw new RegistryException(errMsg, ex);
    } finally {
        if (fileInputStream != null) {
            try {
                fileInputStream.close();
            } catch (IOException e) {
                log.warn("Cannot close file input stream.", e);
            }
        }
    }
}
Also used : HumanTaskStoreException(org.wso2.carbon.humantask.core.store.HumanTaskStoreException) Resource(org.wso2.carbon.registry.core.Resource) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException) FileInputStream(java.io.FileInputStream)

Example 75 with Resource

use of org.wso2.carbon.registry.api.Resource in project carbon-business-process by wso2.

the class HumanTaskPackageRepository method addLatestArchiveToRegistryCollection.

/**
 * Add latest human task package zip to the registry
 *
 * @param deploymentUnitDAO
 * @param humanTaskFile
 * @throws RegistryException
 * @throws HumanTaskStoreException
 */
private void addLatestArchiveToRegistryCollection(DeploymentUnitDAO deploymentUnitDAO, File humanTaskFile) throws HumanTaskStoreException, RegistryException {
    FileInputStream fileInputStream = null;
    try {
        Resource latestHumanTaskArchive = configRegistry.newResource();
        fileInputStream = new FileInputStream(humanTaskFile);
        latestHumanTaskArchive.setContent(fileInputStream);
        configRegistry.put(HumanTaskPackageRepositoryUtils.getHumanTaskPackageArchiveResourcePath(deploymentUnitDAO.getPackageName()), latestHumanTaskArchive);
    } catch (FileNotFoundException ex) {
        String errMsg = "HumanTask package zip file couldn't found on given location " + humanTaskFile.getAbsolutePath();
        throw new HumanTaskStoreException(errMsg, ex);
    } catch (RegistryException ex) {
        String errMsg = "Exception occurred while adding latest archive to registry collection";
        throw new RegistryException(errMsg, ex);
    } finally {
        if (fileInputStream != null) {
            try {
                fileInputStream.close();
            } catch (IOException e) {
                log.warn("Cannot close file input stream.", e);
            }
        }
    }
}
Also used : HumanTaskStoreException(org.wso2.carbon.humantask.core.store.HumanTaskStoreException) Resource(org.wso2.carbon.registry.core.Resource) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException) FileInputStream(java.io.FileInputStream)

Aggregations

APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)111 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)102 HashMap (java.util.HashMap)91 Test (org.testng.annotations.Test)64 HTTPCarbonMessage (org.wso2.transport.http.netty.message.HTTPCarbonMessage)59 HTTPTestRequest (org.ballerinalang.test.services.testutils.HTTPTestRequest)56 HttpMessageDataStreamer (org.wso2.transport.http.netty.message.HttpMessageDataStreamer)53 BJSON (org.ballerinalang.model.values.BJSON)46 APIPublisher (org.wso2.carbon.apimgt.core.api.APIPublisher)38 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)29 BadRequestException (org.wso2.charon3.core.exceptions.BadRequestException)27 APIMgtAdminService (org.wso2.carbon.apimgt.core.api.APIMgtAdminService)24 CharonException (org.wso2.charon3.core.exceptions.CharonException)24 IOException (java.io.IOException)23 Map (java.util.Map)20 SCIMResponse (org.wso2.charon3.core.protocol.SCIMResponse)20 NotFoundException (org.wso2.charon3.core.exceptions.NotFoundException)17 SCIMResourceTypeSchema (org.wso2.charon3.core.schema.SCIMResourceTypeSchema)17 ArrayList (java.util.ArrayList)15 InternalErrorException (org.wso2.charon3.core.exceptions.InternalErrorException)15