001: /**
002: *
003: * Licensed to the Apache Software Foundation (ASF) under one or more
004: * contributor license agreements. See the NOTICE file distributed with
005: * this work for additional information regarding copyright ownership.
006: * The ASF licenses this file to You under the Apache License, Version 2.0
007: * (the "License"); you may not use this file except in compliance with
008: * 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, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */package org.apache.openejb.server.cxf.ejb;
018:
019: import org.apache.cxf.Bus;
020: import org.apache.cxf.binding.soap.SoapBinding;
021: import org.apache.cxf.binding.soap.interceptor.MustUnderstandInterceptor;
022: import org.apache.cxf.binding.soap.saaj.SAAJInInterceptor;
023: import org.apache.cxf.endpoint.Endpoint;
024: import org.apache.cxf.interceptor.Interceptor;
025: import org.apache.cxf.jaxws.handler.logical.LogicalHandlerInInterceptor;
026: import org.apache.cxf.jaxws.handler.soap.SOAPHandlerInterceptor;
027: import org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean;
028: import org.apache.openejb.DeploymentInfo;
029: import org.apache.openejb.core.webservices.JaxWsUtils;
030: import org.apache.openejb.core.webservices.PortData;
031: import org.apache.openejb.server.cxf.CxfEndpoint;
032: import org.apache.openejb.server.cxf.CxfServiceConfiguration;
033: import org.apache.openejb.server.cxf.JaxWsImplementorInfoImpl;
034:
035: import javax.xml.ws.WebServiceException;
036: import java.util.List;
037:
038: /**
039: * A web service endpoint which invokes an EJB container.
040: */
041: public class EjbEndpoint extends CxfEndpoint {
042: private final DeploymentInfo deploymentInfo;
043:
044: public EjbEndpoint(Bus bus, PortData portData,
045: DeploymentInfo deploymentInfo) {
046: super (bus, portData, deploymentInfo.getJndiEnc(),
047: deploymentInfo.getBeanClass());
048: this .deploymentInfo = deploymentInfo;
049:
050: String bindingURI = JaxWsUtils.getBindingURI(portData
051: .getBindingID());
052: implInfo = new JaxWsImplementorInfoImpl((Class) implementor,
053: bindingURI);
054:
055: serviceFactory = new JaxWsServiceFactoryBean(implInfo);
056: serviceFactory.setBus(bus);
057:
058: // install as first to overwrite annotations (wsdl-file, wsdl-port, wsdl-service)
059: CxfServiceConfiguration configuration = new CxfServiceConfiguration(
060: portData);
061: serviceFactory.getConfigurations().add(0, configuration);
062:
063: service = serviceFactory.create();
064: }
065:
066: protected Class getImplementorClass() {
067: return (Class) this .implementor;
068: }
069:
070: protected void init() {
071: // configure handlers
072: try {
073: initHandlers();
074: } catch (Exception e) {
075: throw new WebServiceException("Error configuring handlers",
076: e);
077: }
078:
079: // Set service to invoke the target ejb
080: service.setInvoker(new EjbMethodInvoker(this .bus,
081: deploymentInfo));
082:
083: // Remove interceptors that perform handler processing since
084: // handler processing must happen within the EJB container.
085: Endpoint endpoint = getEndpoint();
086: removeHandlerInterceptors(bus.getInInterceptors());
087: removeHandlerInterceptors(endpoint.getInInterceptors());
088: removeHandlerInterceptors(endpoint.getBinding()
089: .getInInterceptors());
090: removeHandlerInterceptors(endpoint.getService()
091: .getInInterceptors());
092:
093: // Install SAAJ interceptor
094: if (endpoint.getBinding() instanceof SoapBinding
095: && !this .implInfo.isWebServiceProvider()) {
096: endpoint.getService().getInInterceptors().add(
097: new SAAJInInterceptor());
098: }
099: }
100:
101: private static void removeHandlerInterceptors(
102: List<Interceptor> interceptors) {
103: for (Interceptor interceptor : interceptors) {
104: if (interceptor instanceof MustUnderstandInterceptor
105: || interceptor instanceof LogicalHandlerInInterceptor
106: || interceptor instanceof SOAPHandlerInterceptor) {
107: interceptors.remove(interceptor);
108: }
109: }
110: }
111:
112: public void stop() {
113: // call handler preDestroy
114: destroyHandlers();
115:
116: // shutdown server
117: super.stop();
118: }
119: }
|