1 23 24 package com.sun.enterprise.deployment.util; 25 26 import java.util.logging.Level ; 27 28 import java.io.*; 29 import java.net.URL ; 30 import com.sun.enterprise.deployment.deploy.shared.AbstractArchive; 31 import com.sun.enterprise.deployment.BundleDescriptor; 32 import com.sun.enterprise.deployment.ServiceReferenceDescriptor; 33 import com.sun.enterprise.deployment.WebService; 34 import com.sun.enterprise.deployment.util.DOLUtils; 35 import com.sun.enterprise.util.LocalStringManagerImpl; 36 37 45 public class ModuleContentValidator extends DefaultDOLVisitor { 46 47 private AbstractArchive archive_; 48 49 private static LocalStringManagerImpl localStrings = 51 new LocalStringManagerImpl(ModuleContentValidator.class); 52 53 public ModuleContentValidator(AbstractArchive archive) { 54 archive_ = archive; 55 } 56 57 public void accept(ServiceReferenceDescriptor serviceRef) { 58 if( serviceRef.hasWsdlFile() ) { 59 String wsdlFileUri = serviceRef.getWsdlFileUri(); 60 URL url = null; 65 try { 66 url = new URL (wsdlFileUri); 67 } catch(java.net.MalformedURLException e) { 68 } 70 if (url!=null) { 71 if (url.getProtocol().equals("http") || url.getProtocol().equals("https")) 72 return; 73 } 74 File tmpFile = new File(wsdlFileUri); 75 if(tmpFile.isAbsolute() && tmpFile.exists()) { 76 return; 77 } 78 try { 79 InputStream wsdlFileInputStream = 80 archive_.getEntry(wsdlFileUri); 81 if( wsdlFileInputStream != null ) { 82 wsdlFileInputStream.close(); 83 } else { 84 String msg = localStrings.getLocalString( 85 "enterprise.deployment.util.wsdlfilenotfound", 86 "wsdl file {0} does not exist for service-ref {1}", 87 new Object [] {wsdlFileUri, serviceRef.getName()}); 88 DOLUtils.getDefaultLogger().severe(msg); 89 throw new RuntimeException (msg); 90 } 91 } catch(IOException ioe) { 92 String msg = localStrings.getLocalString( 93 "enterprise.deployment.util.wsdlfilenotreadable", 94 "wsdl file {0} for service-ref {1} cannot be opened : {2}", 95 new Object [] {wsdlFileUri, serviceRef.getName(), ioe.getMessage()}); 96 DOLUtils.getDefaultLogger().severe(msg); 97 throw new RuntimeException (ioe); 98 } 99 } 100 101 if( serviceRef.hasMappingFile() ) { 102 String mappingFileUri = serviceRef.getMappingFileUri(); 103 try { 104 InputStream mappingFileInputStream = 105 archive_.getEntry(mappingFileUri); 106 if( mappingFileInputStream != null ) { 107 mappingFileInputStream.close(); 108 } else { 109 String msg = localStrings.getLocalString( 110 "enterprise.deployment.util.mappingfilenotfound", 111 "mapping file {0} does not exist for service-ref {1}", 112 new Object [] {mappingFileUri, serviceRef.getName()}); 113 DOLUtils.getDefaultLogger().severe(msg); 114 throw new RuntimeException (msg); 115 } 116 } catch(IOException ioe) { 117 String msg = localStrings.getLocalString( 118 "enterprise.deployment.util.mappingfilenotreadable", 119 "mapping file {0} for service-ref {1} cannot be opened : {2}", 120 new Object [] {mappingFileUri, serviceRef.getName(), ioe.getMessage()}); 121 DOLUtils.getDefaultLogger().severe(msg); 122 throw new RuntimeException (ioe); 123 } 124 } 125 } 126 127 public void accept(WebService webService) { 128 129 try { 130 131 String wsdlFileUri = webService.getWsdlFileUri(); 132 if (!webService.hasWsdlFile()) { 133 return; 136 } 137 try { 138 URL url = new URL (wsdlFileUri); 139 if (url.getProtocol()!=null && !url.getProtocol().equals("file")) 140 return; 141 } catch(java.net.MalformedURLException e) { 142 } 144 InputStream wsdlFileInputStream = archive_.getEntry(wsdlFileUri); 145 146 if( wsdlFileInputStream != null ) { 147 148 wsdlFileInputStream.close(); 149 BundleDescriptor bundle = webService.getBundleDescriptor(); 150 if( !isWsdlContent(wsdlFileUri, bundle) ) { 151 String msg = localStrings.getLocalString( 152 "enterprise.deployment.util.wsdlpackagedinwrongservicelocation", 153 "wsdl file {0} for web service {1} must be packaged in or below {2}", 154 new Object [] {wsdlFileUri, webService.getName(), bundle.getWsdlDir()}); 155 DOLUtils.getDefaultLogger().severe(msg); 156 throw new RuntimeException (msg); 157 } 158 } else { 159 String fullFileUri = webService.getBundleDescriptor().getWsdlDir() + "/" + wsdlFileUri; 161 wsdlFileInputStream = archive_.getEntry(fullFileUri); 162 163 if( wsdlFileInputStream != null ) { 164 wsdlFileInputStream.close(); 166 webService.setWsdlFileUri(fullFileUri); 167 } else { 168 String msg = localStrings.getLocalString( 170 "enterprise.deployment.util.servicewsdlfilenotfound", 171 "wsdl file {0} does not exist for web service {1}", 172 new Object [] {wsdlFileUri, webService.getName()}); 173 DOLUtils.getDefaultLogger().severe(msg); 174 throw new RuntimeException (msg); 175 } 176 } 177 } catch(IOException ioe) { 178 String msg = localStrings.getLocalString( 179 "enterprise.deployment.util.servicewsdlfilenotreadable", 180 "wsdl file {0} for service-ref {1} cannot be opened : {2}", 181 new Object [] {webService.getWsdlFileUri(), webService.getName(), ioe.getMessage()}); 182 DOLUtils.getDefaultLogger().severe(msg); 183 throw new RuntimeException (ioe); 184 } 185 186 if(webService.getMappingFileUri() == null) { 190 return; 191 } 192 193 try { 194 InputStream mappingFileInputStream = 195 archive_.getEntry(webService.getMappingFileUri()); 196 if( mappingFileInputStream != null ) { 197 mappingFileInputStream.close(); 198 } else { 199 String msg = localStrings.getLocalString( 200 "enterprise.deployment.util.servicemappingfilenotfound", 201 "Web Service mapping file {0} for web service {1} not found", 202 new Object [] {webService.getMappingFileUri(), webService.getName()}); 203 DOLUtils.getDefaultLogger().severe(msg); 204 throw new RuntimeException (msg); 205 } 206 } catch(IOException ioe) { 207 String msg = localStrings.getLocalString( 208 "enterprise.deployment.util.servicemappingfilenotreadable", 209 "Web Service mapping file {0} for web service {1} not found {2} ", 210 new Object [] {webService.getMappingFileUri(), webService.getName(), ioe}); 211 DOLUtils.getDefaultLogger().severe(msg); 212 throw new RuntimeException (ioe); 213 } 214 } 215 216 221 public boolean isWsdlContent(String uri, BundleDescriptor bundle) { 222 String wsdlDir = bundle.getWsdlDir(); 223 return (uri != null) && uri.startsWith(wsdlDir); 224 } 225 } 226 | Popular Tags |