public boolean isGlobalyEngaged(AxisModule axisModule) {
   String modName = axisModule.getName();
   for (Object globallyEngagedModule : globallyEngagedModules) {
     AxisModule module = (AxisModule) globallyEngagedModule;
     if (modName.startsWith(module.getName())) {
       return true;
     }
   }
   return false;
 }
Esempio n. 2
0
 public void processdisengageModule(HttpServletRequest req, HttpServletResponse res)
     throws IOException, ServletException {
   String type = req.getParameter("type");
   String serviceName = req.getParameter("serviceName");
   String moduleName = req.getParameter("module");
   AxisConfiguration axisConfiguration = configContext.getAxisConfiguration();
   AxisService service = axisConfiguration.getService(serviceName);
   AxisModule module = axisConfiguration.getModule(moduleName);
   if (type.equals("operation")) {
     if (service.isEngaged(module.getName()) || axisConfiguration.isEngaged(module.getName())) {
       req.getSession()
           .setAttribute(
               "status",
               "Can not disengage module "
                   + moduleName
                   + ". This module is engaged at a higher level.");
     } else {
       String opName = req.getParameter("operation");
       AxisOperation op = service.getOperation(new QName(opName));
       op.disengageModule(module);
       req.getSession()
           .setAttribute(
               "status",
               "Module "
                   + moduleName
                   + " was disengaged from "
                   + "operation "
                   + opName
                   + " in service "
                   + serviceName
                   + ".");
     }
   } else {
     if (axisConfiguration.isEngaged(module.getName())) {
       req.getSession()
           .setAttribute(
               "status",
               "Can not disengage module "
                   + moduleName
                   + ". "
                   + "This module is engaged at a higher level.");
     } else {
       service.disengageModule(axisConfiguration.getModule(moduleName));
       req.getSession()
           .setAttribute(
               "status",
               "Module " + moduleName + " was disengaged from" + " service " + serviceName + ".");
     }
   }
   renderView("disengage.jsp", req, res);
 }
  /**
   * First create a Deployment engine, use that to create an AxisConfiguration
   *
   * @return Axis Configuration
   * @throws AxisFault
   */
  public AxisConfiguration getAxisConfiguration() throws AxisFault {
    // ClassLoader origTccl = Thread.currentThread().getContextClassLoader();
    // Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
    log.info(
        "Creating tenant AxisConfiguration for tenant: " + getTenantString(tenantDomain, tenantId));
    PrivilegedCarbonContext.startTenantFlow();
    try {
      PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getCurrentContext();
      carbonContext.setTenantId(tenantId);
      carbonContext.setTenantDomain(tenantDomain);
      if (log.isDebugEnabled()) {
        log.debug("Axis2 repo: " + repoLocation);
      }
      populateAxisConfig();
      addDeployer(new ModuleDeployer(), repoLocation + File.separator + "axis2modules", "mar");
      axisConfig.setConfigurator(this);

      // TODO: May need to set certain parameters into the AxisConfig

      // Hot deployment & update should be turned on for tenants
      axisConfig.addParameter(new Parameter(DeploymentConstants.TAG_HOT_DEPLOYMENT, "true"));
      axisConfig.addParameter(new Parameter(DeploymentConstants.TAG_HOT_UPDATE, "true"));

      globallyEngagedModules = axisConfig.getEngagedModules();
      loadRepository(repoLocation);

      // set the service class loader in the axisConfig, this is needed due to ghost deployer
      // as the service deployer is no longer treated as a special case, we have to do this
      File axis2ServicesDir = new File(repoLocation, CarbonUtils.getAxis2ServicesDir(axisConfig));
      if (axis2ServicesDir.exists()) {
        axisConfig.setServiceClassLoader(
            Utils.getClassLoader(
                axisConfig.getSystemClassLoader(),
                axis2ServicesDir,
                axisConfig.isChildFirstClassLoading()));
      }

      for (Object globallyEngagedModule : globallyEngagedModules) {
        AxisModule module = (AxisModule) globallyEngagedModule;
        if (log.isDebugEnabled()) {
          log.debug("Globally engaging module: " + module.getName());
        }
      }

      // Remove all the transports made available in the tenant's axis2.xml
      axisConfig.getTransportsOut().clear();

      // Remove all in-transports made available in the tenant's axis2.xml
      axisConfig.getTransportsIn().clear();

      // Add the transports that are made available in the main axis2.xml file
      TenantAxisUtils.setTenantTransports(mainAxisConfig, tenantDomain, axisConfig);

    } finally {
      PrivilegedCarbonContext.endTenantFlow();
      // Thread.currentThread().setContextClassLoader(origTccl);
    }
    return axisConfig;
  }
  /** Cleanup the axis2 environment and stop the synapse environment. */
  public void stop() {
    try {
      // stop tasks
      SynapseTaskManager synapseTaskManager = synapseEnvironment.getTaskManager();
      if (synapseTaskManager.isInitialized()) {
        synapseTaskManager.cleanup();
      }

      EnterpriseBeanstalkManager manager =
          (EnterpriseBeanstalkManager)
              serverContextInformation.getProperty(
                  EnterpriseBeanstalkConstants.BEANSTALK_MANAGER_PROP_NAME);
      if (manager != null) {
        manager.destroy();
      }

      // stop the listener manager
      if (listenerManager != null) {
        listenerManager.stop();
      }

      // detach the synapse handlers
      if (configurationContext != null) {
        List<Phase> inflowPhases = configurationContext.getAxisConfiguration().getInFlowPhases();
        for (Phase inPhase : inflowPhases) {
          // we are interested about the Dispatch phase in the inflow
          if (PhaseMetadata.PHASE_DISPATCH.equals(inPhase.getPhaseName())) {
            List<HandlerDescription> synapseHandlers = new ArrayList<HandlerDescription>();
            for (Handler handler : inPhase.getHandlers()) {
              if (SynapseDispatcher.NAME.equals(handler.getName())
                  || SynapseMustUnderstandHandler.NAME.equals(handler.getName())) {
                synapseHandlers.add(handler.getHandlerDesc());
              }
            }

            for (HandlerDescription handlerMD : synapseHandlers) {
              inPhase.removeHandler(handlerMD);
            }
          }
        }
      } else {
        handleException(
            "Couldn't detach the Synapse handlers, " + "ConfigurationContext not found.");
      }

      // continue stopping the axis2 environment if we created it
      if (serverConfigurationInformation.isCreateNewInstance()
          && configurationContext != null
          && configurationContext.getAxisConfiguration() != null) {
        Map<String, AxisService> serviceMap =
            configurationContext.getAxisConfiguration().getServices();
        for (AxisService svc : serviceMap.values()) {
          svc.setActive(false);
        }

        // stop all modules
        Map<String, AxisModule> moduleMap =
            configurationContext.getAxisConfiguration().getModules();
        for (AxisModule mod : moduleMap.values()) {
          if (mod.getModule() != null && !"synapse".equals(mod.getName())) {
            mod.getModule().shutdown(configurationContext);
          }
        }
      }
    } catch (AxisFault e) {
      log.error("Error stopping the Axis2 Environment");
    }
  }