1 7 8 10 package org.jboss.net.axis.server; 11 12 import org.jboss.axis.AxisProperties; 13 import org.jboss.axis.EngineConfiguration; 14 import org.jboss.axis.EngineConfigurationFactory; 15 import org.jboss.axis.configuration.EngineConfigurationFactoryFinder; 16 import org.jboss.axis.deployment.wsdd.WSDDUndeployment; 17 import org.jboss.axis.server.AxisServer; 18 import org.jboss.deployment.DeploymentException; 19 import org.jboss.deployment.DeploymentInfo; 20 import org.jboss.deployment.SubDeployerSupport; 21 import org.jboss.metadata.MetaData; 22 import org.jboss.net.axis.AttacheableService; 23 import org.jboss.net.axis.Deployment; 24 import org.jboss.net.axis.XMLResourceProvider; 25 import org.jboss.util.xml.JBossEntityResolver; 26 import org.w3c.dom.Attr ; 27 import org.w3c.dom.Document ; 28 import org.w3c.dom.Element ; 29 import org.w3c.dom.NamedNodeMap ; 30 import org.w3c.dom.Node ; 31 import org.w3c.dom.NodeList ; 32 33 import javax.management.MBeanRegistration ; 34 import javax.naming.InitialContext ; 35 import javax.naming.NamingException ; 36 import javax.xml.parsers.DocumentBuilder ; 37 import javax.xml.parsers.DocumentBuilderFactory ; 38 import javax.xml.rpc.server.ServiceLifecycle ; 39 import java.net.URL ; 40 41 56 57 public class AxisService 58 extends SubDeployerSupport 59 implements AxisServiceMBean, MBeanRegistration 60 { 61 62 66 67 protected AxisServer axisServer; 68 69 70 protected XMLResourceProvider clientConfiguration; 71 72 73 protected XMLResourceProvider serverConfiguration; 74 75 76 protected InitialContext initialContext; 77 78 79 protected DocumentBuilder documentBuilder; 80 81 82 protected boolean validateDTDs; 83 84 88 89 public AxisService() 90 { 91 } 92 93 97 101 protected void copyChildren(Document sourceDoc, 102 Element source, 103 String match, 104 Element target) 105 { 106 NodeList children = source.getChildNodes(); 107 for (int count = 0; count < children.getLength(); count++) 108 { 109 Node actNode = children.item(count); 110 if (actNode instanceof Element ) 111 { 112 if (((Element )actNode).getLocalName().equals(match)) 113 { 114 target.appendChild(sourceDoc.importNode(actNode, true)); 115 } 116 } 117 } 118 } 119 120 121 protected void startAxisDeployment(String deploymentName, Element root, ClassLoader deploymentLoader) 122 throws DeploymentException 123 { 124 125 try 126 { 127 128 Document deployDoc = documentBuilder.newDocument(); 130 Document deployClientDoc = documentBuilder.newDocument(); 132 Element deploy = 134 deployDoc.createElementNS(root.getNamespaceURI(), "deployment"); 135 Element deployClient = 137 deployClientDoc.createElementNS(root.getNamespaceURI(), 138 "deployment"); 139 140 NamedNodeMap attributes = root.getAttributes(); 141 for (int count = 0; count < attributes.getLength(); count++) 142 { 143 Attr attribute = (Attr )attributes.item(count); 144 deploy.setAttributeNodeNS((Attr )deployDoc.importNode(attribute, true)); 145 deployClient.setAttributeNodeNS((Attr )deployClientDoc.importNode(attribute, true)); 146 } 147 148 NodeList children = root.getChildNodes(); 151 for (int count = 0; count < children.getLength(); count++) 152 { 153 Node actNode = children.item(count); 154 if (actNode instanceof Element ) 155 { 156 Element actElement = (Element )actNode; 157 158 if (actElement.getTagName().equals("ejb-ref")) 159 { 160 161 String refName = 162 MetaData.getElementContent(MetaData.getUniqueChild((Element )actNode, 163 "ejb-ref-name")); 164 String linkName = 165 MetaData.getElementContent(MetaData.getUniqueChild((Element )actNode, "ejb-link")); 166 167 log.warn("Web Service Deployment " 168 + deploymentName 169 + " makes use of the deprecated ejb-ref feature. " 170 + "Please adjust any ejb-providing service tag inside your web-service.xml pointing to " 171 + refName 172 + " to use the absolute " 173 + linkName 174 + " instead."); 175 176 } 177 else if (actElement.getTagName().equals("ext-service")) 178 { 179 deployExternalWebService(actElement); 180 } 181 else 182 { 183 if (!actElement.getTagName().equals("service")) 184 { 185 deployClient.appendChild(deployClientDoc.importNode(actNode, true)); 186 } 187 deploy.appendChild(deployDoc.importNode(actNode, true)); 188 } 189 } 190 else 191 { 192 deployClient.appendChild(deployClientDoc.importNode(actNode, true)); 193 deploy.appendChild(deployDoc.importNode(actNode, true)); 194 } 195 } 196 197 deployDoc.appendChild(deploy); 199 deployClientDoc.appendChild(deployClient); 200 201 Deployment.makeSafeDeployment(deploy, deploymentLoader).deployToRegistry(((XMLResourceProvider)axisServer.getConfig()).getDeployment()); 202 Deployment.makeSafeDeployment(deployClient, deploymentLoader).deployToRegistry(clientConfiguration.getDeployment()); 203 axisServer.refreshGlobalOptions(); 204 axisServer.saveConfiguration(); 205 } 206 catch (Exception e) 207 { 208 throw new DeploymentException(Constants.COULD_NOT_DEPLOY_DESCRIPTOR, 209 e); 210 } 211 } 212 213 214 protected void stopAxisDeployment(Element root) throws DeploymentException 215 { 216 try 217 { 218 Document undeployDoc = documentBuilder.newDocument(); 220 Element undeploy = 221 undeployDoc.createElementNS(root.getNamespaceURI(), "undeployment"); 222 223 NamedNodeMap attributes = root.getAttributes(); 225 for (int count = 0; count < attributes.getLength(); count++) 226 { 227 Attr attribute = (Attr )attributes.item(count); 228 undeploy.setAttributeNodeNS((Attr )undeployDoc.importNode(attribute, true)); 229 } 230 231 NodeList children = root.getElementsByTagName("ext-service"); 233 for (int count = 0; count < children.getLength(); count++) 234 { 235 Element actNode = (Element )children.item(count); 236 undeployExternalWebService(actNode); 237 } 238 239 copyChildren(undeployDoc, root, "service", undeploy); 242 243 children = root.getElementsByTagName("service"); 245 for (int count = 0; count < children.getLength(); count++) 246 { 247 Element actNode = (Element )children.item(count); 248 String serviceName = actNode.getAttribute("name"); 249 ServiceLifecycle slc = (ServiceLifecycle )axisServer. 250 getApplicationSession().get(serviceName); 251 if (slc != null) 252 { 253 slc.destroy(); 254 axisServer.getApplicationSession().remove(serviceName); 255 } 256 } 257 258 copyChildren(undeployDoc, root, "handler", undeploy); 259 copyChildren(undeployDoc, root, "typemapping", undeploy); 260 copyChildren(undeployDoc, root, "beanmapping", undeploy); 261 262 undeployDoc.appendChild(undeploy); 264 265 new WSDDUndeployment(undeploy).undeployFromRegistry(((XMLResourceProvider)axisServer.getConfig()).getDeployment()); 267 new WSDDUndeployment(undeploy).undeployFromRegistry(clientConfiguration.getDeployment()); 269 axisServer.refreshGlobalOptions(); 270 axisServer.saveConfiguration(); 271 } 272 catch (Exception e) 273 { 274 throw new DeploymentException(Constants.COULD_NOT_UNDEPLOY, e); 275 } 276 } 277 278 281 282 protected synchronized void deployExternalWebService(Element deployElement) 283 throws DeploymentException 284 { 285 286 try 287 { 288 if (initialContext == null) 289 { 290 initialContext = new InitialContext (); 291 } 292 293 NamedNodeMap attributes = deployElement.getAttributes(); 294 295 String jndiName = attributes.getNamedItem("jndiName").getNodeValue(); 296 String serviceClassName = 297 attributes.getNamedItem("serviceImplClass").getNodeValue(); 298 Object factory = 299 new AttacheableService(serviceClassName, 300 serviceName.getCanonicalName()); 301 initialContext.bind(jndiName, factory); 302 } 303 catch (NamingException e) 304 { 305 throw new DeploymentException("Could not deploy item " + deployElement, 306 e); 307 } 308 } 309 310 311 protected synchronized void undeployExternalWebService(Element deployElement) 312 { 313 try 314 { 315 if (initialContext == null) 316 { 317 initialContext = new InitialContext (); 318 } 319 320 NamedNodeMap attributes = deployElement.getAttributes(); 321 322 String jndiName = attributes.getNamedItem("jndiName").getNodeValue(); 323 324 if (jndiName != null) 325 { 326 initialContext.unbind(jndiName); 327 } 328 } 329 catch (NamingException e) 330 { 331 log.warn("Could not undeploy " + deployElement, 333 e); 334 } 335 } 336 337 341 347 protected void startService() throws Exception 348 { 349 350 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); 351 dbf.setNamespaceAware(true); 352 dbf.setValidating(validateDTDs); 359 360 documentBuilder = dbf.newDocumentBuilder(); 361 documentBuilder.setEntityResolver(new JBossEntityResolver()); 362 363 URL resource = 365 getClass().getClassLoader().getResource(Constants.AXIS_SERVER_CONFIGURATION_FILE); 366 367 if (resource == null) 368 { 369 log.warn("Could not find: " + Constants.AXIS_SERVER_CONFIGURATION_FILE); 370 throw new Exception (Constants.COULD_NOT_FIND_AXIS_CONFIGURATION_0); 371 } 372 373 serverConfiguration = new XMLResourceProvider(resource, getClass().getClassLoader()); 374 375 axisServer = new AxisServer(serverConfiguration); 376 377 serverConfiguration.getGlobalOptions().put(org.jboss.net.axis.Constants.CONFIGURATION_CONTEXT, 379 serviceName.toString()); 380 381 resource = 383 getClass().getClassLoader().getResource(Constants.AXIS_CLIENT_CONFIGURATION_FILE); 384 385 if (resource == null) 386 { 387 log.warn("Failed to find: " + Constants.AXIS_SERVER_CONFIGURATION_FILE); 388 throw new Exception (Constants.COULD_NOT_FIND_AXIS_CONFIGURATION_0); 389 } 390 391 clientConfiguration = new XMLResourceProvider(resource, getClass().getClassLoader()); 392 clientConfiguration.buildDeployment(); 393 clientConfiguration.getGlobalOptions().put(org.jboss.net.axis.Constants.CONFIGURATION_CONTEXT, 394 serviceName.toString()); 395 396 AxisProperties.getNameDiscoverer(); 398 Class initializeThisStaticStuff = 400 EngineConfigurationFactoryFinder.class; 401 System.setProperty(EngineConfigurationFactory.SYSTEM_PROPERTY_NAME, 402 JMXEngineConfigurationFactory.class.getName()); 403 super.startService(); 404 } 405 406 407 protected void stopService() throws Exception 408 { 409 super.stopService(); 410 axisServer.stop(); 411 documentBuilder = null; 412 } 413 414 418 421 422 public boolean accepts(DeploymentInfo sdi) 423 { 424 if (sdi.shortName.endsWith("-axis.xml") 425 || sdi.localCl.getResource(Constants.WEB_SERVICE_DESCRIPTOR) != null) 426 { 427 return true; 428 } 429 return false; 430 } 431 432 435 public void init(DeploymentInfo sdi) throws DeploymentException 436 { 437 super.init(sdi); 438 439 try 440 { 441 if (sdi.document == null) 442 { 443 if (sdi.documentUrl == null) 444 { 445 if (sdi.isXML) 446 { 447 sdi.documentUrl = sdi.localUrl; 448 } 449 else 450 { 451 sdi.documentUrl = 452 sdi.localCl.getResource(Constants.WEB_SERVICE_DESCRIPTOR); 453 } 454 } 455 sdi.document = documentBuilder.parse(sdi.documentUrl.openStream()); 456 } 457 458 if (sdi.isDirectory) 460 { 461 sdi.watch = new URL (sdi.url, Constants.WEB_SERVICE_DESCRIPTOR); 462 } 463 else 464 { 465 sdi.watch = sdi.url; 467 } 468 } 469 catch (Exception e) 470 { 471 throw new DeploymentException(e); 472 } 473 } 474 475 478 public void create(DeploymentInfo sdi) throws DeploymentException 479 { 480 log.debug("create, sdi=" + sdi); 481 super.create(sdi); 482 } 483 484 487 public void start(DeploymentInfo sdi) throws DeploymentException 488 { 489 log.debug("start, sdi=" + sdi); 490 super.start(sdi); 491 492 start(sdi.toString(), sdi.document, sdi.ucl); 493 } 494 495 499 500 public void start(String deploymentName, 501 Document doc, 502 ClassLoader serviceLoader) 503 throws DeploymentException 504 { 505 506 Element root = doc.getDocumentElement(); 508 509 if (root.getNodeName().equals("deployments")) 510 { 511 NodeList children = root.getChildNodes(); 512 513 for (int count = 0; count < children.getLength(); count++) 514 { 515 startAxisDeployment(deploymentName, 516 (Element )children.item(count), serviceLoader); 517 } 518 } 519 else 520 { 521 startAxisDeployment(deploymentName, root, serviceLoader); 522 } 523 } 524 525 528 public void stop(DeploymentInfo sdi) throws DeploymentException 529 { 530 log.debug("stop, sdi=" + sdi); 531 super.stop(sdi); 532 stop(sdi.document); 533 } 534 535 538 public void stop(Document doc) throws DeploymentException 539 { 540 Element root = (Element )doc.getDocumentElement(); 542 if (root.getNodeName().equals("deployments")) 543 { 544 NodeList children = root.getChildNodes(); 545 for (int count = 0; count < children.getLength(); count++) 546 { 547 stopAxisDeployment((Element )children.item(count)); 548 } 549 } 550 else 551 { 552 stopAxisDeployment(root); 553 } 554 } 555 556 559 public void destroy(DeploymentInfo sdi) throws DeploymentException 560 { 561 log.debug("destroy, sdi=" + sdi); 562 super.destroy(sdi); 563 } 564 565 569 public EngineConfiguration getClientEngineConfiguration() 570 { 571 return clientConfiguration; 572 } 573 574 578 public EngineConfiguration getServerEngineConfiguration() 579 { 580 return serverConfiguration; 581 } 582 583 587 public AxisServer getAxisServer() 588 { 589 return axisServer; 590 } 591 592 } 593 | Popular Tags |