1 23 24 package com.sun.enterprise.deployment.backend; 25 26 import java.io.File ; 27 import java.io.OutputStream ; 28 import java.io.BufferedOutputStream ; 29 30 import java.util.Iterator ; 31 import java.util.Collection ; 32 import java.util.HashSet ; 33 import java.util.Set ; 34 35 import java.net.URL ; 36 import javax.servlet.SingleThreadModel ; 37 import javax.xml.ws.http.HTTPBinding; 38 39 import com.sun.enterprise.deployment.Application; 40 import com.sun.enterprise.deployment.WebBundleDescriptor; 41 import com.sun.enterprise.deployment.WebService; 42 import com.sun.enterprise.deployment.WebServiceEndpoint; 43 import com.sun.enterprise.deployment.WebComponentDescriptor; 44 import com.sun.enterprise.deployment.deploy.shared.FileArchive; 45 import com.sun.enterprise.deployment.deploy.shared.AbstractArchive; 46 import com.sun.enterprise.deployment.io.WebDeploymentDescriptorFile; 47 import com.sun.enterprise.deployment.util.WebServerInfo; 48 import com.sun.enterprise.deployment.util.VirtualServerInfo; 49 50 import com.sun.enterprise.webservice.WsUtil; 51 52 import com.sun.enterprise.diagnostics.util.FileUtils; 53 54 import com.sun.enterprise.util.i18n.StringManager; 55 61 public class WebServiceDeployer { 62 63 private static StringManager localStrings = 64 StringManager.getManager( WebServiceDeployer.class ); 65 66 private DeploymentRequest request; 67 68 69 public WebServiceDeployer(DeploymentRequest request) { 70 this.request = request; 71 } 72 73 83 public void doWebServiceDeployment(Application app, File appDir) throws Exception { 84 85 ClassLoader loader = app.getClassLoader(); 86 Collection webBundles = new HashSet (); 87 Collection webServices = new HashSet (); 88 89 webBundles.addAll( app.getWebBundleDescriptors() ); 91 webServices.addAll( app.getWebServiceDescriptors() ); 92 93 if (request.getContextRoot()!=null) { 96 if (app.isVirtual()) { 97 ((WebBundleDescriptor) webBundles.iterator().next()).setContextRoot(request.getContextRoot()); 98 } 99 } 100 101 for(Iterator <WebBundleDescriptor> iter = webBundles.iterator(); iter.hasNext(); ) { 106 doWebServiceDeployment(iter.next(), appDir); 107 } 108 109 for(Iterator <WebService> iter = webServices.iterator(); iter.hasNext(); ) { 112 WsUtil wsUtil = new WsUtil(); 113 WebService next = iter.next(); 114 115 if( (next.getWsdlFileUrl() == null) && 118 (next.getMappingFileUri() == null) ) { 119 for(WebServiceEndpoint wsep : next.getEndpoints()) { 120 if(!(HTTPBinding.HTTP_BINDING.equals(wsep.getProtocolBinding()))) { 121 throw new Exception ( 122 localStrings.getStringWithDefault( 123 "enterprise.webservice.noWsdlError", 124 "Service {0} has an endpoint with non-HTTP binding but there is no WSDL; Deployment cannot proceed", 125 new Object [] {next.getName()})); 126 } 127 wsep.composeFinalWsdlUrl(wsUtil.getWebServerInfo(request).getWebServerRootURL(wsep.isSecure())); 128 } 129 continue; 130 } 131 132 URL clientPublishLocation = next.getClientPublishUrl(); 133 134 URL url = next.getWsdlFileUrl(); 143 144 File genXmlDir = request.getGeneratedXMLDirectory(); 146 if(request.isApplication()) { 147 String subDirName = next.getBundleDescriptor().getModuleDescriptor().getArchiveUri(); 149 genXmlDir = new File (genXmlDir, subDirName.replaceAll("\\.", "_")); 150 } 151 File genWsdlFile = null; 152 153 if (!next.hasWsdlFile()) { 154 genWsdlFile = new File (url.toURI()); 159 genWsdlFile = File.createTempFile("gen_","", genWsdlFile.getParentFile()); 160 } else { 161 String wsdlFileDir = next.getWsdlFileUri().substring(0, next.getWsdlFileUri().lastIndexOf('/')); 162 (new File (genXmlDir, wsdlFileDir)).mkdirs(); 163 genWsdlFile = new File (genXmlDir, next.getWsdlFileUri()); 164 } 165 wsUtil.generateFinalWsdl(url, next, wsUtil.getWebServerInfo(request), genWsdlFile); 166 167 if (!next.hasWsdlFile()) { 168 File finalName = new File (url.toURI()); 172 File tmpName = new File (genWsdlFile.getAbsolutePath() + ".TMP"); 173 boolean renameDone = finalName.renameTo(tmpName); 175 if(!renameDone) { 176 FileUtils.moveFile(finalName.getAbsolutePath(), tmpName.getAbsolutePath()); 179 } 180 renameDone = genWsdlFile.renameTo(finalName); 182 if(!renameDone) { 183 FileUtils.moveFile(genWsdlFile.getAbsolutePath(), finalName.getAbsolutePath()); 186 } 187 tmpName.delete(); 189 } 190 } 191 } 192 193 203 public void doWebServiceDeployment(WebBundleDescriptor web, File outDir) throws Exception { 204 205 Collection endpoints = web.getWebServices().getEndpoints(); 206 ClassLoader loader = web.getClassLoader(); 207 208 boolean writeModule = !endpoints.isEmpty(); 209 210 for(Iterator endpointIter = endpoints.iterator(); 211 endpointIter.hasNext();) { 212 213 WebServiceEndpoint nextEndpoint = (WebServiceEndpoint) 214 endpointIter.next(); 215 WebComponentDescriptor webComp = nextEndpoint.getWebComponentImpl(); 216 String servletImplClass = nextEndpoint.getServletImplClass(); 217 if( !nextEndpoint.hasServletImplClass() ) { 218 throw new Exception ( 219 localStrings.getStringWithDefault( 220 "enterprise.deployment.backend.cannot_find_servlet", 221 "Runtime settings error. Cannot find servlet-impl-class for endpoint {0} ", 222 new Object [] {nextEndpoint.getEndpointName()})); 223 } 224 225 if( !nextEndpoint.getWebService().hasFilePublishing() ) { 226 String publishingUri = nextEndpoint.getPublishingUri(); 228 String publishingUrlPattern = 229 (publishingUri.charAt(0) == '/') ? 230 publishingUri : "/" + publishingUri + "/*"; 231 webComp.addUrlPattern(publishingUrlPattern); 232 } 233 234 Class servletImplClazz = loader.loadClass(servletImplClass); 235 String containerServlet; 236 if("1.1".compareTo(web.getWebServices().getSpecVersion())<0) { 239 containerServlet = "com.sun.enterprise.webservice.JAXWSServlet"; 240 } else { 241 containerServlet = 242 SingleThreadModel .class.isAssignableFrom(servletImplClazz) ? 243 "com.sun.enterprise.webservice.SingleThreadJAXRPCServlet" : 244 "com.sun.enterprise.webservice.JAXRPCServlet"; 245 } 246 webComp.setWebComponentImplementation(containerServlet); 247 } 248 } 249 } 250 | Popular Tags |