PageRenderTime 42ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/jboss-as-7.1.1.Final/webservices/server-integration/src/main/java/org/jboss/as/webservices/deployers/WSIntegrationProcessorJAXWS_JMS.java

#
Java | 159 lines | 112 code | 14 blank | 33 comment | 22 complexity | b39d55880e7d16a02599b9b7f323f032 MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0
  1. /*
  2. * JBoss, Home of Professional Open Source.
  3. * Copyright 2011, Red Hat Middleware LLC, and individual contributors
  4. * as indicated by the @author tags. See the copyright.txt file in the
  5. * distribution for a full listing of individual contributors.
  6. *
  7. * This is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU Lesser General Public License as
  9. * published by the Free Software Foundation; either version 2.1 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This software is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this software; if not, write to the Free
  19. * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  20. * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  21. */
  22. package org.jboss.as.webservices.deployers;
  23. import static org.jboss.as.server.deployment.Attachments.DEPLOYMENT_ROOT;
  24. import static org.jboss.as.server.deployment.Attachments.RESOURCE_ROOTS;
  25. import static org.jboss.as.webservices.WSLogger.ROOT_LOGGER;
  26. import static org.jboss.as.webservices.util.ASHelper.getAnnotations;
  27. import static org.jboss.as.webservices.util.DotNames.WEB_SERVICE_ANNOTATION;
  28. import static org.jboss.as.webservices.util.WSAttachmentKeys.JMS_ENDPOINT_METADATA_KEY;
  29. import java.net.MalformedURLException;
  30. import java.net.URL;
  31. import java.util.HashMap;
  32. import java.util.LinkedList;
  33. import java.util.List;
  34. import java.util.Map;
  35. import javax.xml.namespace.QName;
  36. import org.jboss.as.ee.structure.DeploymentType;
  37. import org.jboss.as.ee.structure.DeploymentTypeMarker;
  38. import org.jboss.as.server.deployment.AttachmentList;
  39. import org.jboss.as.server.deployment.DeploymentPhaseContext;
  40. import org.jboss.as.server.deployment.DeploymentUnit;
  41. import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
  42. import org.jboss.as.server.deployment.DeploymentUnitProcessor;
  43. import org.jboss.as.server.deployment.module.ResourceRoot;
  44. import org.jboss.as.webservices.util.VirtualFileAdaptor;
  45. import org.jboss.jandex.AnnotationInstance;
  46. import org.jboss.jandex.AnnotationValue;
  47. import org.jboss.jandex.ClassInfo;
  48. import org.jboss.vfs.VirtualFile;
  49. import org.jboss.ws.common.deployment.SOAPAddressWSDLParser;
  50. import org.jboss.wsf.spi.deployment.UnifiedVirtualFile;
  51. import org.jboss.wsf.spi.metadata.jms.JMSEndpointMetaData;
  52. import org.jboss.wsf.spi.metadata.jms.JMSEndpointsMetaData;
  53. /**
  54. * DUP for detecting JMS WS endpoints
  55. *
  56. * @author <a href="mailto:alessio.soldano@jboss.com">Alessio Soldano</a>
  57. */
  58. public final class WSIntegrationProcessorJAXWS_JMS implements DeploymentUnitProcessor {
  59. private static final String WSDL_LOCATION = "wsdlLocation";
  60. private static final String PORT_NAME = "portName";
  61. private static final String SERVICE_NAME = "serviceName";
  62. private static final String TARGET_NAMESPACE = "targetNamespace";
  63. @Override
  64. public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
  65. final DeploymentUnit unit = phaseContext.getDeploymentUnit();
  66. if (DeploymentTypeMarker.isType(DeploymentType.EAR, unit)) {
  67. return;
  68. }
  69. final List<AnnotationInstance> webServiceAnnotations = getAnnotations(unit, WEB_SERVICE_ANNOTATION);
  70. // TODO: how about @WebServiceProvider JMS based endpoints?
  71. //group @WebService annotations in the deployment by wsdl contract location
  72. Map<String, List<AnnotationInstance>> map = new HashMap<String, List<AnnotationInstance>>();
  73. for (AnnotationInstance webServiceAnnotation : webServiceAnnotations) {
  74. final AnnotationValue wsdlLocation = webServiceAnnotation.value(WSDL_LOCATION);
  75. final AnnotationValue port = webServiceAnnotation.value(PORT_NAME);
  76. final AnnotationValue service = webServiceAnnotation.value(SERVICE_NAME);
  77. //support for contract-first development only: pick-up @WebService annotations referencing a provided wsdl contract only
  78. if (wsdlLocation != null && port != null && service != null) {
  79. String key = wsdlLocation.asString();
  80. List<AnnotationInstance> annotations = map.get(key);
  81. if (annotations == null) {
  82. annotations = new LinkedList<AnnotationInstance>();
  83. map.put(key, annotations);
  84. }
  85. annotations.add(webServiceAnnotation);
  86. }
  87. }
  88. //extract SOAP-over-JMS 1.0 bindings
  89. final JMSEndpointsMetaData endpointsMetaData = new JMSEndpointsMetaData();
  90. if (!map.isEmpty()) {
  91. for (String wsdlLocation : map.keySet()) {
  92. try {
  93. final ResourceRoot resourceRoot = getWsdlResourceRoot(unit, wsdlLocation);
  94. if (resourceRoot == null) continue;
  95. final UnifiedVirtualFile uvf = new VirtualFileAdaptor(resourceRoot.getRoot());
  96. URL url = uvf.findChild(wsdlLocation).toURL();
  97. SOAPAddressWSDLParser parser = new SOAPAddressWSDLParser(url);
  98. for (AnnotationInstance ai : map.get(wsdlLocation)) {
  99. String port = ai.value(PORT_NAME).asString();
  100. String service = ai.value(SERVICE_NAME).asString();
  101. AnnotationValue targetNS = ai.value(TARGET_NAMESPACE);
  102. String tns = targetNS != null ? targetNS.asString() : null;
  103. QName serviceName = new QName(tns, service);
  104. QName portName = new QName(tns, port);
  105. String soapAddress = parser.filterSoapAddress(serviceName, portName, SOAPAddressWSDLParser.SOAP_OVER_JMS_NS);
  106. if (soapAddress != null) {
  107. ClassInfo webServiceClassInfo = (ClassInfo) ai.target();
  108. String beanClassName = webServiceClassInfo.name().toString();
  109. //service name ?
  110. JMSEndpointMetaData endpointMetaData = new JMSEndpointMetaData(endpointsMetaData);
  111. endpointMetaData.setEndpointName(port);
  112. endpointMetaData.setName(beanClassName);
  113. endpointMetaData.setImplementor(beanClassName);
  114. //endpointMetaData.setName(name);
  115. endpointMetaData.setSoapAddress(soapAddress);
  116. endpointMetaData.setWsdlLocation(wsdlLocation);
  117. endpointsMetaData.addEndpointMetaData(endpointMetaData);
  118. }
  119. }
  120. } catch (Exception ignore) {
  121. ROOT_LOGGER.cannotReadWsdl(wsdlLocation);
  122. }
  123. }
  124. }
  125. unit.putAttachment(JMS_ENDPOINT_METADATA_KEY, endpointsMetaData);
  126. }
  127. @Override
  128. public void undeploy(final DeploymentUnit context) {
  129. // NOOP
  130. }
  131. private static ResourceRoot getWsdlResourceRoot(final DeploymentUnit unit, final String wsdlPath) throws MalformedURLException {
  132. final AttachmentList<ResourceRoot> resourceRoots = new AttachmentList<ResourceRoot>(ResourceRoot.class);
  133. final ResourceRoot root = unit.getAttachment(DEPLOYMENT_ROOT);
  134. resourceRoots.add(root);
  135. final AttachmentList<ResourceRoot> otherResourceRoots = unit.getAttachment(RESOURCE_ROOTS);
  136. if (otherResourceRoots != null) {
  137. resourceRoots.addAll(otherResourceRoots);
  138. }
  139. for (final ResourceRoot resourceRoot : resourceRoots) {
  140. VirtualFile file = resourceRoot.getRoot().getChild(wsdlPath);
  141. if (file.exists()) return resourceRoot;
  142. }
  143. return null;
  144. }
  145. }