Save This Page
Home » geronimo-2.2-source-release » org.apache.geronimo.cxf.pojo » [javadoc | source]
    1   /**
    2    * Licensed to the Apache Software Foundation (ASF) under one
    3    * or more contributor license agreements. See the NOTICE file
    4    * distributed with this work for additional information
    5    * regarding copyright ownership. The ASF licenses this file
    6    * to you under the Apache License, Version 2.0 (the
    7    * "License"); you may not use this file except in compliance
    8    * with 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,
   13    * software distributed under the License is distributed on an
   14    * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
   15    * KIND, either express or implied. See the License for the
   16    * specific language governing permissions and limitations
   17    * under the License.
   18    */
   19   package org.apache.geronimo.cxf.pojo;
   20   
   21   import java.net.URL;
   22   
   23   import javax.naming.Context;
   24   import javax.xml.ws.WebServiceException;
   25   
   26   import org.apache.cxf.Bus;
   27   import org.apache.cxf.jaxws.JAXWSMethodInvoker;
   28   import org.apache.cxf.jaxws.context.WebServiceContextImpl;
   29   import org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean;
   30   import org.apache.geronimo.cxf.CXFEndpoint;
   31   import org.apache.geronimo.cxf.CXFServiceConfiguration;
   32   import org.apache.geronimo.cxf.GeronimoJaxWsImplementorInfo;
   33   import org.apache.geronimo.jaxws.JAXWSAnnotationProcessor;
   34   import org.apache.geronimo.jaxws.JNDIResolver;
   35   import org.apache.geronimo.jaxws.annotations.AnnotationHolder;
   36   import org.slf4j.Logger;
   37   import org.slf4j.LoggerFactory;
   38   
   39   public class POJOEndpoint extends CXFEndpoint {
   40   
   41       private static final Logger LOG = LoggerFactory.getLogger(POJOEndpoint.class);
   42       
   43       private AnnotationHolder holder;
   44   
   45       public POJOEndpoint(Bus bus, 
   46                           URL configurationBaseUrl, 
   47                           Class instance) {
   48           super(bus, instance);
   49           
   50           implInfo = new GeronimoJaxWsImplementorInfo(instance, this.portInfo, instance.getClassLoader());
   51   
   52           serviceFactory = new JaxWsServiceFactoryBean(implInfo);        
   53           serviceFactory.setBus(bus);
   54                   
   55           String wsdlLocation = null;
   56           if (this.portInfo.getWsdlFile() != null) {
   57               wsdlLocation = this.portInfo.getWsdlFile();
   58           } else {
   59               wsdlLocation = implInfo.getWsdlLocation();
   60           }        
   61           URL wsdlURL = getWsdlURL(configurationBaseUrl, wsdlLocation);
   62   
   63           // install as first to overwrite annotations (wsdl-file, wsdl-port, wsdl-service)
   64           CXFServiceConfiguration configuration = 
   65               new CXFServiceConfiguration(this.portInfo, wsdlURL);
   66           serviceFactory.getConfigurations().add(0, configuration);
   67   
   68           service = serviceFactory.create();
   69           
   70           this.holder = bus.getExtension(AnnotationHolder.class);
   71           
   72           Context context = bus.getExtension(Context.class);
   73           
   74           // instantiate and inject resources into service
   75           try {
   76               this.implementor = this.holder.newInstance(instance.getName(), 
   77                                                          instance.getClassLoader(), 
   78                                                          context);
   79           } catch (Exception e) {
   80               throw new WebServiceException("Service resource injection failed", e);
   81           }
   82           
   83           service.setInvoker(new JAXWSMethodInvoker(this.implementor));       
   84   
   85           JNDIResolver jndiResolver = (JNDIResolver) bus.getExtension(JNDIResolver.class);
   86           this.annotationProcessor = new JAXWSAnnotationProcessor(jndiResolver, new WebServiceContextImpl());
   87       }
   88       
   89       @Override
   90       protected void init() {        
   91           // configure and inject handlers
   92           try {
   93               initHandlers();
   94               injectHandlers();
   95           } catch (Exception e) {
   96               throw new WebServiceException("Error configuring handlers", e);
   97           }
   98       }
   99   
  100       @Override
  101       public void stop() {
  102           // call handler preDestroy
  103           destroyHandlers();
  104   
  105           // call service preDestroy
  106           if (this.implementor != null) {
  107               try {
  108                   this.holder.destroyInstance(this.implementor);
  109               } catch (Exception e) {
  110                   LOG.warn("Error calling @PreDestroy method", e); 
  111               }
  112           }
  113   
  114           // shutdown server
  115           super.stop();
  116       }
  117   
  118   }

Save This Page
Home » geronimo-2.2-source-release » org.apache.geronimo.cxf.pojo » [javadoc | source]