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