Search in sources :

Example 1 with SynapseArtifactDeploymentException

use of org.apache.synapse.deployers.SynapseArtifactDeploymentException in project wso2-synapse by wso2.

the class LibDeployerUtils method populateDependencies.

/**
 * populate Dependencies using main root artifacts.xml.. Schema for artifacts.xml is follwing
 *
 *<artifacts>
 *         <artifact name="SampleLib" package="synapse.sample" >
 *                <dependency artifact="templates1" /> +
 *                <description>sample synapse library</description> ?
 *         </artifact>
 *    </artifacts>
 *
 * @param libXmlPath
 * @return
 */
private static SynapseLibrary populateDependencies(String libXmlPath) {
    File f = new File(libXmlPath);
    if (!f.exists()) {
        throw new SynapseException("artifacts.xml file not found at : " + libXmlPath);
    }
    InputStream xmlInputStream = null;
    try {
        xmlInputStream = new FileInputStream(f);
        OMElement documentElement = new StAXOMBuilder(xmlInputStream).getDocumentElement();
        if (documentElement == null) {
            throw new SynapseArtifactDeploymentException("Document element for artifacts.xml is " + "null. Can't build " + "the synapse library configuration");
        }
        Iterator artifactItr = documentElement.getChildrenWithLocalName(LibDeployerConstants.ARTIFACT);
        SynapseLibrary mainSynLibArtifact = null;
        mainSynLibArtifact = createSynapseLibraryWithDeps(((OMElement) artifactItr.next()));
        if (mainSynLibArtifact == null) {
            throw new SynapseArtifactDeploymentException("artifacts.xml is invalid. <artifact> element" + " Not Found ");
        }
        return mainSynLibArtifact;
    } catch (FileNotFoundException e) {
        throw new SynapseArtifactDeploymentException("artifacts.xml File cannot be loaded from " + libXmlPath, e);
    } catch (XMLStreamException e) {
        throw new SynapseArtifactDeploymentException("Error while parsing the artifacts.xml file ", e);
    } finally {
        if (xmlInputStream != null) {
            try {
                xmlInputStream.close();
            } catch (IOException e) {
                log.error("Error while closing input stream.", e);
            }
        }
    }
}
Also used : SynapseException(org.apache.synapse.SynapseException) XMLStreamException(javax.xml.stream.XMLStreamException) SynapseArtifactDeploymentException(org.apache.synapse.deployers.SynapseArtifactDeploymentException) SynapseLibrary(org.apache.synapse.libraries.model.SynapseLibrary) OMElement(org.apache.axiom.om.OMElement) StAXOMBuilder(org.apache.axiom.om.impl.builder.StAXOMBuilder) ZipFile(java.util.zip.ZipFile)

Example 2 with SynapseArtifactDeploymentException

use of org.apache.synapse.deployers.SynapseArtifactDeploymentException in project wso2-synapse by wso2.

the class LibDeployerUtils method searchAndResolveDependencies.

/**
 * Deploys all artifacts under a root artifact..
 *
 * @param rootDirPath - root dir of the extracted artifact
 * @param library     - lib instance
 */
private static void searchAndResolveDependencies(String rootDirPath, SynapseLibrary library) {
    List<LibraryArtifact> libraryArtifacts = new ArrayList<LibraryArtifact>();
    File extractedDir = new File(rootDirPath);
    File[] allFiles = extractedDir.listFiles();
    if (allFiles == null) {
        return;
    }
    // search for all directories under the extracted path
    for (File artifactDirectory : allFiles) {
        if (!artifactDirectory.isDirectory()) {
            continue;
        }
        String directoryPath = artifactDirectory.getAbsolutePath();
        String artifactXmlPath = directoryPath + File.separator + LibDeployerConstants.ARTIFACT_XML;
        File f = new File(artifactXmlPath);
        // if the artifact.xml not found, ignore this dir
        if (!f.exists()) {
            continue;
        }
        LibraryArtifact artifact = null;
        InputStream xmlInputStream = null;
        try {
            xmlInputStream = new FileInputStream(f);
            artifact = buildArtifact(library, xmlInputStream, directoryPath);
        } catch (FileNotFoundException e) {
            log.warn("Error while resolving synapse lib dir :" + artifactDirectory.getName() + " artifacts.xml File cannot be loaded " + "from " + artifactXmlPath, e);
        } catch (Exception e) {
            log.warn("Error ocurred while resolving synapse lib dir :" + artifactDirectory.getName() + " for artifacts.xml path" + artifactXmlPath, e);
        } finally {
            if (xmlInputStream != null) {
                try {
                    xmlInputStream.close();
                } catch (IOException e) {
                    log.error("Error while closing input stream.", e);
                }
            }
        }
        if (artifact == null) {
            log.warn("Could not build lib artifact for path : " + directoryPath + " Synapse Library :" + library.getQName() + ". Continue searching for other lib artifacts");
            continue;
        }
        libraryArtifacts.add(artifact);
    }
    boolean isDepsResolved = library.resolveDependencies(libraryArtifacts);
    if (!isDepsResolved) {
        throw new SynapseArtifactDeploymentException("Error when resolving Dependencies for lib : " + library.toString());
    }
}
Also used : SynapseException(org.apache.synapse.SynapseException) SynapseArtifactDeploymentException(org.apache.synapse.deployers.SynapseArtifactDeploymentException) XMLStreamException(javax.xml.stream.XMLStreamException) DeploymentException(org.apache.axis2.deployment.DeploymentException) SynapseArtifactDeploymentException(org.apache.synapse.deployers.SynapseArtifactDeploymentException) LibraryArtifact(org.apache.synapse.libraries.model.LibraryArtifact) ZipFile(java.util.zip.ZipFile)

