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