001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */package org.apache.geronimo.cxf.ejb;
019:
020: import java.net.URL;
021: import java.util.List;
022:
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.cxf.Bus;
029: import org.apache.cxf.binding.soap.SoapBinding;
030: import org.apache.cxf.binding.soap.interceptor.MustUnderstandInterceptor;
031: import org.apache.cxf.binding.soap.saaj.SAAJInInterceptor;
032: import org.apache.cxf.endpoint.Endpoint;
033: import org.apache.cxf.interceptor.Interceptor;
034: import org.apache.cxf.jaxws.handler.logical.LogicalHandlerInInterceptor;
035: import org.apache.cxf.jaxws.handler.soap.SOAPHandlerInterceptor;
036: import org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean;
037: import org.apache.geronimo.cxf.CXFEndpoint;
038: import org.apache.geronimo.cxf.CXFServiceConfiguration;
039: import org.apache.geronimo.cxf.GeronimoJaxWsImplementorInfo;
040: import org.apache.geronimo.jaxws.JAXWSAnnotationProcessor;
041: import org.apache.geronimo.jaxws.JNDIResolver;
042: import org.apache.openejb.DeploymentInfo;
043:
044: public class EJBEndpoint extends CXFEndpoint {
045:
046: public EJBEndpoint(Bus bus, URL configurationBaseUrl, Class instance) {
047: super (bus, instance);
048:
049: implInfo = new GeronimoJaxWsImplementorInfo(instance,
050: this .portInfo, instance.getClassLoader());
051:
052: serviceFactory = new JaxWsServiceFactoryBean(implInfo);
053: serviceFactory.setBus(bus);
054:
055: String wsdlLocation = null;
056: if (this .portInfo.getWsdlFile() != null) {
057: wsdlLocation = this .portInfo.getWsdlFile();
058: } else {
059: wsdlLocation = implInfo.getWsdlLocation();
060: }
061: URL wsdlURL = getWsdlURL(configurationBaseUrl, wsdlLocation);
062:
063: // install as first to overwrite annotations (wsdl-file, wsdl-port, wsdl-service)
064: CXFServiceConfiguration configuration = new CXFServiceConfiguration(
065: this .portInfo, wsdlURL);
066: serviceFactory.getConfigurations().add(0, configuration);
067:
068: service = serviceFactory.create();
069: }
070:
071: protected Class getImplementorClass() {
072: return (Class) this .implementor;
073: }
074:
075: protected void init() {
076: // configure handlers
077: try {
078: initHandlers();
079: } catch (Exception e) {
080: throw new WebServiceException("Error configuring handlers",
081: e);
082: }
083:
084: DeploymentInfo deploymentInfo = (DeploymentInfo) bus
085: .getExtension(DeploymentInfo.class);
086:
087: service.setInvoker(new EJBMethodInvoker(this , this .bus,
088: deploymentInfo));
089:
090: Endpoint endpoint = getEndpoint();
091:
092: /*
093: * Remove interceptors that perform handler processing since
094: * handler processing must happen within the EJB container.
095: */
096: removeHandlerInterceptors(bus.getInInterceptors());
097: removeHandlerInterceptors(endpoint.getInInterceptors());
098: removeHandlerInterceptors(endpoint.getBinding()
099: .getInInterceptors());
100: removeHandlerInterceptors(endpoint.getService()
101: .getInInterceptors());
102:
103: // install SAAJ interceptor
104: if (endpoint.getBinding() instanceof SoapBinding
105: && !this .implInfo.isWebServiceProvider()) {
106: endpoint.getService().getInInterceptors().add(
107: new SAAJInInterceptor());
108: }
109: }
110:
111: private static void removeHandlerInterceptors(
112: List<Interceptor> interceptors) {
113: for (Interceptor interceptor : interceptors) {
114: if (interceptor instanceof MustUnderstandInterceptor
115: || interceptor instanceof LogicalHandlerInInterceptor
116: || interceptor instanceof SOAPHandlerInterceptor) {
117: interceptors.remove(interceptor);
118: }
119: }
120: }
121:
122: public synchronized void injectHandlers() {
123: if (this .annotationProcessor != null) {
124: // assume injection was already done
125: return;
126: }
127:
128: WebServiceContext wsContext = null;
129: try {
130: InitialContext ctx = new InitialContext();
131: wsContext = (WebServiceContext) ctx
132: .lookup("java:comp/WebServiceContext");
133: } catch (NamingException e) {
134: throw new WebServiceException(
135: "Failed to lookup WebServiceContext", e);
136: }
137:
138: this .annotationProcessor = new JAXWSAnnotationProcessor(
139: new JNDIResolver(), wsContext);
140: super .injectHandlers();
141: }
142:
143: public void stop() {
144: // call handler preDestroy
145: destroyHandlers();
146:
147: // shutdown server
148: super.stop();
149: }
150:
151: }
|