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.cxf.ejb;
017:
018: import java.net.URL;
019:
020: import javax.naming.Context;
021:
022: import org.apache.cxf.Bus;
023: import org.apache.geronimo.cxf.CXFCatalogUtils;
024: import org.apache.geronimo.cxf.CXFWebServiceContainer;
025: import org.apache.geronimo.gbean.GBeanInfo;
026: import org.apache.geronimo.gbean.GBeanInfoBuilder;
027: import org.apache.geronimo.gbean.GBeanLifecycle;
028: import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
029: import org.apache.geronimo.jaxws.JNDIResolver;
030: import org.apache.geronimo.jaxws.PortInfo;
031: import org.apache.geronimo.jaxws.ServerJNDIResolver;
032: import org.apache.geronimo.kernel.Kernel;
033: import org.apache.geronimo.openejb.EjbDeployment;
034: import org.apache.geronimo.webservices.SoapHandler;
035: import org.apache.openejb.DeploymentInfo;
036:
037: public class EJBWebServiceGBean implements GBeanLifecycle {
038:
039: private SoapHandler soapHandler;
040: private String location;
041: private EJBWebServiceContainer container;
042:
043: public EJBWebServiceGBean(EjbDeployment ejbDeploymentContext,
044: PortInfo portInfo, Kernel kernel, URL configurationBaseUrl,
045: SoapHandler soapHandler, String securityRealmName,
046: String realmName, String transportGuarantee,
047: String authMethod, String[] virtualHosts) throws Exception {
048: if (ejbDeploymentContext == null || soapHandler == null
049: || portInfo == null) {
050: return;
051: }
052:
053: this .soapHandler = soapHandler;
054: this .location = portInfo.getLocation();
055:
056: assert this .location != null : "null location received";
057:
058: Class beanClass = ejbDeploymentContext.getBeanClass();
059: Context context = ejbDeploymentContext.getComponentContext();
060:
061: Bus bus = CXFWebServiceContainer.getBus();
062: bus.setExtension(new ServerJNDIResolver(context),
063: JNDIResolver.class);
064: bus.setExtension(portInfo, PortInfo.class);
065: bus.setExtension(ejbDeploymentContext.getDeploymentInfo(),
066: DeploymentInfo.class);
067:
068: CXFCatalogUtils.loadOASISCatalog(bus, configurationBaseUrl,
069: "META-INF/jax-ws-catalog.xml");
070:
071: this .container = new EJBWebServiceContainer(bus,
072: configurationBaseUrl, beanClass);
073:
074: ClassLoader classLoader = ejbDeploymentContext.getClassLoader();
075: if (soapHandler != null) {
076: soapHandler.addWebService(this .location, virtualHosts,
077: this .container, securityRealmName, realmName,
078: transportGuarantee, authMethod, classLoader);
079: }
080:
081: }
082:
083: public void doStart() throws Exception {
084: }
085:
086: public void doStop() throws Exception {
087: if (this .soapHandler != null) {
088: this .soapHandler.removeWebService(this .location);
089: }
090: if (this .container != null) {
091: this .container.destroy();
092: }
093: }
094:
095: public void doFail() {
096: }
097:
098: public static final GBeanInfo GBEAN_INFO;
099:
100: static {
101: GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic(
102: EJBWebServiceGBean.class, EJBWebServiceGBean.class,
103: NameFactory.WEB_SERVICE_LINK);
104:
105: infoFactory.addReference("EjbDeployment", EjbDeployment.class);
106: infoFactory.addAttribute("portInfo", PortInfo.class, true);
107: infoFactory.addAttribute("kernel", Kernel.class, false);
108: infoFactory.addAttribute("configurationBaseUrl", URL.class,
109: true);
110: infoFactory.addAttribute("securityRealmName", String.class,
111: true);
112: infoFactory.addAttribute("realmName", String.class, true);
113: infoFactory.addAttribute("transportGuarantee", String.class,
114: true);
115: infoFactory.addAttribute("authMethod", String.class, true);
116: infoFactory.addAttribute("virtualHosts", String[].class, true);
117: infoFactory.addReference("WebServiceContainer",
118: SoapHandler.class);
119:
120: infoFactory.setConstructor(new String[] { "EjbDeployment",
121: "portInfo", "kernel", "configurationBaseUrl",
122: "WebServiceContainer", "securityRealmName",
123: "realmName", "transportGuarantee", "authMethod",
124: "virtualHosts" });
125:
126: GBEAN_INFO = infoFactory.getBeanInfo();
127: }
128:
129: public static GBeanInfo getGBeanInfo() {
130: return GBEAN_INFO;
131: }
132:
133: }
|