Save This Page
Home » axis2-1.5-src » org.apache » axis2 » deployment » [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   
   20   package org.apache.axis2.deployment;
   21   
   22   import org.apache.axis2.AxisFault;
   23   import org.apache.axis2.Constants;
   24   import org.apache.axis2.context.ConfigurationContext;
   25   import org.apache.axis2.deployment.repository.util.ArchiveReader;
   26   import org.apache.axis2.deployment.repository.util.DeploymentFileData;
   27   import org.apache.axis2.deployment.util.Utils;
   28   import org.apache.axis2.description.AxisOperation;
   29   import org.apache.axis2.description.AxisService;
   30   import org.apache.axis2.description.AxisServiceGroup;
   31   import org.apache.axis2.engine.AxisConfiguration;
   32   import org.apache.axis2.i18n.Messages;
   33   import org.apache.commons.logging.Log;
   34   import org.apache.commons.logging.LogFactory;
   35   
   36   import java.io.File;
   37   import java.io.PrintWriter;
   38   import java.io.StringWriter;
   39   import java.net.URL;
   40   import java.util.ArrayList;
   41   import java.util.HashMap;
   42   import java.util.Iterator;
   43   
   44   public class ServiceDeployer implements Deployer {
   45       private static final Log log = LogFactory.getLog(ServiceDeployer.class);
   46       private AxisConfiguration axisConfig;
   47       private ConfigurationContext configCtx;
   48   
   49       //To initialize the deployer
   50       public void init(ConfigurationContext configCtx) {
   51           this.configCtx = configCtx;
   52           this.axisConfig = this.configCtx.getAxisConfiguration();
   53       }
   54   
   55       //Will process the file and add that to axisConfig
   56   
   57       public void deploy(DeploymentFileData deploymentFileData) throws DeploymentException {
   58           boolean isDirectory = deploymentFileData.getFile().isDirectory();
   59           ArchiveReader archiveReader;
   60           StringWriter errorWriter = new StringWriter();
   61           archiveReader = new ArchiveReader();
   62           String serviceStatus = "";
   63           try {
   64               deploymentFileData.setClassLoader(isDirectory,
   65                                                 axisConfig.getServiceClassLoader(),
   66                       (File)axisConfig.getParameterValue(Constants.Configuration.ARTIFACTS_TEMP_DIR));
   67               HashMap wsdlservice = archiveReader.processWSDLs(deploymentFileData);
   68               if (wsdlservice != null && wsdlservice.size() > 0) {
   69                   Iterator services = wsdlservice.values().iterator();
   70                   while (services.hasNext()) {
   71                       AxisService service = (AxisService) services.next();
   72                       Iterator operations = service.getOperations();
   73                       while (operations.hasNext()) {
   74                           AxisOperation axisOperation = (AxisOperation) operations.next();
   75                           axisConfig.getPhasesInfo().setOperationPhases(axisOperation);
   76                       }
   77                   }
   78               }
   79               AxisServiceGroup serviceGroup = new AxisServiceGroup(axisConfig);
   80               serviceGroup.setServiceGroupClassLoader(deploymentFileData.getClassLoader());
   81               ArrayList serviceList = archiveReader.processServiceGroup(
   82                       deploymentFileData.getAbsolutePath(), deploymentFileData,
   83                       serviceGroup, isDirectory, wsdlservice,
   84                       configCtx);
   85               URL location = deploymentFileData.getFile().toURL();
   86               DeploymentEngine.addServiceGroup(serviceGroup,
   87                                                serviceList,
   88                                                location,
   89                                                deploymentFileData,
   90                                                axisConfig);
   91               log.info(Messages.getMessage(DeploymentErrorMsgs.DEPLOYING_WS,
   92                                            deploymentFileData.getName(),
   93                                            location.toString()));
   94           } catch (DeploymentException de) {
   95               de.printStackTrace();
   96               log.error(Messages.getMessage(DeploymentErrorMsgs.INVALID_SERVICE,
   97                                             deploymentFileData.getName(),
   98                                             de.getMessage()),
   99                         de);
  100               PrintWriter error_ptintWriter = new PrintWriter(errorWriter);
  101               de.printStackTrace(error_ptintWriter);
  102               serviceStatus = "Error:\n" + errorWriter.toString();
  103   
  104               throw de;
  105   
  106           } catch (AxisFault axisFault) {
  107               log.error(Messages.getMessage(DeploymentErrorMsgs.INVALID_SERVICE,
  108                                             deploymentFileData.getName(),
  109                                             axisFault.getMessage()),
  110                         axisFault);
  111               PrintWriter error_ptintWriter = new PrintWriter(errorWriter);
  112               axisFault.printStackTrace(error_ptintWriter);
  113               serviceStatus = "Error:\n" + errorWriter.toString();
  114   
  115               throw new DeploymentException(axisFault);
  116   
  117           } catch (Exception e) {
  118               if (log.isInfoEnabled()) {
  119                   StringWriter sw = new StringWriter();
  120                   PrintWriter pw = new PrintWriter(sw);
  121                   e.printStackTrace(pw);
  122                   log.info(Messages.getMessage(
  123                           DeploymentErrorMsgs.INVALID_SERVICE,
  124                           deploymentFileData.getName(),
  125                           sw.getBuffer().toString()));
  126               }
  127               PrintWriter error_ptintWriter = new PrintWriter(errorWriter);
  128               e.printStackTrace(error_ptintWriter);
  129               serviceStatus = "Error:\n" + errorWriter.toString();
  130   
  131               throw new DeploymentException(e);
  132   
  133           } catch (Throwable t) {
  134               if (log.isInfoEnabled()) {
  135                   StringWriter sw = new StringWriter();
  136                   PrintWriter pw = new PrintWriter(sw);
  137                   t.printStackTrace(pw);
  138                   log.info(Messages.getMessage(
  139                           DeploymentErrorMsgs.INVALID_SERVICE,
  140                           deploymentFileData.getName(),
  141                           sw.getBuffer().toString()));
  142               }
  143               PrintWriter error_ptintWriter = new PrintWriter(errorWriter);
  144               t.printStackTrace(error_ptintWriter);
  145               serviceStatus = "Error:\n" + errorWriter.toString();
  146   
  147               throw new DeploymentException(new Exception(t));
  148   
  149           } finally {
  150               if (serviceStatus.startsWith("Error:")) {
  151                   axisConfig.getFaultyServices().put(deploymentFileData.getFile().getAbsolutePath(),
  152                                                      serviceStatus);
  153               }
  154           }
  155       }
  156   
  157       public void setDirectory(String directory) {
  158       }
  159   
  160       public void setExtension(String extension) {
  161       }
  162   
  163       public void unDeploy(String fileName) throws DeploymentException {
  164           try {
  165               fileName = Utils.getShortFileName(fileName);
  166               fileName = DeploymentEngine.getAxisServiceName(fileName);
  167               AxisServiceGroup serviceGroup = axisConfig.removeServiceGroup(fileName);
  168               if (serviceGroup != null) {
  169                   configCtx.removeServiceGroupContext(serviceGroup);
  170                   log.info(Messages.getMessage(DeploymentErrorMsgs.SERVICE_REMOVED,
  171                           fileName));
  172               } else {
  173                   axisConfig.removeFaultyService(fileName);
  174               }
  175           } catch (AxisFault axisFault) {
  176               //May be a faulty service
  177               axisConfig.removeFaultyService(fileName);
  178   
  179               throw new DeploymentException(axisFault);
  180           }
  181       }
  182   }

Save This Page
Home » axis2-1.5-src » org.apache » axis2 » deployment » [javadoc | source]