Beispiel #1
0
 public static boolean generateHandler(Registry configSystemRegistry, String resourceFullPath)
     throws RegistryException, XMLStreamException {
   RegistryContext registryContext = configSystemRegistry.getRegistryContext();
   if (registryContext == null) {
     return false;
   }
   Resource resource = configSystemRegistry.get(resourceFullPath);
   if (resource != null) {
     String content = null;
     if (resource.getContent() != null) {
       content = RegistryUtils.decodeBytes((byte[]) resource.getContent());
     }
     if (content != null) {
       OMElement handler = AXIOMUtil.stringToOM(content);
       if (handler != null) {
         OMElement dummy = OMAbstractFactory.getOMFactory().createOMElement("dummy", null);
         dummy.addChild(handler);
         try {
           configSystemRegistry.beginTransaction();
           boolean status =
               RegistryConfigurationProcessor.updateHandler(
                   dummy,
                   configSystemRegistry.getRegistryContext(),
                   HandlerLifecycleManager.USER_DEFINED_HANDLER_PHASE);
           configSystemRegistry.commitTransaction();
           return status;
         } catch (Exception e) {
           configSystemRegistry.rollbackTransaction();
           throw new RegistryException("Unable to add handler", e);
         }
       }
     }
   }
   return false;
 }
Beispiel #2
0
  public static boolean removeHandler(Registry configSystemRegistry, String handlerName)
      throws RegistryException, XMLStreamException {
    String handlerConfiguration = getHandlerConfiguration(configSystemRegistry, handlerName);
    if (handlerConfiguration != null) {
      OMElement element = AXIOMUtil.stringToOM(handlerConfiguration);
      try {
        try {
          configSystemRegistry.beginTransaction();
          RegistryConfigurationProcessor.HandlerDefinitionObject handlerDefinitionObject =
              new RegistryConfigurationProcessor.HandlerDefinitionObject(null, element).invoke();
          String[] methods = handlerDefinitionObject.getMethods();
          Filter filter = handlerDefinitionObject.getFilter();
          Handler handler = handlerDefinitionObject.getHandler();
          if (handlerDefinitionObject.getTenantId() != -1) {
            CurrentSession.setCallerTenantId(handlerDefinitionObject.getTenantId());
            // We need to swap the tenant id for this call, if the handler has overriden the
            // default value.
            configSystemRegistry
                .getRegistryContext()
                .getHandlerManager()
                .removeHandler(
                    methods, filter, handler, HandlerLifecycleManager.USER_DEFINED_HANDLER_PHASE);
            CurrentSession.removeCallerTenantId();
          } else {
            configSystemRegistry
                .getRegistryContext()
                .getHandlerManager()
                .removeHandler(
                    methods, filter, handler, HandlerLifecycleManager.USER_DEFINED_HANDLER_PHASE);
          }

          configSystemRegistry.commitTransaction();
          return true;
        } catch (Exception e) {
          configSystemRegistry.rollbackTransaction();
          throw e;
        }
      } catch (Exception e) {
        if (e instanceof RegistryException) {
          throw (RegistryException) e;
        } else if (e instanceof XMLStreamException) {
          throw (XMLStreamException) e;
        }
        throw new RegistryException("Unable to build handler configuration", e);
      }
    }
    return false;
  }