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
018 package org.apache.geronimo.axis2.ejb;
019
020 import java.net.URL;
021
022 import javax.naming.Context;
023 import javax.naming.InitialContext;
024 import javax.naming.NamingException;
025 import javax.xml.ws.WebServiceContext;
026 import javax.xml.ws.WebServiceException;
027
028 import org.apache.axis2.util.JavaUtils;
029 import org.apache.geronimo.axis2.Axis2WebServiceContainer;
030 import org.apache.geronimo.axis2.AxisServiceGenerator;
031 import org.apache.geronimo.jaxws.JAXWSAnnotationProcessor;
032 import org.apache.geronimo.jaxws.JNDIResolver;
033 import org.apache.geronimo.jaxws.PortInfo;
034 import org.apache.openejb.DeploymentInfo;
035
036 /**
037 * @version $Rev: 706640 $ $Date: 2008-10-21 14:44:05 +0000 (Tue, 21 Oct 2008) $
038 */
039 public class EJBWebServiceContainer extends Axis2WebServiceContainer {
040
041 private DeploymentInfo deploymnetInfo;
042
043 public EJBWebServiceContainer(PortInfo portInfo,
044 String endpointClassName,
045 ClassLoader classLoader,
046 Context context,
047 URL configurationBaseUrl,
048 DeploymentInfo deploymnetInfo) {
049 super(portInfo, endpointClassName, classLoader, context, configurationBaseUrl);
050 this.deploymnetInfo = deploymnetInfo;
051 }
052
053 @Override
054 public void init() throws Exception {
055 super.init();
056
057 String rootContext = null;
058 String servicePath = null;
059 String location = trimContext(this.portInfo.getLocation());
060 int pos = location.indexOf('/');
061 if (pos > 0) {
062 rootContext = location.substring(0, pos);
063 servicePath = location.substring(pos + 1);
064 } else {
065 rootContext = "/";
066 servicePath = location;
067 }
068
069 this.configurationContext.setServicePath(servicePath);
070 //need to setContextRoot after servicePath as cachedServicePath is only built
071 //when setContextRoot is called.
072 this.configurationContext.setContextRoot(rootContext);
073
074 // configure handlers
075 try {
076 configureHandlers();
077 } catch (Exception e) {
078 throw new WebServiceException("Error configuring handlers", e);
079 }
080 }
081
082 @Override
083 protected AxisServiceGenerator createServiceGenerator() {
084 AxisServiceGenerator serviceGenerator = super.createServiceGenerator();
085 EJBMessageReceiver messageReceiver =
086 new EJBMessageReceiver(this, this.endpointClass, this.deploymnetInfo);
087 serviceGenerator.setMessageReceiver(messageReceiver);
088 return serviceGenerator;
089 }
090
091 public synchronized void injectHandlers() {
092 if (this.annotationProcessor != null) {
093 // assume injection was already done
094 return;
095 }
096
097 WebServiceContext wsContext = null;
098 try {
099 InitialContext ctx = new InitialContext();
100 wsContext = (WebServiceContext) ctx.lookup("java:comp/WebServiceContext");
101 } catch (NamingException e) {
102 throw new WebServiceException("Failed to lookup WebServiceContext", e);
103 }
104
105 this.annotationProcessor = new JAXWSAnnotationProcessor(new JNDIResolver(), wsContext);
106 super.injectHandlers();
107 }
108
109 @Override
110 public void destroy() {
111 // call handler preDestroy
112 destroyHandlers();
113
114 super.destroy();
115 }
116 }