PageRenderTime 49ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/jboss-as-7.1.1.Final/webservices/server-integration/src/main/java/org/jboss/as/webservices/dmr/WSSubsystemAdd.java

#
Java | 159 lines | 108 code | 22 blank | 29 comment | 13 complexity | 3413a08126591bd94fedbff22c4fb936 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, Inc., 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.dmr;
  23. import org.jboss.as.controller.PathAddress;
  24. import static org.jboss.as.webservices.WSLogger.ROOT_LOGGER;
  25. import static org.jboss.as.webservices.dmr.Constants.ENDPOINT;
  26. import static org.jboss.as.webservices.dmr.Constants.ENDPOINT_CONFIG;
  27. import static org.jboss.as.webservices.dmr.Constants.MODIFY_WSDL_ADDRESS;
  28. import static org.jboss.as.webservices.dmr.Constants.WSDL_HOST;
  29. import static org.jboss.as.webservices.dmr.Constants.WSDL_PORT;
  30. import static org.jboss.as.webservices.dmr.Constants.WSDL_SECURE_PORT;
  31. import java.net.UnknownHostException;
  32. import java.util.List;
  33. import org.jboss.as.controller.AbstractBoottimeAddStepHandler;
  34. import org.jboss.as.controller.OperationContext;
  35. import org.jboss.as.controller.OperationFailedException;
  36. import org.jboss.as.controller.PathElement;
  37. import org.jboss.as.controller.ProcessType;
  38. import org.jboss.as.controller.ServiceVerificationHandler;
  39. import org.jboss.as.controller.operations.validation.ModelTypeValidator;
  40. import org.jboss.as.controller.operations.validation.ParametersValidator;
  41. import org.jboss.as.controller.registry.Resource;
  42. import org.jboss.as.server.AbstractDeploymentChainStep;
  43. import org.jboss.as.server.DeploymentProcessorTarget;
  44. import org.jboss.as.webservices.config.ServerConfigImpl;
  45. import org.jboss.as.webservices.service.EndpointRegistryService;
  46. import org.jboss.as.webservices.service.PortComponentLinkService;
  47. import org.jboss.as.webservices.service.ServerConfigService;
  48. import org.jboss.as.webservices.util.ModuleClassLoaderProvider;
  49. import org.jboss.as.webservices.util.WSServices;
  50. import org.jboss.dmr.ModelNode;
  51. import org.jboss.dmr.ModelType;
  52. import org.jboss.msc.service.ServiceController;
  53. import org.jboss.msc.service.ServiceTarget;
  54. /**
  55. * @author alessio.soldano@jboss.com
  56. * @author <a href="mailto:darran.lofthouse@jboss.com">Darran Lofthouse</a>
  57. * @author <a href="mailto:ropalka@redhat.com">Richard Opalka</a>
  58. */
  59. public class WSSubsystemAdd extends AbstractBoottimeAddStepHandler {
  60. static final WSSubsystemAdd INSTANCE = new WSSubsystemAdd();
  61. private final ParametersValidator configValidator = new ParametersValidator();
  62. // Private to ensure a singleton.
  63. private WSSubsystemAdd() {
  64. configValidator.registerValidator(WSDL_HOST, new ModelTypeValidator(ModelType.STRING, true, true));
  65. configValidator.registerValidator(MODIFY_WSDL_ADDRESS, new ModelTypeValidator(ModelType.BOOLEAN));
  66. configValidator.registerValidator(WSDL_PORT, new ModelTypeValidator(ModelType.INT, true, true));
  67. configValidator.registerValidator(WSDL_SECURE_PORT, new ModelTypeValidator(ModelType.INT, true, true));
  68. }
  69. protected void populateModel(final OperationContext context, final ModelNode operation, final Resource resource) throws OperationFailedException {
  70. final boolean appclient = context.getProcessType() == ProcessType.APPLICATION_CLIENT;
  71. final ModelNode submodel = resource.getModel();
  72. if (operation.hasDefined(WSDL_PORT)) {
  73. submodel.get(WSDL_PORT).set(operation.require(WSDL_PORT));
  74. }
  75. if (operation.hasDefined(WSDL_SECURE_PORT)) {
  76. submodel.get(WSDL_SECURE_PORT).set(operation.require(WSDL_SECURE_PORT));
  77. }
  78. if (appclient && operation.hasDefined(WSDL_HOST)) {
  79. submodel.get(WSDL_HOST).setExpression(operation.require(WSDL_HOST).asString());
  80. }
  81. if (!appclient) {
  82. submodel.get(WSDL_HOST).setExpression(operation.require(WSDL_HOST).asString());
  83. configValidator.validate(operation);
  84. submodel.get(MODIFY_WSDL_ADDRESS).set(operation.require(MODIFY_WSDL_ADDRESS));
  85. submodel.get(ENDPOINT_CONFIG).setEmptyObject();
  86. submodel.get(ENDPOINT).setEmptyObject();
  87. }
  88. }
  89. @Override
  90. protected void populateModel(final ModelNode operation, final ModelNode model) throws OperationFailedException {
  91. //NOOP this is not actually used
  92. }
  93. protected void performBoottime(OperationContext context, ModelNode operation, ModelNode model, ServiceVerificationHandler verificationHandler, List<ServiceController<?>> newControllers) {
  94. ROOT_LOGGER.activatingWebservicesExtension();
  95. ModuleClassLoaderProvider.register();
  96. final boolean appclient = context.getProcessType() == ProcessType.APPLICATION_CLIENT;
  97. context.addStep(new AbstractDeploymentChainStep() {
  98. protected void execute(DeploymentProcessorTarget processorTarget) {
  99. // add the DUP for dealing with WS deployments
  100. WSDeploymentActivator.activate(processorTarget, appclient);
  101. }
  102. }, OperationContext.Stage.RUNTIME);
  103. WSServices.saveContainerRegistry(context.getServiceRegistry(false));
  104. ServiceTarget serviceTarget = context.getServiceTarget();
  105. if (appclient && model.hasDefined(WSDL_HOST)) {
  106. ServerConfigImpl serverConfig = createServerConfig(model, true);
  107. newControllers.add(ServerConfigService.install(serviceTarget, serverConfig, verificationHandler));
  108. }
  109. if (!appclient) {
  110. ServerConfigImpl serverConfig = createServerConfig(model, false);
  111. newControllers.add(ServerConfigService.install(serviceTarget, serverConfig, verificationHandler));
  112. newControllers.add(EndpointRegistryService.install(serviceTarget, verificationHandler));
  113. final Resource webSubsystem = context.readResourceFromRoot(PathAddress.pathAddress(PathElement.pathElement("subsystem", "web")));
  114. String defaultHost = webSubsystem.getModel().get("default-virtual-server").asString();
  115. newControllers.add(PortComponentLinkService.install(serviceTarget, defaultHost, verificationHandler));
  116. }
  117. }
  118. private static ServerConfigImpl createServerConfig(ModelNode configuration, boolean appclient) {
  119. final ServerConfigImpl config = ServerConfigImpl.newInstance();
  120. try {
  121. ModelNode wsdlHost = configuration.require(WSDL_HOST).resolve();
  122. config.setWebServiceHost(wsdlHost.asString());
  123. } catch (UnknownHostException e) {
  124. throw new RuntimeException(e);
  125. }
  126. if (!appclient) {
  127. config.setModifySOAPAddress(configuration.require(MODIFY_WSDL_ADDRESS).asBoolean());
  128. }
  129. if (configuration.hasDefined(WSDL_PORT)) {
  130. config.setWebServicePort(configuration.require(WSDL_PORT).asInt());
  131. }
  132. if (configuration.hasDefined(WSDL_SECURE_PORT)) {
  133. config.setWebServiceSecurePort(configuration.require(WSDL_SECURE_PORT).asInt());
  134. }
  135. return config;
  136. }
  137. }