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.axis.server;
018    
019    import org.apache.axis.description.JavaServiceDesc;
020    import org.apache.axis.handlers.soap.SOAPService;
021    import org.apache.axis.providers.java.RPCProvider;
022    import org.apache.geronimo.gbean.GBeanInfo;
023    import org.apache.geronimo.gbean.GBeanInfoBuilder;
024    import org.apache.geronimo.gbean.GBeanLifecycle;
025    import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
026    import org.apache.geronimo.openejb.EjbDeployment;
027    import org.apache.geronimo.webservices.SoapHandler;
028    import org.apache.openejb.server.axis.EjbContainerProvider;
029    
030    import java.net.URI;
031    
032    public class EjbWebServiceGBean implements GBeanLifecycle {
033    
034        private final SoapHandler soapHandler;
035        private final URI location;
036    
037        protected EjbWebServiceGBean() {
038            soapHandler = null;
039            location = null;
040        }
041    
042        public EjbWebServiceGBean(EjbDeployment ejbDeploymentContext,
043                                  URI location,
044                                  URI wsdlURI,
045                                  SoapHandler soapHandler,
046                                  ServiceInfo serviceInfo,
047                                  String securityRealmName,
048                                  String realmName,
049                                  String transportGuarantee,
050                                  String authMethod,
051                                  String[] virtualHosts) throws Exception {
052    
053            this.soapHandler = soapHandler;
054            this.location = location;
055                            
056            //for use as a template
057            if (ejbDeploymentContext == null) {
058                return;
059            }
060            RPCProvider provider = new EjbContainerProvider(ejbDeploymentContext.getDeploymentInfo(), serviceInfo.getHandlerInfos());
061            SOAPService service = new SOAPService(null, provider, null);
062    
063            JavaServiceDesc serviceDesc = serviceInfo.getServiceDesc();
064            service.setServiceDescription(serviceDesc);
065            
066            ClassLoader classLoader = ejbDeploymentContext.getClassLoader();
067                    
068            Class serviceEndpointInterface = 
069                classLoader.loadClass(ejbDeploymentContext.getServiceEndpointInterfaceName());
070            
071            service.setOption("className", serviceEndpointInterface.getName());
072            serviceDesc.setImplClass(serviceEndpointInterface);
073            
074            AxisWebServiceContainer axisContainer = new AxisWebServiceContainer(location, wsdlURI, service, serviceInfo.getWsdlMap(), classLoader);
075            if (soapHandler != null) {
076                soapHandler.addWebService(location.getPath(), virtualHosts, axisContainer, securityRealmName, realmName, transportGuarantee, authMethod, classLoader);
077            }
078        }
079    
080        public void doStart() throws Exception {
081    
082        }
083    
084        public void doStop() throws Exception {
085            if (soapHandler != null) {
086                soapHandler.removeWebService(location.getPath());
087            }
088        }
089    
090        public void doFail() {
091    
092        }
093    
094        public static final GBeanInfo GBEAN_INFO;
095    
096        static {
097            GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic(EjbWebServiceGBean.class, EjbWebServiceGBean.class, NameFactory.WEB_SERVICE_LINK);
098    
099    //        infoFactory.addOperation("invoke", new Class[]{WebServiceContainer.Request.class, WebServiceContainer.Response.class});
100    
101            infoFactory.addReference("EjbDeployment", EjbDeployment.class);
102            infoFactory.addAttribute("location", URI.class, true);
103            infoFactory.addAttribute("wsdlURI", URI.class, true);
104            infoFactory.addAttribute("securityRealmName", String.class, true);
105            infoFactory.addAttribute("realmName", String.class, true);
106            infoFactory.addAttribute("transportGuarantee", String.class, true);
107            infoFactory.addAttribute("authMethod", String.class, true);
108            infoFactory.addAttribute("serviceInfo", ServiceInfo.class, true);
109            infoFactory.addAttribute("virtualHosts", String[].class, true);
110            infoFactory.addReference("WebServiceContainer", SoapHandler.class);
111    
112            infoFactory.setConstructor(new String[]{
113                    "EjbDeployment",
114                    "location",
115                    "wsdlURI",
116                    "WebServiceContainer",
117                    "serviceInfo",
118                    "securityRealmName",
119                    "realmName",
120                    "transportGuarantee",
121                    "authMethod",
122                    "virtualHosts"
123            });
124    
125            GBEAN_INFO = infoFactory.getBeanInfo();
126        }
127    
128        public static GBeanInfo getGBeanInfo() {
129            return GBEAN_INFO;
130        }
131    
132    
133    }