1 7 8 package org.jboss.webservice; 10 11 13 import org.dom4j.Document; 14 import org.dom4j.io.OutputFormat; 15 import org.dom4j.io.SAXReader; 16 import org.dom4j.io.XMLWriter; 17 import org.jboss.deployment.DeploymentException; 18 import org.jboss.deployment.DeploymentInfo; 19 import org.jboss.logging.Logger; 20 import org.jboss.webservice.metadata.PortComponentMetaData; 21 import org.jboss.webservice.metadata.WebserviceDescriptionMetaData; 22 import org.jboss.webservice.metadata.WebservicesMetaData; 23 import org.jboss.webservice.server.ServiceEndpointServletJSE; 24 import org.jboss.util.xml.JBossEntityResolver; 25 26 import javax.management.ObjectName ; 27 import java.io.File ; 28 import java.io.FileOutputStream ; 29 import java.io.IOException ; 30 import java.net.URL ; 31 32 41 public class ServiceDeployerJSE extends ServiceDeployer implements ServiceDeployerJSEMBean 42 { 43 private final Logger log = Logger.getLogger(ServiceDeployer.class); 45 46 private ObjectName warDeployer; 48 49 54 public void setWARDeployer(ObjectName deployerName) 55 { 56 this.warDeployer = deployerName; 57 } 58 59 62 protected void startService() throws Exception 63 { 64 super.startService(); 65 registerNotificationListener(warDeployer); 66 } 67 68 71 protected void stopService() throws Exception 72 { 73 unregisterNotificationListener(warDeployer); 74 super.stopService(); 75 } 76 77 80 protected URL getWebservicesDescriptor(DeploymentInfo di) 81 { 82 if (di.localCl != null) 83 return di.localCl.findResource("WEB-INF/webservices.xml"); 84 else 85 return null; 86 } 87 88 92 protected void createWebservice(DeploymentInfo di) throws DeploymentException 93 { 94 super.createWebservice(di); 96 97 WebservicesMetaData webservices = (WebservicesMetaData)webservicesMap.get(di.url); 98 modifyWebXML(di, webservices); 99 } 100 101 103 private void modifyWebXML(DeploymentInfo di, WebservicesMetaData webservices) 104 throws DeploymentException 105 { 106 if (webservices == null) 107 throw new DeploymentException("webservices.xml not registerd"); 108 109 File warFile = new File (di.localUrl.getFile()); 110 if (warFile.isDirectory() == false) 111 throw new DeploymentException("Expected a war directory: " + di.localUrl); 112 113 File webXML = new File (di.localUrl.getFile() + "/WEB-INF/web.xml"); 114 if (webXML.isFile() == false) 115 throw new DeploymentException("Cannot find web.xml: " + webXML); 116 117 FileOutputStream fos = null; 118 try 119 { 120 SAXReader saxReader = new SAXReader(); 121 saxReader.setEntityResolver(new JBossEntityResolver()); 122 123 Document doc = saxReader.read(webXML); 124 125 if (modifyWebXMLDocument(doc, di, webservices)) 126 { 127 File orgWebXML = new File (webXML.getCanonicalPath() + ".org"); 129 orgWebXML.delete(); 130 131 if (webXML.renameTo(orgWebXML) == false) 133 throw new DeploymentException("Cannot rename web.xml: " + orgWebXML); 134 135 OutputFormat format = OutputFormat.createPrettyPrint(); 136 fos = new FileOutputStream (webXML); 137 XMLWriter writer = new XMLWriter(fos, format); 138 writer.write(doc); 139 } 140 } 141 catch (DeploymentException e) 142 { 143 throw e; 144 } 145 catch (Exception e) 146 { 147 throw new DeploymentException(e); 148 } 149 finally 150 { 151 if (fos != null) 152 { 153 try 154 { 155 fos.close(); 156 } 157 catch (IOException e) 158 { 159 log.warn("Unexpected IOException on file close", e); 160 } 161 } 162 } 163 } 164 165 170 private boolean modifyWebXMLDocument(Document doc, DeploymentInfo di, WebservicesMetaData webservices) throws DeploymentException 171 { 172 boolean modified = false; 173 174 WebserviceDescriptionMetaData[] wsDescriptions = webservices.getWebserviceDescriptions(); 175 for (int i = 0; i < wsDescriptions.length; i++) 176 { 177 WebserviceDescriptionMetaData wsDescription = wsDescriptions[i]; 178 PortComponentMetaData[] portComponents = wsDescription.getPortComponents(); 179 for (int j = 0; j < portComponents.length; j++) 180 { 181 PortComponentMetaData pcMetaData = portComponents[j]; 182 PortComponentInfo pcInfo = new PortComponentInfo(di, pcMetaData); 183 184 String servletLink = pcMetaData.getServletLink(); 186 if (servletLink == null) 187 throw new DeploymentException("Cannot find servlet-link in port-component: " + pcMetaData.getPortComponentName()); 188 189 if (modifyServletConfig(doc, servletLink, pcInfo)) 191 modified = true; 192 } 193 } 194 195 return modified; 196 } 197 198 199 protected String getServiceEndpointServletName() 200 { 201 return ServiceEndpointServletJSE.class.getName(); 202 } 203 } 204 | Popular Tags |