Ejemplo n.º 1
0
  /**
   * Adds the given WSDL artifact to the registry.
   *
   * @param wsdl the WSDL artifact.
   * @throws GovernanceException if the operation failed.
   */
  public void addWsdl(Wsdl wsdl) throws GovernanceException {
    boolean succeeded = false;
    try {
      registry.beginTransaction();
      String url = wsdl.getUrl();
      Resource wsdlResource = registry.newResource();
      wsdlResource.setMediaType(GovernanceConstants.WSDL_MEDIA_TYPE);

      // setting the wsdl content
      setContent(wsdl, wsdlResource);
      wsdlResource.setUUID(wsdl.getId());

      String tmpPath;
      if (wsdl.getQName() != null) {
        tmpPath = "/" + wsdl.getQName().getLocalPart();
      } else if (url != null && !url.startsWith("name://")) {
        tmpPath = RegistryUtils.getResourceName(new URL(url).getFile().replace("~", ""));
      } else if (url != null) {
        tmpPath = url.substring("name://".length());
      } else {
        tmpPath = wsdl.getId() + ".wsdl";
      }
      // OK this is a hack to get the UUID of the newly added artifact. This needs to be fixed
      // properly with the fix for UUID support at Kernel-level - Janaka.
      //            Resource resource;
      if (url == null || url.startsWith("name://")) {
        //                resource = registry.get(registry.put("/" + tmpPath, wsdlResource));
        registry.put("/" + tmpPath, wsdlResource);
      } else {
        //                resource = registry.get(registry.importResource(tmpPath, url,
        // wsdlResource));
        registry.importResource(tmpPath, url, wsdlResource);
      }
      //            wsdl.setId(resource.getUUID());
      wsdl.updatePath();
      //    wsdl.loadWsdlDetails();
      succeeded = true;
    } catch (RegistryException e) {
      String msg = "Error in adding the wsdl. wsdl id: " + wsdl.getId() + ".";
      log.error(msg, e);
      throw new GovernanceException(msg, e);
    } catch (MalformedURLException e) {
      String msg = "Malformed policy url provided. url: " + wsdl.getUrl() + ".";
      log.error(msg, e);
      throw new GovernanceException(msg, e);
    } finally {
      if (succeeded) {
        try {
          registry.commitTransaction();
        } catch (RegistryException e) {
          String msg =
              "Error in committing transactions. Add wsdl failed: wsdl id: "
                  + wsdl.getId()
                  + ", path: "
                  + wsdl.getPath()
                  + ".";
          log.error(msg, e);
        }
      } else {
        try {
          registry.rollbackTransaction();
        } catch (RegistryException e) {
          String msg =
              "Error in rolling back transactions. Add wsdl failed: wsdl id: "
                  + wsdl.getId()
                  + ", path: "
                  + wsdl.getPath()
                  + ".";
          log.error(msg, e);
        }
      }
    }
  }
Ejemplo n.º 2
0
  /**
   * Updates the given WSDL artifact on the registry.
   *
   * @param wsdl the WSDL artifact.
   * @throws GovernanceException if the operation failed.
   */
  public void updateWsdl(Wsdl wsdl) throws GovernanceException {
    if (wsdl.getWsdlElement() == null) {
      // there won't be any updates
      String msg =
          "Updates are only accepted if the wsdlElement available. "
              + "So no updates will be done. "
              + "wsdl id: "
              + wsdl.getId()
              + ", wsdl path: "
              + wsdl.getPath()
              + ".";
      log.error(msg);
      throw new GovernanceException(msg);
    }
    boolean succeeded = false;
    try {
      registry.beginTransaction();

      // getting the old wsdl.
      Wsdl oldWsdl = getWsdl(wsdl.getId());
      if (oldWsdl == null) {
        addWsdl(wsdl);
        return;
      }
      // we are expecting only the OMElement to be different.
      Resource wsdlResource = registry.newResource();
      wsdlResource.setMediaType(GovernanceConstants.WSDL_MEDIA_TYPE);

      // setting the wsdl content
      setContent(wsdl, wsdlResource);

      // remove the old wsdl resource.
      String tmpPath = oldWsdl.getPath();
      wsdlResource.setUUID(wsdl.getId());
      registry.put(tmpPath, wsdlResource);
      //            wsdl.setId(wsdlResource.getUUID());
      wsdl.updatePath();
      //            wsdl.loadWsdlDetails();

      succeeded = true;
    } catch (RegistryException e) {
      String msg =
          "Error in updating the wsdl, wsdl id: "
              + wsdl.getId()
              + ", wsdl path: "
              + wsdl.getPath()
              + ".";
      log.error(msg, e);
      throw new GovernanceException(msg, e);
    } finally {
      if (succeeded) {
        try {
          registry.commitTransaction();
        } catch (RegistryException e) {
          String msg =
              "Error in committing transactions. Update wsdl failed: wsdl id: "
                  + wsdl.getId()
                  + ", path: "
                  + wsdl.getPath()
                  + ".";
          log.error(msg, e);
        }
      } else {
        try {
          registry.rollbackTransaction();
        } catch (RegistryException e) {
          String msg =
              "Error in rolling back transactions. Update wsdl failed: wsdl id: "
                  + wsdl.getId()
                  + ", path: "
                  + wsdl.getPath()
                  + ".";
          log.error(msg, e);
        }
      }
    }
  }