public static FormatConverter getConverter(String name) {
    if (StringUtilities.isBlank(name)) {
      return null;
    }

    return CONVERSION_MAP.get(name);
  }
  private int getEntityLength() throws IOException {
    // Default to -1, which will be treated as an unknown entity length leading to the usage of
    // chunked encoding.
    int entityLength = -1;
    switch (chunkedEncoding.toLowerCase()) {
      case "true":
      case "1":
        break;
      case "auto":
        if (StringUtilities.nullSafeEqualsIgnoreCase(
            sourceRequest.getHeader("transfer-encoding"), "chunked")) {
          break;
        }
      case "false":
      case "0":
        // todo: optimize so subsequent calls to this method do not need to read/copy the entity
        final ByteArrayOutputStream sourceEntity = new ByteArrayOutputStream();
        RawInputStreamReader.instance().copyTo(sourceRequest.getInputStream(), sourceEntity);

        final ServletInputStream readableEntity =
            new BufferedServletInputStream(new ByteArrayInputStream(sourceEntity.toByteArray()));
        sourceRequest = new HttpServletRequestWrapper(sourceRequest, readableEntity);

        entityLength = sourceEntity.size();
        break;
      default:
        LOG.warn("Invalid chunked encoding value -- using chunked encoding");
        break;
    }
    return entityLength;
  }
Пример #3
0
  @Override
  public void applyTo(MutableHttpServletRequest request) {
    if (requestHeaderManager().hasHeaders()) {
      requestHeaderManager().applyTo(request);
    }

    if (requestUriQuery != null) {
      request.setQueryString(requestUriQuery);
    }

    if (requestUri != null && StringUtilities.isNotBlank(requestUri)) {
      request.setRequestUri(requestUri);
    }

    if (requestUrl != null && StringUtilities.isNotBlank(requestUrl.toString())) {
      request.setRequestUrl(requestUrl);
    }

    for (RouteDestination dest : destinations) {
      request.addDestination(dest);
    }
  }
  public List<FilterContext> buildFilterContexts(
      ClassLoaderManagerService classLoaderContextManager, ReposeCluster domain, Node localHost) {
    Thread.currentThread().setName(instanceInfo.toString());
    final List<FilterContext> filterContexts = new LinkedList<FilterContext>();

    if (localHost == null || domain == null) {
      LOG.error(
          "Unable to identify the local host in the system model - please check your system-model.cfg.xml");
      throw new IllegalArgumentException("Domain and host cannot be null");
    }

    if (domain.getFilters() != null && domain.getFilters().getFilter() != null) {
      for (org.openrepose.core.systemmodel.Filter papiFilter : domain.getFilters().getFilter()) {

        if (StringUtilities.isBlank(papiFilter.getName())) {
          LOG.error(
              "Filter declaration has a null or empty name value - please check your system model configuration");
          continue;
        }

        if (classLoaderContextManager.hasFilter(papiFilter.getName())) {
          final FilterContext context = getFilterContext(classLoaderContextManager, papiFilter);

          if (context != null) {
            filterContexts.add(context);
          } else {
            filterContexts.add(new FilterContext(null, null, papiFilter));
          }
        } else {
          LOG.error(
              "Unable to satisfy requested filter chain - none of the loaded artifacts supply a filter named "
                  + papiFilter.getName());
          filterContexts.add(new FilterContext(null, null, papiFilter));
        }
      }
    }

    return filterContexts;
  }