コード例 #1
0
  @AfterClass(
      groups = "wso2.greg",
      alwaysRun = true,
      description = "cleaning up the artifacts added")
  public void tearDown()
      throws RegistryException, LoginAuthenticationExceptionException, RemoteException,
          ResourceAdminServiceExceptionException {

    String pathPrefix = "/_system/governance";
    Endpoint[] endpoints;

    endpoints = wsdl.getAttachedEndpoints();
    assertNotNull(endpoints, "there should be associated endpoints with the wsdl");

    GovernanceArtifact[] governanceArtifacts = wsdl.getDependents();
    assertNotNull(governanceArtifacts, "there should be dependent of the wsdl");

    for (GovernanceArtifact tmpGovernanceArtifact : governanceArtifacts) {
      wsRegistry.delete(pathPrefix + tmpGovernanceArtifact.getPath());
    }

    for (Endpoint tmpEndpoint : endpoints) {
      GovernanceArtifact[] dependentArtifacts = tmpEndpoint.getDependents();
      for (GovernanceArtifact tmpGovernanceArtifact : dependentArtifacts) {
        wsRegistry.delete(pathPrefix + tmpGovernanceArtifact.getPath());
      }
      wsRegistry.delete(pathPrefix + tmpEndpoint.getPath());
    }
  }
コード例 #2
0
ファイル: WsdlManager.java プロジェクト: rcamus/platform
 /**
  * Create a new WSDL based on content either embedded or passed to a service.
  *
  * @param content the WSDL content
  * @param name the WSDL name
  * @return the artifact added.
  * @throws GovernanceException if the operation failed.
  */
 public Wsdl newWsdl(byte[] content, String name) throws RegistryException {
   String wsdlId = UUID.randomUUID().toString();
   Wsdl wsdl = new Wsdl(wsdlId, name != null ? "name://" + name : null);
   wsdl.associateRegistry(registry);
   wsdl.setWsdlElement(GovernanceUtils.buildOMElement(content));
   return wsdl;
 }
コード例 #3
0
 public void verifyWSDL() throws GovernanceException {
   WsdlManager wsdlManager = new WsdlManager(governance);
   Wsdl[] wsdls = wsdlManager.getAllWsdls();
   boolean resourceFound = false;
   for (Wsdl wsdl : wsdls) {
     if (wsdl.getQName().getLocalPart().equals("wsdl_with_EncrOnlyAnonymous.wsdl")) {
       resourceFound = true;
     }
   }
   Assert.assertTrue(resourceFound);
 }
コード例 #4
0
 private void addWSDL() throws IOException, RegistryException {
   WsdlManager wsdlManager = new WsdlManager(governance);
   Wsdl wsdl;
   String wsdlFilePath =
       ProductConstant.getResourceLocations(ProductConstant.GREG_SERVER_NAME)
           + File.separator
           + "wsdl"
           + File.separator;
   wsdl =
       wsdlManager.newWsdl(
           FileManager.readFile(wsdlFilePath + "echo.wsdl").getBytes(), "echo.wsdl");
   wsdlManager.addWsdl(wsdl);
   wsdl = wsdlManager.getWsdl(wsdl.getId());
   Resource resource = governance.get(wsdl.getPath());
   resource.addProperty("y", "20");
   governance.put(wsdl.getPath(), resource);
 }
コード例 #5
0
  /*
   * adding an invalid wsdl (a normal .xml) no assertions and tear down
   * because wsdl addition wouldn't happen
   */
  @Test(
      groups = "wso2.greg",
      description = "Add Invalid WSDL",
      expectedExceptions = GovernanceException.class)
  public void testInvalidAdditionWSDL()
      throws RemoteException, ResourceAdminServiceExceptionException, GovernanceException,
          MalformedURLException {

    WsdlManager wsdlManager = new WsdlManager(governanceRegistry);
    Wsdl wsdl =
        wsdlManager.newWsdl(
            "https://svn.wso2.org/repos/wso2/carbon/platform/trunk/"
                + "platform-integration/clarity-tests/org.wso2.carbon.automation.test.repo/"
                + "src/main/resources/artifacts/GREG/wsdl/AutomatedInvalidWSDL.wsdl");
    wsdl.addAttribute("version", "1.0.0");
    wsdl.addAttribute("author", "Aparna");
    wsdl.addAttribute("description", "added invalid wsdl using url");
    wsdlManager.addWsdl(wsdl);
  }