Example 3 with SynapseArtifactDeploymentException

use of org.apache.synapse.deployers.SynapseArtifactDeploymentException in project wso2-synapse by wso2.

the class LibDeployerUtils method createSynapseLibrary.

public static Library createSynapseLibrary(String libPath) {
    File libFile = new File(libPath);
    // extract
    String extractPath = LibDeployerUtils.extractSynapseLib(libFile);
    // create synapse lib metadata
    SynapseLibrary synapseLib = LibDeployerUtils.populateDependencies(extractPath + LibDeployerConstants.ARTIFACTS_XML);
    String libArtifactName = synapseLib.getQName().toString();
    Library deployedLib = SynapseConfiguration.getDeployedLib(libArtifactName);
    if (deployedLib == null) {
        // create a ClassLoader for loading this synapse lib classes/resources
        try {
            ClassLoader libLoader = Utils.getClassLoader(LibDeployerUtils.class.getClassLoader(), extractPath, false);
            synapseLib.setLibClassLoader(libLoader);
        } catch (DeploymentException e) {
            throw new SynapseArtifactDeploymentException("Error setting up lib classpath for Synapse" + " Library  : " + libFile.getAbsolutePath(), e);
        }
    } else {
        synapseLib.setLibClassLoader(deployedLib.getLibClassLoader());
    }
    // resolve synapse lib artifacts
    LibDeployerUtils.searchAndResolveDependencies(extractPath, synapseLib);
    // TODO:reslove local-entry references
    LibDeployerUtils.populateLocalEnties(synapseLib, extractPath + LibDeployerConstants.LOCAL_ENTRIES);
    synapseLib.setFileName(libFile.getAbsolutePath());
    return synapseLib;
}
Also used : SynapseArtifactDeploymentException(org.apache.synapse.deployers.SynapseArtifactDeploymentException) SynapseLibrary(org.apache.synapse.libraries.model.SynapseLibrary) SynapseArtifactDeploymentException(org.apache.synapse.deployers.SynapseArtifactDeploymentException) DeploymentException(org.apache.axis2.deployment.DeploymentException) Library(org.apache.synapse.libraries.model.Library) SynapseLibrary(org.apache.synapse.libraries.model.SynapseLibrary) ZipFile(java.util.zip.ZipFile)

Example 4 with SynapseArtifactDeploymentException

use of org.apache.synapse.deployers.SynapseArtifactDeploymentException in project wso2-synapse by wso2.

the class LibraryArtifact method loadComponentsInto.

public void loadComponentsInto(SynapseLibrary library) {
    for (String artifactName : subArtifacts.keySet()) {
        LibraryArtifact artifact = subArtifacts.get(artifactName);
        if (artifact.isLeafArtifact()) {
            delegateClassLoading(artifact, library);
            // this is where actual artifact is constructed to it's ture form
            Object template = artifact.file.build();
            if (artifact.file instanceof TemplateArtifactFile) {
                if (template instanceof TemplateMediator) {
                    TemplateMediator templateMediator = (TemplateMediator) template;
                    // make template dynamic as it is not directly available to synapse environment
                    templateMediator.setDynamic(true);
                    String templateName = templateMediator.getName();
                    library.addComponent(getQualifiedName(library.getPackage(), templateName, library.getQName().getLocalPart()), template);
                } else if (template instanceof Template) {
                    String templateName = ((Template) template).getName();
                    library.addComponent(getQualifiedName(library.getPackage(), templateName, library.getQName().getLocalPart()), template);
                } else if (template != null) {
                    library.addComponent(getQualifiedName(library.getPackage(), artifact.getName(), library.getQName().getLocalPart()), template);
                } else {
                    throw new SynapseArtifactDeploymentException("Cannot load components into " + "Synapse Library. Component " + "cannot be built for " + artifactName);
                }
            }
        } else {
            artifact.loadComponentsInto(library);
        }
    }
}
Also used : TemplateMediator(org.apache.synapse.mediators.template.TemplateMediator) SynapseArtifactDeploymentException(org.apache.synapse.deployers.SynapseArtifactDeploymentException) Template(org.apache.synapse.endpoints.Template)

Aggregations

SynapseArtifactDeploymentException (org.apache.synapse.deployers.SynapseArtifactDeploymentException)4 ZipFile (java.util.zip.ZipFile)3 XMLStreamException (javax.xml.stream.XMLStreamException)2 DeploymentException (org.apache.axis2.deployment.DeploymentException)2 SynapseException (org.apache.synapse.SynapseException)2 SynapseLibrary (org.apache.synapse.libraries.model.SynapseLibrary)2 OMElement (org.apache.axiom.om.OMElement)1 StAXOMBuilder (org.apache.axiom.om.impl.builder.StAXOMBuilder)1 Template (org.apache.synapse.endpoints.Template)1 Library (org.apache.synapse.libraries.model.Library)1 LibraryArtifact (org.apache.synapse.libraries.model.LibraryArtifact)1 TemplateMediator (org.apache.synapse.mediators.template.TemplateMediator)1