Home » rampart-dist-1.4-src » org.apache » axis2 » integration » [javadoc | source]

    1   /*
    2    * Copyright 2004,2005 The Apache Software Foundation.
    3    *
    4    * Licensed under the Apache License, Version 2.0 (the "License");
    5    * you may not use this file except in compliance with the License.
    6    * You may obtain a copy of the License at
    7    *
    8    *      http://www.apache.org/licenses/LICENSE-2.0
    9    *
   10    * Unless required by applicable law or agreed to in writing, software
   11    * distributed under the License is distributed on an "AS IS" BASIS,
   12    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   13    * See the License for the specific language governing permissions and
   14    * limitations under the License.
   15    */
   16   
   17   package org.apache.axis2.integration;
   18   
   19   import org.apache.axis2.AxisFault;
   20   import org.apache.axis2.context.ConfigurationContext;
   21   import org.apache.axis2.context.ConfigurationContextFactory;
   22   import org.apache.axis2.context.ServiceGroupContext;
   23   import org.apache.axis2.description.AxisService;
   24   import org.apache.axis2.description.AxisServiceGroup;
   25   import org.apache.axis2.engine.ListenerManager;
   26   import org.apache.axis2.transport.tcp.TCPServer;
   27   import org.apache.commons.logging.Log;
   28   import org.apache.commons.logging.LogFactory;
   29   
   30   import javax.xml.namespace.QName;
   31   import java.io.File;
   32   
   33   public class UtilsTCPServer {
   34       private static int count = 0;
   35   
   36       private static TCPServer receiver;
   37   
   38       public static final int TESTING_PORT = 5555;
   39   
   40       public static final String FAILURE_MESSAGE = "Intentional Failure";
   41   
   42   	private static final Log log = LogFactory.getLog(UtilsTCPServer.class);
   43   
   44       public static synchronized void deployService(AxisService service)
   45               throws AxisFault {
   46   
   47           receiver.getConfigurationContext().getAxisConfiguration().addService(service);
   48           ServiceGroupContext serviceGroupContext = new ServiceGroupContext(
   49                   receiver.getConfigurationContext(), (AxisServiceGroup) service.getParent());
   50       }
   51   
   52       public static synchronized void unDeployService(QName service)
   53               throws AxisFault {
   54           receiver.getConfigurationContext().getAxisConfiguration().removeService(
   55                   service.getLocalPart());
   56       }
   57   
   58       public static synchronized void start() throws Exception {
   59           if (count == 0) {
   60   
   61               // start tcp server
   62   
   63               File file = new File(org.apache.axis2.Constants.TESTING_REPOSITORY);
   64               System.out.println(file.getAbsoluteFile());
   65               if (!file.exists()) {
   66                   throw new Exception("Repository directory does not exist");
   67               }
   68   
   69               ConfigurationContext er = ConfigurationContextFactory.createConfigurationContextFromFileSystem(file
   70                       .getAbsolutePath(), file
   71                       .getAbsolutePath() + "/conf/axis2.xml");
   72               try {
   73                   Thread.sleep(1000);
   74               } catch (InterruptedException e1) {
   75                   throw new AxisFault("Thread interuptted", e1);
   76               }
   77               receiver = new TCPServer(UtilServer.TESTING_PORT, er);
   78               receiver.start();
   79   
   80           }
   81           count++;
   82       }
   83   
   84       public static synchronized void stop() throws AxisFault {
   85           try {
   86               if (count == 1) {
   87                   receiver.stop();
   88                   count = 0;
   89                   System.out.print("Server stopped .....");
   90               } else {
   91                   count--;
   92               }
   93           } catch (AxisFault e) {
   94               log.error(e.getMessage(), e);
   95           }
   96           receiver.getConfigurationContext().terminate();
   97       }
   98   
   99   }

Home » rampart-dist-1.4-src » org.apache » axis2 » integration » [javadoc | source]