PageRenderTime 22ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/jboss-as-7.1.1.Final/webservices/server-integration/src/main/java/org/jboss/as/webservices/metadata/AbstractMetaDataBuilderPOJO.java

#
Java | 241 lines | 133 code | 34 blank | 74 comment | 20 complexity | 37c8f872bb36e4a30af34babc603a8d8 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.metadata;
  23. import static org.jboss.as.webservices.WSLogger.ROOT_LOGGER;
  24. import static org.jboss.as.webservices.util.ASHelper.getContextRoot;
  25. import java.util.HashMap;
  26. import java.util.LinkedList;
  27. import java.util.List;
  28. import java.util.Map;
  29. import org.jboss.as.server.deployment.DeploymentUnit;
  30. import org.jboss.as.webservices.metadata.model.POJOEndpoint;
  31. import org.jboss.as.webservices.util.WebMetaDataHelper;
  32. import org.jboss.metadata.javaee.spec.ParamValueMetaData;
  33. import org.jboss.metadata.web.jboss.JBossServletsMetaData;
  34. import org.jboss.metadata.web.jboss.JBossWebMetaData;
  35. import org.jboss.metadata.web.spec.SecurityConstraintMetaData;
  36. import org.jboss.metadata.web.spec.ServletMappingMetaData;
  37. import org.jboss.metadata.web.spec.WebResourceCollectionMetaData;
  38. import org.jboss.metadata.web.spec.WebResourceCollectionsMetaData;
  39. import org.jboss.ws.common.integration.WSConstants;
  40. import org.jboss.ws.common.integration.WSHelper;
  41. import org.jboss.wsf.spi.deployment.Deployment;
  42. import org.jboss.wsf.spi.metadata.j2ee.JSEArchiveMetaData;
  43. import org.jboss.wsf.spi.metadata.j2ee.JSESecurityMetaData;
  44. import org.jboss.wsf.spi.metadata.j2ee.JSESecurityMetaData.JSEResourceCollection;
  45. import org.jboss.wsf.spi.metadata.j2ee.PublishLocationAdapter;
  46. import org.jboss.wsf.spi.metadata.webservices.JBossWebservicesMetaData;
  47. /**
  48. * Builds container independent meta data from WEB container meta data.
  49. *
  50. * @author <a href="mailto:ropalka@redhat.com">Richard Opalka</a>
  51. * @author <a href="mailto:tdiesler@redhat.com">Thomas Diesler</a>
  52. * @author <a href="mailto:alessio.soldano@jboss.com">Alessio Soldano</a>
  53. */
  54. abstract class AbstractMetaDataBuilderPOJO {
  55. AbstractMetaDataBuilderPOJO() {
  56. super();
  57. }
  58. /**
  59. * Builds universal JSE meta data model that is AS agnostic.
  60. *
  61. * @param dep webservice deployment
  62. * @return universal JSE meta data model
  63. */
  64. JSEArchiveMetaData create(final Deployment dep) {
  65. ROOT_LOGGER.creatingPojoDeployment(dep.getSimpleName());
  66. final JBossWebMetaData jbossWebMD = WSHelper.getRequiredAttachment(dep, JBossWebMetaData.class);
  67. final DeploymentUnit unit = WSHelper.getRequiredAttachment(dep, DeploymentUnit.class);
  68. final List<POJOEndpoint> pojoEndpoints = getPojoEndpoints(unit);
  69. final JSEArchiveMetaData jseArchiveMD = new JSEArchiveMetaData();
  70. // set context root
  71. final String contextRoot = getContextRoot(dep, jbossWebMD);
  72. jseArchiveMD.setContextRoot(contextRoot);
  73. ROOT_LOGGER.settingContextRoot(contextRoot);
  74. // set servlet url patterns mappings
  75. final Map<String, String> servletMappings = getServletUrlPatternsMappings(jbossWebMD, pojoEndpoints);
  76. jseArchiveMD.setServletMappings(servletMappings);
  77. // set servlet class names mappings
  78. final Map<String, String> servletClassNamesMappings = getServletClassMappings(jbossWebMD, pojoEndpoints);
  79. jseArchiveMD.setServletClassNames(servletClassNamesMappings);
  80. // set security domain
  81. final String securityDomain = jbossWebMD.getSecurityDomain();
  82. jseArchiveMD.setSecurityDomain(securityDomain);
  83. // set wsdl location resolver
  84. final JBossWebservicesMetaData jbossWebservicesMD = WSHelper.getOptionalAttachment(dep, JBossWebservicesMetaData.class);
  85. if (jbossWebservicesMD != null) {
  86. final PublishLocationAdapter resolver = new PublishLocationAdapterImpl(jbossWebservicesMD.getWebserviceDescriptions());
  87. jseArchiveMD.setPublishLocationAdapter(resolver);
  88. }
  89. // set security meta data
  90. final List<JSESecurityMetaData> jseSecurityMDs = getSecurityMetaData(jbossWebMD.getSecurityConstraints());
  91. jseArchiveMD.setSecurityMetaData(jseSecurityMDs);
  92. // set config name and file
  93. setConfigNameAndFile(jseArchiveMD, jbossWebMD, jbossWebservicesMD);
  94. return jseArchiveMD;
  95. }
  96. protected abstract List<POJOEndpoint> getPojoEndpoints(final DeploymentUnit unit);
  97. /**
  98. * Sets config name and config file.
  99. *
  100. * @param jseArchiveMD universal JSE meta data model
  101. * @param jbossWebMD jboss web meta data
  102. */
  103. private void setConfigNameAndFile(final JSEArchiveMetaData jseArchiveMD, final JBossWebMetaData jbossWebMD, final JBossWebservicesMetaData jbossWebservicesMD) {
  104. if (jbossWebservicesMD != null) {
  105. if (jbossWebservicesMD.getConfigName() != null) {
  106. final String configName = jbossWebservicesMD.getConfigName();
  107. jseArchiveMD.setConfigName(configName);
  108. ROOT_LOGGER.settingConfigName(configName);
  109. final String configFile = jbossWebservicesMD.getConfigFile();
  110. jseArchiveMD.setConfigFile(configFile);
  111. ROOT_LOGGER.settingConfigFile(configFile);
  112. // ensure higher priority against web.xml context parameters
  113. return;
  114. }
  115. }
  116. final List<ParamValueMetaData> contextParams = jbossWebMD.getContextParams();
  117. if (contextParams != null) {
  118. for (final ParamValueMetaData contextParam : contextParams) {
  119. if (WSConstants.JBOSSWS_CONFIG_NAME.equals(contextParam.getParamName())) {
  120. final String configName = contextParam.getParamValue();
  121. jseArchiveMD.setConfigName(configName);
  122. ROOT_LOGGER.settingConfigName(configName);
  123. }
  124. if (WSConstants.JBOSSWS_CONFIG_FILE.equals(contextParam.getParamName())) {
  125. final String configFile = contextParam.getParamValue();
  126. jseArchiveMD.setConfigFile(configFile);
  127. ROOT_LOGGER.settingConfigFile(configFile);
  128. }
  129. }
  130. }
  131. }
  132. /**
  133. * Builds security meta data.
  134. *
  135. * @param securityConstraintsMD security constraints meta data
  136. * @return universal JSE security meta data model
  137. */
  138. private List<JSESecurityMetaData> getSecurityMetaData(final List<SecurityConstraintMetaData> securityConstraintsMD) {
  139. final List<JSESecurityMetaData> jseSecurityMDs = new LinkedList<JSESecurityMetaData>();
  140. if (securityConstraintsMD != null) {
  141. for (final SecurityConstraintMetaData securityConstraintMD : securityConstraintsMD) {
  142. final JSESecurityMetaData jseSecurityMD = new JSESecurityMetaData();
  143. // transport guarantee
  144. jseSecurityMD.setTransportGuarantee(securityConstraintMD.getTransportGuarantee().name());
  145. // web resources
  146. this.setWebResources(jseSecurityMD, securityConstraintMD);
  147. jseSecurityMDs.add(jseSecurityMD);
  148. }
  149. }
  150. return jseSecurityMDs;
  151. }
  152. /**
  153. * Sets web resources in universal meta data model.
  154. *
  155. * @param jseSecurityMD universal JSE security meta data model
  156. * @param securityConstraintMD security constraint meta data
  157. */
  158. private void setWebResources(final JSESecurityMetaData jseSecurityMD, final SecurityConstraintMetaData securityConstraintMD) {
  159. final WebResourceCollectionsMetaData webResources = securityConstraintMD.getResourceCollections();
  160. for (final WebResourceCollectionMetaData webResourceMD : webResources) {
  161. final JSEResourceCollection jseResource = jseSecurityMD.addWebResource(webResourceMD.getName());
  162. for (final String webResourceUrlPatterns : webResourceMD.getUrlPatterns()) {
  163. jseResource.addPattern(webResourceUrlPatterns);
  164. }
  165. }
  166. }
  167. /**
  168. * Returns servlet name to url pattern mappings.
  169. *
  170. * @param jbossWebMD jboss web meta data
  171. * @return servlet name to url pattern mappings
  172. */
  173. private Map<String, String> getServletUrlPatternsMappings(final JBossWebMetaData jbossWebMD, final List<POJOEndpoint> pojoEndpoints) {
  174. final Map<String, String> mappings = new HashMap<String, String>();
  175. final List<ServletMappingMetaData> servletMappings = WebMetaDataHelper.getServletMappings(jbossWebMD);
  176. for (final POJOEndpoint pojoEndpoint : pojoEndpoints) {
  177. mappings.put(pojoEndpoint.getName(), pojoEndpoint.getUrlPattern());
  178. if (!pojoEndpoint.isDeclared()) {
  179. final String endpointName = pojoEndpoint.getName();
  180. final List<String> urlPatterns = WebMetaDataHelper.getUrlPatterns(pojoEndpoint.getUrlPattern());
  181. WebMetaDataHelper.newServletMapping(endpointName, urlPatterns, servletMappings);
  182. }
  183. }
  184. return mappings;
  185. }
  186. /**
  187. * Returns servlet name to servlet class mappings.
  188. *
  189. * @param jbossWebMD jboss web meta data
  190. * @return servlet name to servlet mappings
  191. */
  192. private Map<String, String> getServletClassMappings(final JBossWebMetaData jbossWebMD, final List<POJOEndpoint> pojoEndpoints) {
  193. final Map<String, String> mappings = new HashMap<String, String>();
  194. final JBossServletsMetaData servlets = WebMetaDataHelper.getServlets(jbossWebMD);
  195. for (final POJOEndpoint pojoEndpoint : pojoEndpoints) {
  196. final String pojoName = pojoEndpoint.getName();
  197. final String pojoClassName = pojoEndpoint.getClassName();
  198. mappings.put(pojoName, pojoClassName);
  199. if (!pojoEndpoint.isDeclared()) {
  200. final String endpointName = pojoEndpoint.getName();
  201. final String endpointClassName = pojoEndpoint.getClassName();
  202. WebMetaDataHelper.newServlet(endpointName, endpointClassName, servlets);
  203. }
  204. }
  205. return mappings;
  206. }
  207. }