31
31
import org .apache .synapse .config .SynapsePropertiesLoader ;
32
32
import org .apache .synapse .config .xml .SynapseXMLConfigurationFactory ;
33
33
import org .apache .synapse .deployers .SynapseArtifactDeploymentException ;
34
+ import org .apache .synapse .libraries .LibClassLoader ;
34
35
import org .apache .synapse .libraries .imports .SynapseImport ;
35
36
import org .apache .synapse .libraries .model .Library ;
36
37
import org .apache .synapse .libraries .model .LibraryArtifact ;
39
40
import javax .xml .namespace .QName ;
40
41
import javax .xml .stream .XMLStreamException ;
41
42
import java .io .*;
43
+ import java .net .MalformedURLException ;
42
44
import java .util .*;
43
45
import java .util .zip .ZipEntry ;
44
46
import java .util .zip .ZipFile ;
@@ -57,9 +59,11 @@ public class LibDeployerUtils {
57
59
58
60
private static final Log log = LogFactory .getLog (LibDeployerUtils .class );
59
61
62
+ public static Library createSynapseLibrary (String libPath ) throws DeploymentException {
63
+ return createSynapseLibrary (libPath , null );
64
+ }
60
65
61
-
62
- public static Library createSynapseLibrary (String libPath ) {
66
+ public static Library createSynapseLibrary (String libPath , ClassLoader classLoader ) throws DeploymentException {
63
67
File libFile = new File (libPath );
64
68
//extract
65
69
String extractPath = LibDeployerUtils .extractSynapseLib (libFile );
@@ -72,10 +76,23 @@ public static Library createSynapseLibrary(String libPath) {
72
76
if (deployedLibClassLoader == null ) {
73
77
//create a ClassLoader for loading this synapse lib classes/resources
74
78
try {
75
- ClassLoader libLoader = Utils .getClassLoader (LibDeployerUtils .class .getClassLoader (),
79
+ if (classLoader != null ) {
80
+ synapseLib .setLibClassLoader (classLoader );
81
+ SynapseConfiguration .addLibraryClassLoader (libArtifactName , classLoader );
82
+ if (classLoader instanceof LibClassLoader ) {
83
+ try {
84
+ ((LibClassLoader ) classLoader ).addURL (new File (extractPath ).toURI ().toURL ());
85
+ } catch (MalformedURLException e ) {
86
+ throw new DeploymentException ("Error while adding URL to the classloader" , e );
87
+ }
88
+ }
89
+ } else {
90
+ ClassLoader libLoader = Utils .getClassLoader (LibDeployerUtils .class .getClassLoader (),
76
91
extractPath , false );
77
- SynapseConfiguration .addLibraryClassLoader (libArtifactName , libLoader );
78
- synapseLib .setLibClassLoader (libLoader );
92
+ SynapseConfiguration .addLibraryClassLoader (libArtifactName , libLoader );
93
+ synapseLib .setLibClassLoader (libLoader );
94
+ }
95
+
79
96
} catch (DeploymentException e ) {
80
97
throw new SynapseArtifactDeploymentException ("Error setting up lib classpath for Synapse" +
81
98
" Library : " + libFile .getAbsolutePath (), e );
0 commit comments