예제 #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;
  }
예제 #2
0
  @Override
  public void deployPackage(
      PackageModel packageRN,
      String token,
      InputStream stream,
      Map<String, DatabaseAction> associatedDatabases) {
    try {
      install(stream, packageRN, associatedDatabases);

      String name = packageRN.getUrlPath();
      if (packageRN.getUrlPath() == null || packageRN.getUrlPath().isEmpty()) name = "ROOT";

      name = name + PackageFileType.APP_WAR.getDotExtension();
      String file = packageRN.getName() + PackageFileType.APP_WAR.getDotExtension();
      progress.status("... deploying application: " + name, 1, LogLevel.INFO);
      requestTaskService.deploy(packageRN.getId(), name, file);
      progress.status("Archive version", 2, LogLevel.INFO);
      OPFEngine.RegistryService.archive(packageRN.getId());
      progress.status("Installation process has been completed", 2, LogLevel.INFO);
    } catch (ClientHandlerException e) {
      if (e.getCause() instanceof FileNotFoundException) {
        progress.status("Package archive has not been found", 1, LogLevel.ERROR);
      } else if (e.getCause() instanceof ConnectException) {
        progress.status("Connection refused", 1, LogLevel.ERROR);
      } else {
        progress.status("Occurred error", 1, LogLevel.ERROR);
      }
      logger.error(e.getMessage(), e);
    } catch (Exception e) {
      progress.status("Occurred error", 1, LogLevel.ERROR);
      logger.error(e.getMessage(), e);
    } finally {
      if (stream != null) {
        IOUtils.closeQuietly(stream);
      }
    }
  }
예제 #3
0
  @Override
  public void route(
      MutableHttpServletRequest servletRequest, MutableHttpServletResponse servletResponse)
      throws IOException, ServletException, URISyntaxException {
    DestinationLocation location = null;

    if (!StringUtilities.isBlank(defaultDst)) {
      servletRequest.addDestination(defaultDst, servletRequest.getRequestURI(), -1);
    }
    RouteDestination routingDestination = servletRequest.getDestination();
    String rootPath = "";

    if (routingDestination != null) {
      Destination configDestinationElement =
          destinations.get(routingDestination.getDestinationId());
      if (configDestinationElement == null) {
        LOG.warn(
            "Invalid routing destination specified: "
                + routingDestination.getDestinationId()
                + " for domain: "
                + domain.getId());
        ((HttpServletResponse) servletResponse).setStatus(HttpStatusCode.NOT_FOUND.intValue());
      } else {
        location =
            locationBuilder.build(
                configDestinationElement, routingDestination.getUri(), servletRequest);

        rootPath = configDestinationElement.getRootPath();
      }
    }

    if (location != null) {
      // According to the Java 6 javadocs the routeDestination passed into getContext:
      // "The given path [routeDestination] must begin with /, is interpreted relative to the
      // server's document root
      // and is matched against the context roots of other web applications hosted on this
      // container."
      final ServletContext targetContext = context.getContext(location.getUri().toString());

      if (targetContext != null) {
        // Capture this for Location header processing
        final HttpServletRequest originalRequest = (HttpServletRequest) servletRequest.getRequest();

        String uri =
            new DispatchPathBuilder(location.getUri().getPath(), targetContext.getContextPath())
                .build();
        final RequestDispatcher dispatcher = targetContext.getRequestDispatcher(uri);

        servletRequest.setRequestUrl(new StringBuffer(location.getUrl().toExternalForm()));
        servletRequest.setRequestUri(location.getUri().getPath());
        requestHeaderService.setVia(servletRequest);
        requestHeaderService.setXForwardedFor(servletRequest);
        if (dispatcher != null) {
          LOG.debug("Attempting to route to " + location.getUri());
          LOG.debug("Request URL: " + ((HttpServletRequest) servletRequest).getRequestURL());
          LOG.debug("Request URI: " + ((HttpServletRequest) servletRequest).getRequestURI());
          LOG.debug("Context path = " + targetContext.getContextPath());

          final long startTime = System.currentTimeMillis();
          try {
            reportingService.incrementRequestCount(routingDestination.getDestinationId());
            dispatcher.forward(servletRequest, servletResponse);
            final long stopTime = System.currentTimeMillis();
            reportingService.recordServiceResponse(
                routingDestination.getDestinationId(),
                servletResponse.getStatus(),
                (stopTime - startTime));
            responseHeaderService.fixLocationHeader(
                originalRequest,
                servletResponse,
                routingDestination,
                location.getUri().toString(),
                rootPath);
          } catch (ClientHandlerException e) {
            if (e.getCause() instanceof ReadLimitReachedException) {
              LOG.error("Error reading request content", e);
              servletResponse.sendError(
                  HttpStatusCode.REQUEST_ENTITY_TOO_LARGE.intValue(),
                  "Error reading request content");
              servletResponse.setLastException(e);
            } else {
              LOG.error("Connection Refused to " + location.getUri() + " " + e.getMessage(), e);
              ((HttpServletResponse) servletResponse)
                  .setStatus(HttpStatusCode.SERVICE_UNAVAIL.intValue());
            }
          }
        }
      }
    }
  }