001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.geronimo.axis.builder;
017:
018: import java.net.URL;
019: import java.util.Collection;
020: import java.util.HashMap;
021: import java.util.List;
022: import java.util.Map;
023: import java.util.jar.JarFile;
024:
025: import org.apache.geronimo.axis.server.EjbWebServiceGBean;
026: import org.apache.geronimo.common.DeploymentException;
027: import org.apache.geronimo.deployment.ModuleIDBuilder;
028: import org.apache.geronimo.deployment.service.EnvironmentBuilder;
029: import org.apache.geronimo.gbean.AbstractName;
030: import org.apache.geronimo.gbean.AbstractNameQuery;
031: import org.apache.geronimo.gbean.GBeanData;
032: import org.apache.geronimo.gbean.GBeanInfo;
033: import org.apache.geronimo.gbean.GBeanInfoBuilder;
034: import org.apache.geronimo.j2ee.deployment.EARContext;
035: import org.apache.geronimo.j2ee.deployment.Module;
036: import org.apache.geronimo.j2ee.deployment.ModuleBuilderExtension;
037: import org.apache.geronimo.j2ee.deployment.WebServiceBuilder;
038: import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
039: import org.apache.geronimo.kernel.GBeanAlreadyExistsException;
040: import org.apache.geronimo.kernel.Naming;
041: import org.apache.geronimo.kernel.config.ConfigurationModuleType;
042: import org.apache.geronimo.kernel.config.ConfigurationStore;
043: import org.apache.geronimo.kernel.repository.Environment;
044: import org.apache.geronimo.openejb.deployment.EjbModule;
045: import org.apache.openejb.assembler.classic.EnterpriseBeanInfo;
046: import org.apache.openejb.jee.oejb2.GeronimoEjbJarType;
047: import org.apache.openejb.jee.oejb2.WebServiceBindingType;
048: import org.apache.openejb.jee.oejb2.WebServiceBindingType.WebServiceSecurityType;
049:
050: /**
051: * @version $Rev$ $Date$
052: */
053: public class AxisModuleBuilderExtension implements
054: ModuleBuilderExtension {
055:
056: private WebServiceBuilder axisBuilder;
057: private Environment defaultEnvironment;
058: private AbstractNameQuery listener;
059:
060: public AxisModuleBuilderExtension() {
061: this (null, null, null);
062: }
063:
064: public AxisModuleBuilderExtension(WebServiceBuilder wsBuilder,
065: Environment defaultEnvironment, AbstractNameQuery listener) {
066: this .axisBuilder = wsBuilder;
067: this .defaultEnvironment = defaultEnvironment;
068: this .listener = listener;
069: }
070:
071: public void createModule(Module module, Object plan,
072: JarFile moduleFile, String targetPath, URL specDDUrl,
073: Environment environment, Object moduleContextInfo,
074: AbstractName earName, Naming naming,
075: ModuleIDBuilder idBuilder) throws DeploymentException {
076: if (module.getType() != ConfigurationModuleType.EJB) {
077: return;
078: }
079:
080: EjbModule ejbModule = (EjbModule) module;
081:
082: //overridden web service locations
083: Map correctedPortLocations = new HashMap();
084: GeronimoEjbJarType geronimoEjbJarType = (GeronimoEjbJarType) ejbModule
085: .getEjbModule().getAltDDs().get("geronimo-openejb.xml");
086: if (geronimoEjbJarType != null) {
087: for (WebServiceBindingType bt : geronimoEjbJarType
088: .getWebServiceBinding()) {
089: String location = bt.getWebServiceAddress();
090: if (location != null) {
091: location = location.trim();
092: if (!location.startsWith("/")) {
093: location = "/" + location;
094: }
095: correctedPortLocations.put(bt.getEjbName(),
096: location);
097: }
098: }
099: }
100:
101: axisBuilder.findWebServices(module, true,
102: correctedPortLocations, environment, ejbModule
103: .getSharedContext());
104:
105: if (this .defaultEnvironment != null) {
106: EnvironmentBuilder.mergeEnvironments(environment,
107: this .defaultEnvironment);
108: }
109: }
110:
111: public void installModule(JarFile earFile, EARContext earContext,
112: Module module, Collection configurationStores,
113: ConfigurationStore targetConfigurationStore,
114: Collection repository) throws DeploymentException {
115: }
116:
117: public void initContext(EARContext earContext, Module module,
118: ClassLoader cl) throws DeploymentException {
119: }
120:
121: public void addGBeans(EARContext earContext, Module module,
122: ClassLoader cl, Collection repository)
123: throws DeploymentException {
124: if (module.getType() != ConfigurationModuleType.EJB) {
125: return;
126: }
127:
128: EjbModule ejbModule = (EjbModule) module;
129:
130: Map<String, WebServiceBindingType> wsBindingMap = createWebServiceBindingMap(ejbModule);
131:
132: for (EnterpriseBeanInfo bean : ejbModule.getEjbJarInfo().enterpriseBeans) {
133: if (bean.type != EnterpriseBeanInfo.STATELESS) {
134: continue;
135: }
136: String ejbName = bean.ejbName;
137:
138: AbstractName sessionName = earContext.getNaming()
139: .createChildName(module.getModuleName(), ejbName,
140: NameFactory.STATELESS_SESSION_BEAN);
141:
142: assert sessionName != null : "StatelesSessionBean object name is null";
143:
144: AbstractName ejbWebServiceName = earContext.getNaming()
145: .createChildName(sessionName, ejbName,
146: NameFactory.WEB_SERVICE_LINK);
147:
148: GBeanData ejbWebServiceGBean = new GBeanData(
149: ejbWebServiceName, EjbWebServiceGBean.GBEAN_INFO);
150:
151: ejbWebServiceGBean.setAttribute("ejbName", ejbName);
152: ejbWebServiceGBean.setAttribute("ejbClass", bean.ejbClass);
153:
154: WebServiceBindingType wsBinding = wsBindingMap.get(ejbName);
155: if (wsBinding != null) {
156: List<String> ddVirtualHosts = wsBinding
157: .getWebServiceVirtualHost();
158: if (ddVirtualHosts != null) {
159: String[] virtualHosts = new String[ddVirtualHosts
160: .size()];
161: for (int i = 0; i < ddVirtualHosts.size(); i++) {
162: virtualHosts[i] = ddVirtualHosts.get(i).trim();
163: }
164: ejbWebServiceGBean.setAttribute("virtualHosts",
165: virtualHosts);
166: }
167:
168: WebServiceSecurityType wsSecurity = wsBinding
169: .getWebServiceSecurity();
170: if (wsSecurity != null) {
171: ejbWebServiceGBean.setAttribute(
172: "securityRealmName", wsSecurity
173: .getSecurityRealmName().trim());
174: ejbWebServiceGBean
175: .setAttribute("transportGuarantee",
176: wsSecurity.getTransportGuarantee()
177: .toString());
178: ejbWebServiceGBean.setAttribute("authMethod",
179: wsSecurity.getAuthMethod().value());
180: if (wsSecurity.getRealmName() != null) {
181: ejbWebServiceGBean.setAttribute("realmName",
182: wsSecurity.getRealmName().trim());
183: }
184: }
185: }
186:
187: if (axisBuilder.configureEJB(ejbWebServiceGBean, ejbName,
188: ejbModule, ejbModule.getSharedContext(), cl)) {
189:
190: try {
191: earContext.addGBean(ejbWebServiceGBean);
192: } catch (GBeanAlreadyExistsException e) {
193: throw new DeploymentException(
194: "Could not add axis ejb web service gbean to context",
195: e);
196: }
197:
198: if (this .listener != null) {
199: ejbWebServiceGBean.setReferencePattern(
200: "WebServiceContainer", this .listener);
201: }
202:
203: ejbWebServiceGBean.setReferencePattern("EjbDeployment",
204: sessionName);
205: }
206:
207: ejbWebServiceGBean.clearAttribute("ejbName");
208: ejbWebServiceGBean.clearAttribute("ejbClass");
209:
210: }
211: }
212:
213: private Map<String, WebServiceBindingType> createWebServiceBindingMap(
214: EjbModule ejbModule) {
215: Map<String, WebServiceBindingType> wsBindingMap = new HashMap<String, WebServiceBindingType>();
216: GeronimoEjbJarType geronimoEjbJarType = (GeronimoEjbJarType) ejbModule
217: .getEjbModule().getAltDDs().get("geronimo-openejb.xml");
218: if (geronimoEjbJarType != null) {
219: for (WebServiceBindingType bt : geronimoEjbJarType
220: .getWebServiceBinding()) {
221: wsBindingMap.put(bt.getEjbName(), bt);
222: }
223: }
224: return wsBindingMap;
225: }
226:
227: public static final GBeanInfo GBEAN_INFO;
228:
229: static {
230: GBeanInfoBuilder infoBuilder = GBeanInfoBuilder.createStatic(
231: AxisModuleBuilderExtension.class,
232: NameFactory.MODULE_BUILDER);
233: infoBuilder.addInterface(ModuleBuilderExtension.class);
234: infoBuilder.addReference("WebServiceBuilder",
235: WebServiceBuilder.class, NameFactory.MODULE_BUILDER);
236: infoBuilder.addAttribute("defaultEnvironment",
237: Environment.class, true, true);
238: infoBuilder.addAttribute("listener", AbstractNameQuery.class,
239: true);
240:
241: infoBuilder.setConstructor(new String[] { "WebServiceBuilder",
242: "defaultEnvironment", "listener" });
243:
244: GBEAN_INFO = infoBuilder.getBeanInfo();
245: }
246:
247: public static GBeanInfo getGBeanInfo() {
248: return GBEAN_INFO;
249: }
250:
251: }
|