Home » openejb-3.1.2-src » org.apache » openejb » server » axis » [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.axis;
   19   
   20   import org.apache.axis.description.JavaServiceDesc;
   21   import org.apache.axis.handlers.HandlerInfoChainFactory;
   22   import org.apache.axis.handlers.soap.SOAPService;
   23   import org.apache.axis.providers.java.RPCProvider;
   24   import org.apache.openejb.DeploymentInfo;
   25   import org.apache.openejb.OpenEJBException;
   26   import org.apache.openejb.core.webservices.HandlerChainData;
   27   import org.apache.openejb.core.webservices.HandlerData;
   28   import org.apache.openejb.core.webservices.PortData;
   29   import org.apache.openejb.jee.JavaWsdlMapping;
   30   import org.apache.openejb.jee.PortComponent;
   31   import org.apache.openejb.server.axis.assembler.CommonsSchemaInfoBuilder;
   32   import org.apache.openejb.server.axis.assembler.JaxRpcServiceInfo;
   33   import org.apache.openejb.server.axis.assembler.JaxRpcServiceInfoBuilder;
   34   import org.apache.openejb.server.axis.assembler.XmlSchemaInfo;
   35   import org.apache.openejb.server.httpd.HttpListener;
   36   import org.apache.openejb.server.webservices.WsService;
   37   
   38   import javax.naming.Context;
   39   import javax.wsdl.Port;
   40   import javax.xml.namespace.QName;
   41   import javax.xml.rpc.handler.HandlerInfo;
   42   import java.net.URL;
   43   import java.util.ArrayList;
   44   import java.util.HashMap;
   45   import java.util.List;
   46   import java.util.Map;
   47   import java.util.TreeMap;
   48   
   49   public class AxisService extends WsService {
   50       private final Map<String, AxisWsContainer> wsContainers = new TreeMap<String, AxisWsContainer>();
   51   
   52       public String getName() {
   53           return "axis";
   54       }
   55   
   56       private JaxRpcServiceInfo getJaxRpcServiceInfo(ClassLoader classLoader) throws OpenEJBException {
   57           JavaWsdlMapping mapping = null; // the java to wsdl mapping file
   58           CommonsSchemaInfoBuilder xmlBeansSchemaInfoBuilder = new CommonsSchemaInfoBuilder(null, null); // the schema data from the wsdl file
   59           PortComponent portComponent = null; // webservice.xml declaration of this service
   60           Port port = null; // wsdl.xml declaration of this service
   61           String wsdlFile = null;
   62   
   63           XmlSchemaInfo schemaInfo = xmlBeansSchemaInfoBuilder.createSchemaInfo();
   64   
   65           JaxRpcServiceInfoBuilder serviceInfoBuilder = new JaxRpcServiceInfoBuilder(mapping, schemaInfo, portComponent, port, wsdlFile, classLoader);
   66           JaxRpcServiceInfo serviceInfo = serviceInfoBuilder.createServiceInfo();
   67           return serviceInfo;
   68       }
   69   
   70       protected HttpListener createEjbWsContainer(URL moduleBaseUrl, PortData port, DeploymentInfo deploymentInfo) throws Exception {
   71           ClassLoader classLoader = deploymentInfo.getClassLoader();
   72   
   73           // todo build JaxRpcServiceInfo in assembler
   74           JaxRpcServiceInfo serviceInfo = getJaxRpcServiceInfo(classLoader);
   75   
   76           // Build java service descriptor
   77           JavaServiceDescBuilder javaServiceDescBuilder = new JavaServiceDescBuilder(serviceInfo, classLoader);
   78           JavaServiceDesc serviceDesc = javaServiceDescBuilder.createServiceDesc();
   79   
   80           // Create service
   81           RPCProvider provider = new EjbContainerProvider(deploymentInfo, createHandlerInfos(port.getHandlerChains()));
   82           SOAPService service = new SOAPService(null, provider, null);
   83           service.setServiceDescription(serviceDesc);
   84   
   85           // Set class name
   86           service.setOption("className", deploymentInfo.getServiceEndpointInterface().getName());
   87           serviceDesc.setImplClass(deploymentInfo.getServiceEndpointInterface());
   88   
   89           // Create container
   90           AxisWsContainer container = new AxisWsContainer(port.getWsdlUrl(), service, null, classLoader);
   91           wsContainers.put(deploymentInfo.getDeploymentID().toString(), container);
   92           return container;
   93       }
   94   
   95       protected void destroyEjbWsContainer(String deploymentId) {
   96           AxisWsContainer container = wsContainers.remove(deploymentId);
   97           if (container != null) {
   98               container.destroy();
   99           }
  100       }
  101   
  102       protected HttpListener createPojoWsContainer(URL moduleBaseUrl, PortData port, String serviceId, Class target, Context context, String contextRoot) throws Exception {
  103           ClassLoader classLoader = target.getClassLoader();
  104   
  105           // todo build JaxRpcServiceInfo in assembler
  106           JaxRpcServiceInfo serviceInfo = getJaxRpcServiceInfo(classLoader);
  107   
  108           // Build java service descriptor
  109           JavaServiceDescBuilder javaServiceDescBuilder = new JavaServiceDescBuilder(serviceInfo, classLoader);
  110           JavaServiceDesc serviceDesc = javaServiceDescBuilder.createServiceDesc();
  111   
  112           // Create service
  113           RPCProvider provider = new PojoProvider();
  114           SOAPService service = new SOAPService(null, provider, null);
  115           service.setServiceDescription(serviceDesc);
  116   
  117           // Set class name
  118           service.setOption("className", target.getName());
  119   
  120           // Add Handler Chain
  121           List<HandlerInfo> handlerInfos = createHandlerInfos(port.getHandlerChains());
  122           HandlerInfoChainFactory handlerInfoChainFactory = new HandlerInfoChainFactory(handlerInfos);
  123           service.setOption(org.apache.axis.Constants.ATTR_HANDLERINFOCHAIN, handlerInfoChainFactory);
  124   
  125           // Create container
  126           AxisWsContainer container = new AxisWsContainer(port.getWsdlUrl(), service, null, classLoader);
  127           wsContainers.put(serviceId, container);
  128           return container;
  129       }
  130   
  131       protected void destroyPojoWsContainer(String serviceId) {
  132           AxisWsContainer container = wsContainers.remove(serviceId);
  133           if (container != null) {
  134               container.destroy();
  135           }
  136       }
  137   
  138       @SuppressWarnings({"unchecked"})
  139       private List<HandlerInfo> createHandlerInfos(List<HandlerChainData> handlerChains) throws ClassNotFoundException {
  140           if (handlerChains == null || handlerChains.isEmpty()) return null;
  141           List<HandlerData> handlers = handlerChains.get(0).getHandlers();
  142   
  143           List<HandlerInfo> handlerInfos = new ArrayList<HandlerInfo>(handlers.size());
  144           for (HandlerData handler : handlers) {
  145               Class<?> handlerClass = handler.getHandlerClass();
  146               Map initParams = new HashMap(handler.getInitParams());
  147               QName[] headers = handler.getSoapHeaders().toArray(new QName[handler.getSoapHeaders().size()]);
  148               HandlerInfo handlerInfo = new HandlerInfo(handlerClass, initParams, headers);
  149               handlerInfos.add(handlerInfo);
  150           }
  151   
  152           return handlerInfos;
  153       }
  154   }

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