1 16 17 package org.apache.axis2.deployment.repository.util; 18 19 import org.apache.axis2.deployment.DeploymentConstants; 20 import org.apache.axis2.deployment.DeploymentEngine; 21 import org.apache.axis2.deployment.DeploymentException; 22 import org.apache.axis2.deployment.DeploymentParser; 23 import org.apache.axis2.description.AxisDescWSDLComponentFactory; 24 import org.apache.axis2.description.ModuleDescription; 25 import org.apache.axis2.description.ServiceDescription; 26 import org.apache.axis2.wsdl.WSDLVersionWrapper; 27 import org.apache.axis2.wsdl.builder.WOMBuilderFactory; 28 import org.apache.axis2.wsdl.builder.WOMBuilder; 29 import org.apache.commons.logging.Log; 30 import org.apache.commons.logging.LogFactory; 31 import org.apache.wsdl.WSDLDescription; 32 33 import java.io.*; 34 import java.util.Iterator ; 35 import java.util.zip.ZipEntry ; 36 import java.util.zip.ZipInputStream ; 37 import java.util.zip.ZipOutputStream ; 38 39 public class ArchiveReader implements DeploymentConstants { 40 41 private Log log = LogFactory.getLog(getClass()); 42 43 78 public ServiceDescription createService(ArchiveFileData file) throws DeploymentException { 79 ServiceDescription service = null; 80 InputStream in= file.getClassLoader().getResourceAsStream(SERVICEWSDL); 81 boolean foundservice = false; 82 try { 83 if(in!= null){ 84 WOMBuilder builder = WOMBuilderFactory.getBuilder(WOMBuilderFactory.WSDL11); 85 WSDLVersionWrapper wsdlVersionWrapper = builder.build(in, new AxisDescWSDLComponentFactory()); 86 WSDLDescription womDescription = wsdlVersionWrapper.getDescription(); 87 Iterator iterator = womDescription.getServices().keySet().iterator(); 88 if(iterator.hasNext()){ 89 foundservice = true; 90 service = (ServiceDescription)womDescription.getServices().get(iterator.next()); 91 } 92 if(!foundservice){ 93 service = new ServiceDescription(); 94 } 95 service.setWSDLDefinition(wsdlVersionWrapper.getDefinition()); 96 in.close(); 97 } else { 98 service = new ServiceDescription(); 99 log.info("WSDL file not found for the service : " + file.getName()); 100 } 101 } catch (Exception e) { 102 throw new DeploymentException(e); 103 } 104 105 return service; 106 } 107 108 115 116 public void readServiceArchive(String filename, DeploymentEngine engine, ServiceDescription service) throws DeploymentException { 117 boolean foundServiceXML = false; 119 String strArchive = filename; 120 ZipInputStream zin; 121 try { 122 zin = new ZipInputStream (new FileInputStream(strArchive)); 123 ZipEntry entry; 124 while ((entry = zin.getNextEntry()) != null) { 125 if (entry.getName().equals(SERVICEXML)) { 126 foundServiceXML = true; 127 DeploymentParser schme = new DeploymentParser(zin, engine); 128 schme.parseServiceXML(service); 129 break; 130 } 131 } 132 zin.close(); 133 if (!foundServiceXML) { 134 throw new DeploymentException("service.xml not found"); 135 } 136 } catch (Exception e) { 137 throw new DeploymentException(e); 138 } 139 } 140 141 public void readModuleArchive(String filename, DeploymentEngine engine, ModuleDescription module) throws DeploymentException { 142 boolean foundmoduleXML = false; 144 String strArchive = filename; 145 ZipInputStream zin = null; 146 try { 147 zin = new ZipInputStream (new FileInputStream(strArchive)); 148 ZipEntry entry; 149 while ((entry = zin.getNextEntry()) != null) { 150 if (entry.getName().equals(MODULEXML)) { 151 foundmoduleXML = true; 152 DeploymentParser schme = new DeploymentParser(zin, engine); 153 schme.procesModuleXML(module); 154 break; 155 } 156 } 157 zin.close(); 159 if (!foundmoduleXML) { 160 throw new DeploymentException("module.xml not found for the module : " + strArchive); 161 } 162 } catch (Exception e) { 163 throw new DeploymentException(e.getMessage()); 164 } 165 } 166 167 175 public File creatModuleArchivefromResource(String moduleName) throws DeploymentException { 176 File modulearchiveFile = null; 177 File modules = null; 178 try { 179 int BUFFER = 2048; 180 if(DeploymentEngine.axis2repository == null ){ 181 String userHome = System.getProperty("user.home"); 182 File userHomedir = new File(userHome); 183 File repository = new File(userHomedir, ".axis2home"); 184 if (!repository.exists()) { 185 repository.mkdirs(); 186 modules = new File(repository, "modules"); 187 modules.mkdirs(); 188 } 189 } else { 190 modules = new File(DeploymentEngine.axis2repository , "modules"); 191 if(!modules.exists()){ 192 modules = new File(DeploymentEngine.axis2repository, "modules"); 193 modules.mkdirs(); 194 } 195 } 196 String modulearchiveName =moduleName + ".mar"; 197 modulearchiveFile = new File(modules,modulearchiveName); 198 if (modulearchiveFile.exists()) { 199 return modulearchiveFile; 200 } else { 201 modulearchiveFile.createNewFile(); 202 } 203 FileOutputStream dest = new 204 FileOutputStream(modulearchiveFile); 205 ZipOutputStream out = new ZipOutputStream (new 206 BufferedOutputStream(dest)); 207 byte data[] = new byte[BUFFER]; 208 209 ClassLoader cl = Thread.currentThread().getContextClassLoader(); 210 InputStream in = cl.getResourceAsStream("modules/" + moduleName + ".mar"); 211 if(in == null ){ 212 in = cl.getResourceAsStream("modules/" + moduleName + ".jar"); 213 } 214 if(in == null){ 215 throw new DeploymentException( moduleName + " module is not found"); 216 } 217 ZipInputStream zin = null; 218 zin = new ZipInputStream (in); 219 ZipEntry entry; 220 while ((entry = zin.getNextEntry()) != null) { 221 ZipEntry zip = new ZipEntry (entry); 222 out.putNextEntry(zip); 223 int count; 224 while ((count = zin.read(data, 0, BUFFER)) != -1) { 225 out.write(data, 0, count); 226 } 227 } 228 out.close(); 229 zin.close(); 230 } catch (Exception e) { 231 throw new DeploymentException(e.getMessage()); 232 } 233 return modulearchiveFile; 234 } 235 236 } 237 238 239 240 241 242 243 244 245 | Popular Tags |