Search in sources :

Example 1 with SynapseLibrary

use of org.apache.synapse.libraries.model.SynapseLibrary in project wso2-synapse by wso2.

the class LibDeployerUtils method createSynapseLibraryWithDeps.

/**
 * Builds the Artifact object when an artifact element is given
 *
 * @param artifactEle - artifact OMElement
 * @return created Artifact object
 */
private static SynapseLibrary createSynapseLibraryWithDeps(OMElement artifactEle) {
    if (artifactEle == null) {
        return null;
    }
    SynapseLibrary synLib = new SynapseLibrary(readAttribute(artifactEle, LibDeployerConstants.NAME), readAttribute(artifactEle, LibDeployerConstants.PACKAGE_ATTR));
    synLib.setDescription(readChildText(artifactEle, LibDeployerConstants.DESCRIPTION_ELEMENT));
    // read the dependencies
    Iterator itr = artifactEle.getChildrenWithLocalName(LibDeployerConstants.DEPENDENCY);
    while (itr.hasNext()) {
        OMElement depElement = (OMElement) itr.next();
        // create a synLib for each dependency and add to the root synLib
        LibraryArtifact.Dependency dep = new LibraryArtifact.Dependency(readAttribute(depElement, LibDeployerConstants.ARTIFACT));
        synLib.addDependency(dep);
    }
    return synLib;
}
Also used : SynapseLibrary(org.apache.synapse.libraries.model.SynapseLibrary) OMElement(org.apache.axiom.om.OMElement) LibraryArtifact(org.apache.synapse.libraries.model.LibraryArtifact)

Example 2 with SynapseLibrary

use of org.apache.synapse.libraries.model.SynapseLibrary 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 3 with SynapseLibrary

use of org.apache.synapse.libraries.model.SynapseLibrary in project wso2-synapse by wso2.

the class LibDeployerUtils method createSynapseLibrary.

public static Library createSynapseLibrary(String libPath) {
    String libFilePath = LibDeployerUtils.formatPath(libPath);
    // extract
    String extractPath = LibDeployerUtils.extractSynapseLib(libFilePath);
    // create synapse lib metadata
    SynapseLibrary synapseLib = LibDeployerUtils.populateDependencies(extractPath + LibDeployerConstants.ARTIFACTS_XML);
    // 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  : " + libFilePath, e);
    }
    // resolve synapse lib artifacts
    LibDeployerUtils.searchAndResolveDependencies(extractPath, synapseLib);
    // TODO:reslove local-entry references
    LibDeployerUtils.populateLocalEnties(synapseLib, extractPath + LibDeployerConstants.LOCAL_ENTRIES);
    synapseLib.setFileName(libFilePath);
    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)

Aggregations

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