Example #1
0
  public Map<String, ApplicationWrapper> getApplications() {
    Map<String, ApplicationWrapper> apps = new HashMap<String, ApplicationWrapper>();
    String csarUrl = getContainerUrl() + CONFIG.CSAR_LIST_REL_URL;

    try {
      String ret =
          this.jerseyClient
              .resource(csarUrl)
              .accept(MediaType.MEDIA_TYPE_WILDCARD)
              .get(String.class);

      DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
      DocumentBuilder builder = factory.newDocumentBuilder();
      Document parse = builder.parse(new InputSource(new StringReader(ret)));
      NodeList elementsByTagName = parse.getElementsByTagName("Reference");

      for (int i = 0; i < elementsByTagName.getLength(); i++) {
        Node item = elementsByTagName.item(i);
        String csarBaseUrl = item.getAttributes().getNamedItem("xlink:href").getNodeValue();
        // "self" is no application
        if (item.getAttributes().getNamedItem("xlink:title").getNodeValue().equals("Self")) {
          continue;
        }

        // Create Self Service Base Url
        String selfServiceBaseUrl = csarBaseUrl + CONFIG.METADATA_FOLDER;
        String data = get(selfServiceBaseUrl + CONFIG.METADATA_FILE);
        if (data == null || data.isEmpty()) {
          continue;
        }

        // Create Application
        ApplicationWrapper application = ApplicationUnmarshaller.unmarshall(data);
        application.setSelfServiceBaseUrl(selfServiceBaseUrl);
        apps.put(selfServiceBaseUrl, application);
      }

    } catch (com.sun.jersey.api.client.ClientHandlerException e) {
      if (e.getCause() != null && e.getCause() instanceof java.net.ConnectException) {
        throw new CannotConnectToContainerException(getContainerUrl(), e.getCause());
      } else {
        throw new RuntimeException("Failed to get applications from " + csarUrl, e);
      }

    } catch (com.sun.jersey.api.client.UniformInterfaceException e) {
      throw new CannotConnectToContainerException(
          csarUrl, (e.getCause() != null) ? e.getCause() : e);

    } catch (Exception e) {
      throw new RuntimeException("Failed to get applications from " + csarUrl, e);
    }

    return apps;
  }
Example #2
0
 public String get(ApplicationWrapper application, String url) {
   return get(application.convertToAbsoluteUrl(url));
 }