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