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

    1   /**
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements.  See the NOTICE file distributed with
    4    * this work for additional information regarding copyright ownership.
    5    * The ASF licenses this file to You under the Apache License, Version 2.0
    6    * (the "License"); you may not use this file except in compliance with
    7    * the License.  You may obtain a copy of the License at
    8    *
    9    *     http://www.apache.org/licenses/LICENSE-2.0
   10    *
   11    * Unless required by applicable law or agreed to in writing, software
   12    * distributed under the License is distributed on an "AS IS" BASIS,
   13    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   14    * See the License for the specific language governing permissions and
   15    * limitations under the License.
   16    */
   17   
   18   package org.apache.openejb.server.axis2.pojo;
   19   
   20   import org.apache.axis2.context.ConfigurationContext;
   21   import org.apache.axis2.context.MessageContext;
   22   import org.apache.axis2.context.ServiceContext;
   23   import org.apache.axis2.description.AxisService;
   24   import org.apache.axis2.jaxws.registry.FactoryRegistry;
   25   import org.apache.axis2.jaxws.server.endpoint.lifecycle.factory.EndpointLifecycleManagerFactory;
   26   import org.apache.axis2.transport.http.HTTPConstants;
   27   import org.apache.axis2.transport.http.HTTPTransportUtils;
   28   import org.apache.openejb.InjectionProcessor;
   29   import static org.apache.openejb.InjectionProcessor.unwrap;
   30   import org.apache.openejb.core.webservices.PortData;
   31   import org.apache.openejb.server.axis2.Axis2WsContainer;
   32   import org.apache.openejb.server.httpd.HttpRequest;
   33   import org.apache.openejb.server.httpd.HttpResponse;
   34   
   35   import javax.naming.Context;
   36   import javax.xml.ws.WebServiceException;
   37   
   38   public class PojoWsContainer extends Axis2WsContainer {
   39       private Object endpointInstance;
   40       private String contextRoot;
   41       private InjectionProcessor<Object> injectionProcessor;
   42   
   43       public PojoWsContainer(PortData port, Class<?> endpointClass, Context context, String contextRoot) {
   44           super(port, endpointClass, context);
   45           this.contextRoot = contextRoot;
   46       }
   47       
   48       public void start() throws Exception {
   49           super.start();
   50           
   51           /*
   52            * This replaces EndpointLifecycleManagerFactory for all web services.
   53            * This should be ok as we do our own endpoint instance management and injection.       
   54            */
   55           FactoryRegistry.setFactory(EndpointLifecycleManagerFactory.class, 
   56                                      new PojoEndpointLifecycleManagerFactory());
   57                                         
   58           String servicePath = trimContext(getServicePath(this.contextRoot));
   59           this.configurationContext.setServicePath(servicePath);
   60           //need to setContextRoot after servicePath as cachedServicePath is only built 
   61           //when setContextRoot is called.
   62           String rootContext = trimContext(this.contextRoot);
   63           this.configurationContext.setContextRoot(rootContext); 
   64           
   65           // instantiate and inject resources into service
   66           try {
   67               injectionProcessor = new InjectionProcessor<Object>(endpointClass, port.getInjections(), null, null, unwrap(context));
   68               injectionProcessor.createInstance();
   69               injectionProcessor.postConstruct();
   70               endpointInstance = injectionProcessor.getInstance();
   71           } catch (Exception e) {
   72               throw new WebServiceException("Service resource injection failed", e);
   73           }
   74           
   75           // configure and inject handlers
   76           try {
   77               configureHandlers();
   78           } catch (Exception e) {
   79               throw new WebServiceException("Error configuring handlers", e);
   80           }
   81           
   82       }
   83       
   84       protected void processPOSTRequest(HttpRequest request, HttpResponse response, AxisService service, MessageContext msgContext) throws Exception {
   85           String contentType = request.getHeader(HTTPConstants.HEADER_CONTENT_TYPE);
   86           String soapAction = request.getHeader(HTTPConstants.HEADER_SOAP_ACTION);
   87           if (soapAction == null) {
   88               soapAction = "\"\"";
   89           }
   90   
   91           ConfigurationContext configurationContext = msgContext.getConfigurationContext();
   92           configurationContext.fillServiceContextAndServiceGroupContext(msgContext);
   93           
   94           setMsgContextProperties(request, response, service, msgContext);
   95   
   96           ServiceContext serviceContext = msgContext.getServiceContext();
   97           serviceContext.setProperty(ServiceContext.SERVICE_OBJECT, this.endpointInstance);
   98   
   99           try {
  100               HTTPTransportUtils.processHTTPPostRequest(msgContext,
  101                                                         request.getInputStream(),
  102                                                         response.getOutputStream(),
  103                                                         contentType,
  104                                                         soapAction,
  105                                                         request.getURI().getPath());
  106           } finally {                        
  107               // de-associate JAX-WS MessageContext with the thread
  108               // (association happens in POJOEndpointLifecycleManager.createService() call)
  109               PojoWsContext.clear();
  110           } 
  111       }
  112            
  113       public void destroy() {
  114           // call handler preDestroy
  115           destroyHandlers();
  116           
  117           // call service preDestroy
  118           if (injectionProcessor != null) {
  119               injectionProcessor.preDestroy();
  120           }
  121   
  122           super.destroy();
  123       }
  124   }

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