Exemplo n.º 1
0
  public static boolean addHandler(Registry configSystemRegistry, String payload)
      throws RegistryException, XMLStreamException {
    String name;
    OMElement element = AXIOMUtil.stringToOM(payload);
    if (element != null) {
      name = element.getAttributeValue(new QName("class"));
    } else return false;

    if (isHandlerNameInUse(name))
      throw new RegistryException("The added handler name is already in use!");

    String path = getContextRoot() + name;
    Resource resource;
    if (!handlerExists(configSystemRegistry, name)) {
      resource = new ResourceImpl();
    } else {
      throw new RegistryException("The added handler name is already in use!");
    }
    resource.setContent(payload);
    try {
      configSystemRegistry.beginTransaction();
      configSystemRegistry.put(path, resource);
      generateHandler(configSystemRegistry, path);
      configSystemRegistry.commitTransaction();
    } catch (Exception e) {
      configSystemRegistry.rollbackTransaction();
      throw new RegistryException("Unable to generate handler", e);
    }
    return true;
  }
Exemplo n.º 2
0
  public static HandlerConfigurationBean deserializeHandlerConfiguration(
      OMElement configurationElement) {
    if (configurationElement == null || !"handler".equals(configurationElement.getLocalName())) {
      return null;
    }
    HandlerConfigurationBean handlerConfigurationBean = new HandlerConfigurationBean();
    handlerConfigurationBean.setHandlerClass(
        configurationElement.getAttributeValue(new QName("class")));
    handlerConfigurationBean.setTenant(configurationElement.getAttributeValue(new QName("tenant")));
    String methodsAttribute = configurationElement.getAttributeValue(new QName("methods"));
    if (methodsAttribute != null && methodsAttribute.length() != 0) {
      handlerConfigurationBean.setMethods(methodsAttribute.split(","));
    }
    @SuppressWarnings("unchecked")
    Iterator<OMElement> handlerProps =
        configurationElement.getChildrenWithName(new QName("property"));
    while (handlerProps.hasNext()) {
      OMElement propElement = handlerProps.next();
      String propName = propElement.getAttributeValue(new QName("name"));
      String propType = propElement.getAttributeValue(new QName("type"));

      if (propType != null && "xml".equals(propType)) {
        handlerConfigurationBean.getXmlProperties().put(propName, propElement);
      } else {
        handlerConfigurationBean.getNonXmlProperties().put(propName, propElement.getText());
      }
      handlerConfigurationBean.getPropertyList().add(propName);
    }
    FilterConfigurationBean filterConfigurationBean = new FilterConfigurationBean();
    OMElement filterElement = configurationElement.getFirstChildWithName(new QName("filter"));
    filterConfigurationBean.setFilterClass(filterElement.getAttributeValue(new QName("class")));
    @SuppressWarnings("unchecked")
    Iterator<OMElement> filterProps = filterElement.getChildrenWithName(new QName("property"));
    while (filterProps.hasNext()) {
      OMElement propElement = filterProps.next();
      String propName = propElement.getAttributeValue(new QName("name"));
      String propType = propElement.getAttributeValue(new QName("type"));

      if (propType != null && "xml".equals(propType)) {
        filterConfigurationBean.getXmlProperties().put(propName, propElement);
      } else {
        filterConfigurationBean.getNonXmlProperties().put(propName, propElement.getText());
      }
      filterConfigurationBean.getPropertyList().add(propName);
    }
    handlerConfigurationBean.setFilter(filterConfigurationBean);
    return handlerConfigurationBean;
  }
Exemplo n.º 3
0
  public static boolean updateHandler(Registry configSystemRegistry, String oldName, String payload)
      throws RegistryException, XMLStreamException {
    if (isHandlerNameInUse(oldName))
      throw new RegistryException("Could not update handler since it is already in use!");

    String newName = null;
    OMElement element = AXIOMUtil.stringToOM(payload);
    if (element != null) {
      newName = element.getAttributeValue(new QName("class"));
    }

    if (newName == null || newName.equals("")) return false; // invalid configuration

    if (oldName == null || oldName.equals("")) {
      String path = getContextRoot() + newName;
      Resource resource;
      if (handlerExists(configSystemRegistry, newName)) {
        return false; // we are adding a new handler
      } else {
        resource = new ResourceImpl();
      }
      resource.setContent(payload);
      try {
        configSystemRegistry.beginTransaction();
        configSystemRegistry.put(path, resource);
        generateHandler(configSystemRegistry, path);
        configSystemRegistry.commitTransaction();
      } catch (Exception e) {
        configSystemRegistry.rollbackTransaction();
        throw new RegistryException("Unable to generate handler", e);
      }
      return true;
    }

    if (newName.equals(oldName)) {
      // updating the rest of the content
      String oldPath = getContextRoot() + oldName;
      Resource resource;
      if (handlerExists(configSystemRegistry, oldName)) {
        resource = configSystemRegistry.get(oldPath);
      } else {
        resource = new ResourceImpl(); // will this ever happen?
      }
      resource.setContent(payload);
      try {
        configSystemRegistry.beginTransaction();
        removeHandler(configSystemRegistry, oldName);
        configSystemRegistry.put(oldPath, resource);
        generateHandler(configSystemRegistry, oldPath);
        configSystemRegistry.commitTransaction();
      } catch (Exception e) {
        configSystemRegistry.rollbackTransaction();
        throw new RegistryException("Unable to generate handler", e);
      }
      return true;
    } else {
      String oldPath = getContextRoot() + oldName;
      String newPath = getContextRoot() + newName;

      if (handlerExists(configSystemRegistry, newName)) {
        return false; // we are trying to use the name of a existing handler
      }

      Resource resource;
      if (handlerExists(configSystemRegistry, oldName)) {
        resource = configSystemRegistry.get(oldPath);
      } else {
        resource = new ResourceImpl(); // will this ever happen?
      }

      resource.setContent(payload);
      try {
        configSystemRegistry.beginTransaction();
        configSystemRegistry.put(newPath, resource);
        generateHandler(configSystemRegistry, newPath);
        removeHandler(configSystemRegistry, oldName);
        configSystemRegistry.delete(oldPath);
        configSystemRegistry.commitTransaction();
      } catch (Exception e) {
        configSystemRegistry.rollbackTransaction();
        throw new RegistryException("Unable to renew handler", e);
      }
      return true;
    }
  }