コード例 #6
0
  /** adding a encoded URL wsdl */
  @Test(groups = "wso2.greg", description = "Add Encoded WSDL")
  public void testAddEncodedURLWSDL()
      throws RemoteException, ResourceAdminServiceExceptionException, GovernanceException,
          MalformedURLException {

    wsdl =
        wsdlManager.newWsdl(
            "https://raw.githubusercontent.com/wso2/wso2-qa-artifacts/master/automation-artifacts/greg"
                + "/wsdl/StockQuote.wsdl");

    wsdl.addAttribute("version", "1.0.0");
    wsdl.addAttribute("author", "Aparna");
    wsdl.addAttribute("description", "added encoded url wsdl");
    wsdlManager.addWsdl(wsdl);
    assertFalse(wsdl.getId().isEmpty());
    assertNotNull(wsdl);
    assertTrue(wsdl.getAttribute("author").contentEquals("Aparna")); // encoded url wsdl
    // addition verification
  }
  /** adding an valid wsdl with corrupted policies: exception verified via expectedExceptions */
  @Test(
      groups = "wso2.greg",
      description = "Add valid wsdl with corrupted policies",
      expectedExceptions = GovernanceException.class)
  public void testAddValidWSDLWithCorruptedPolicies()
      throws RemoteException, GovernanceException, MalformedURLException {

    WsdlManager wsdlManager = new WsdlManager(governanceRegistry);

    Wsdl wsdl =
        wsdlManager.newWsdl(
            "https://svn.wso2.org/repos/wso2/carbon/platform/trunk/platform-integration/"
                + "platform-automated-test-suite/org.wso2.carbon.automation.test.repo/src/main/resources/artifacts/"
                + "GREG/wsdl/wsdlWithCorruptedPolicy.wsdl");

    wsdl.addAttribute("version", "1.0.0");
    wsdl.addAttribute("author", "Aparna");
    wsdl.addAttribute("description", "added valid wsdl with corrupted Policy via url");
    wsdlManager.addWsdl(wsdl);
  }
コード例 #8
0
ファイル: WsdlManager.java プロジェクト: rcamus/platform
  /**
   * 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);
        }
      }
    }
  }
コード例 #9
0
ファイル: WsdlManager.java プロジェクト: rcamus/platform
 /**
  * Adds a new WSDL artifact from the given URL.
  *
  * @param url the given URL.
  * @return the artifact added.
  * @throws GovernanceException if the operation failed.
  */
 public Wsdl newWsdl(String url) throws GovernanceException {
   String wsdlId = UUID.randomUUID().toString();
   Wsdl wsdl = new Wsdl(wsdlId, url);
   wsdl.associateRegistry(registry);
   return wsdl;
 }
コード例 #10
0
ファイル: WsdlManager.java プロジェクト: rcamus/platform
 /**
  * Sets content of the given WSDL artifact to the given resource on the registry.
  *
  * @param wsdl the WSDL artifact.
  * @param wsdlResource the content resource.
  * @throws GovernanceException if the operation failed.
  */
 protected void setContent(Wsdl wsdl, Resource wsdlResource) throws GovernanceException {
   if (wsdl.getWsdlElement() != null) {
     OMElement contentElement = wsdl.getWsdlElement().cloneOMElement();
     try {
       for (String importType : new String[] {"import", "include"}) {
         List<OMElement> wsdlImports =
             GovernanceUtils.evaluateXPathToElements("//wsdl:" + importType, contentElement);
         for (OMElement wsdlImport : wsdlImports) {
           OMAttribute location = wsdlImport.getAttribute(new QName("location"));
           if (location != null) {
             String path = location.getAttributeValue();
             if (path.indexOf(";version:") > 0) {
               location.setAttributeValue(path.substring(0, path.lastIndexOf(";version:")));
             }
           }
         }
       }
       for (String importType : new String[] {"import", "include", "redefine"}) {
         List<OMElement> schemaImports =
             GovernanceUtils.evaluateXPathToElements("//xsd:" + importType, contentElement);
         for (OMElement schemaImport : schemaImports) {
           OMAttribute location = schemaImport.getAttribute(new QName("schemaLocation"));
           if (location != null) {
             String path = location.getAttributeValue();
             if (path.indexOf(";version:") > 0) {
               location.setAttributeValue(path.substring(0, path.lastIndexOf(";version:")));
             }
           }
         }
       }
     } catch (JaxenException ignore) {
     }
     String wsdlContent = contentElement.toString();
     try {
       wsdlResource.setContent(wsdlContent);
     } catch (RegistryException e) {
       String msg =
           "Error in setting the content from wsdl, wsdl id: "
               + wsdl.getId()
               + ", wsdl path: "
               + wsdl.getPath()
               + ".";
       log.error(msg, e);
       throw new GovernanceException(msg, e);
     }
   }
   // and set all the attributes as properties.
   String[] attributeKeys = wsdl.getAttributeKeys();
   if (attributeKeys != null) {
     Properties properties = new Properties();
     for (String attributeKey : attributeKeys) {
       String[] attributeValues = wsdl.getAttributes(attributeKey);
       if (attributeValues != null) {
         // The list obtained from the Arrays#asList method is
         // immutable. Therefore,
         // we create a mutable object out of it before adding it as
         // a property.
         properties.put(attributeKey, new ArrayList<String>(Arrays.asList(attributeValues)));
       }
     }
     wsdlResource.setProperties(properties);
   }
   wsdlResource.setUUID(wsdl.getId());
 }
コード例 #11
0
ファイル: WsdlManager.java プロジェクト: rcamus/platform
  /**
   * 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);
        }
      }
    }
  }