Home » openejb-3.1.2-src » org.apache » openejb » server » cxf » ejb » [javadoc | source]

    1   /**
    2    *
    3    * Licensed to the Apache Software Foundation (ASF) under one or more
    4    * contributor license agreements.  See the NOTICE file distributed with
    5    * this work for additional information regarding copyright ownership.
    6    * The ASF licenses this file to You under the Apache License, Version 2.0
    7    * (the "License"); you may not use this file except in compliance with
    8    * the License.  You may obtain a copy of the License at
    9    *
   10    *     http://www.apache.org/licenses/LICENSE-2.0
   11    *
   12    *  Unless required by applicable law or agreed to in writing, software
   13    *  distributed under the License is distributed on an "AS IS" BASIS,
   14    *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   15    *  See the License for the specific language governing permissions and
   16    *  limitations under the License.
   17    */
   18   package org.apache.openejb.server.cxf.ejb;
   19   
   20   import org.apache.cxf.Bus;
   21   import org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor;
   22   import org.apache.cxf.binding.soap.SoapBinding;
   23   import org.apache.cxf.binding.soap.interceptor.MustUnderstandInterceptor;
   24   import org.apache.cxf.binding.soap.saaj.SAAJInInterceptor;
   25   import org.apache.cxf.endpoint.Endpoint;
   26   import org.apache.cxf.interceptor.Interceptor;
   27   import org.apache.cxf.jaxws.handler.logical.LogicalHandlerInInterceptor;
   28   import org.apache.cxf.jaxws.handler.soap.SOAPHandlerInterceptor;
   29   import org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean;
   30   import org.apache.openejb.DeploymentInfo;
   31   import org.apache.openejb.core.webservices.JaxWsUtils;
   32   import org.apache.openejb.core.webservices.PortData;
   33   import org.apache.openejb.server.cxf.ConfigureCxfSecurity;
   34   import org.apache.openejb.server.cxf.CxfEndpoint;
   35   import org.apache.openejb.server.cxf.CxfServiceConfiguration;
   36   import org.apache.openejb.server.cxf.JaxWsImplementorInfoImpl;
   37   import org.apache.openejb.server.cxf.ServerPasswordHandler;
   38   import org.apache.ws.security.handler.WSHandlerConstants;
   39   import org.apache.ws.security.WSConstants;
   40   
   41   import javax.xml.ws.WebServiceException;
   42   import java.util.List;
   43   import java.util.Map;
   44   import java.util.HashMap;
   45   
   46   /**
   47    * A web service endpoint which invokes an EJB container.
   48    */
   49   public class EjbEndpoint extends CxfEndpoint {
   50       private final DeploymentInfo deploymentInfo;
   51   
   52       public EjbEndpoint(Bus bus, PortData portData, DeploymentInfo deploymentInfo) {
   53           super(bus, portData, deploymentInfo.getJndiEnc(), deploymentInfo.getBeanClass());
   54           this.deploymentInfo = deploymentInfo;
   55   
   56           String bindingURI = JaxWsUtils.getBindingURI(portData.getBindingID());
   57           implInfo = new JaxWsImplementorInfoImpl((Class) implementor, bindingURI);
   58   
   59           serviceFactory = new JaxWsServiceFactoryBean(implInfo);
   60           serviceFactory.setBus(bus);
   61   
   62           // install as first to overwrite annotations (wsdl-file, wsdl-port, wsdl-service)
   63           CxfServiceConfiguration configuration = new CxfServiceConfiguration(portData);
   64           serviceFactory.getConfigurations().add(0, configuration);
   65   
   66           service = serviceFactory.create();
   67       }
   68   
   69       protected Class getImplementorClass() {
   70           return (Class) this.implementor;
   71       }
   72   
   73       protected void init() {
   74           // configure handlers
   75           try {
   76               initHandlers();
   77           } catch (Exception e) {
   78               throw new WebServiceException("Error configuring handlers", e);
   79           }
   80   
   81           // Set service to invoke the target ejb
   82           service.setInvoker(new EjbMethodInvoker(this.bus, deploymentInfo));
   83   
   84           // Remove interceptors that perform handler processing since
   85           // handler processing must happen within the EJB container.
   86           Endpoint endpoint = getEndpoint();
   87           removeHandlerInterceptors(bus.getInInterceptors());
   88           removeHandlerInterceptors(endpoint.getInInterceptors());
   89           removeHandlerInterceptors(endpoint.getBinding().getInInterceptors());
   90           removeHandlerInterceptors(endpoint.getService().getInInterceptors());
   91   
   92           // Install SAAJ interceptor
   93           if (endpoint.getBinding() instanceof SoapBinding && !this.implInfo.isWebServiceProvider()) {
   94               endpoint.getService().getInInterceptors().add(new SAAJInInterceptor());
   95           }
   96   
   97           // Install WSS4J interceptor
   98           if (port.isSecure()) {
   99               ConfigureCxfSecurity.configure(endpoint, port.getSecurityProperties());
  100           }
  101   
  102       }
  103   
  104       private static void removeHandlerInterceptors(List<Interceptor> interceptors) {
  105           for (Interceptor interceptor : interceptors) {
  106               if (interceptor instanceof MustUnderstandInterceptor || interceptor instanceof LogicalHandlerInInterceptor || 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   }

Home » openejb-3.1.2-src » org.apache » openejb » server » cxf » ejb » [javadoc | source]