コード例 #1
0
  private URL getLocationUrl(MutableHttpServletResponse servletResponse)
      throws MalformedURLException {
    String locationHeader = servletResponse.getHeader(CommonHttpHeader.LOCATION.name());
    if (StringUtilities.isNotBlank(locationHeader)) {
      return new URL(locationHeader);
    }

    return null;
  }
コード例 #2
0
    @Test
    public void shouldRemoveRootPathWithoutPort80() throws MalformedURLException {
      // original request http://myhost.com/test
      when(originalRequest.getServerName()).thenReturn("myhost.com");
      when(originalRequest.getServerPort()).thenReturn(80);
      when(originalRequest.getContextPath()).thenReturn("");

      // destination http://otherhost.com/mocks/test
      final String destUri = "http://otherhost.com/mocks/test";
      final String requestedContext = "";
      final String rootPath = "/mocks";

      when(response.getHeader(eq(CommonHttpHeader.LOCATION.name())))
          .thenReturn("http://myhost.com/mocks/test");

      instance.setLocationHeader(originalRequest, response, destUri, requestedContext, rootPath);

      final String expected = "http://myhost.com/test";
      verify(response).setHeader(eq(CommonHttpHeader.LOCATION.name()), eq(expected));
    }
コード例 #3
0
  public void setLocationHeader(
      HttpServletRequest originalRequest,
      MutableHttpServletResponse servletResponse,
      String destinationUri,
      String requestedContext,
      String rootPath)
      throws MalformedURLException {
    final URL locationUrl = getLocationUrl(servletResponse);

    if (locationUrl == null) {
      return;
    }

    final URL requestedHostUrl = extractHostPath(originalRequest);
    final URL proxiedHostUrl = new TargetHostInfo(destinationUri).getProxiedHostUrl();

    final String translatedLocationUrl =
        translateLocationUrl(
            locationUrl, proxiedHostUrl, requestedHostUrl, requestedContext, rootPath);

    if (translatedLocationUrl != null) {
      servletResponse.setHeader(CommonHttpHeader.LOCATION.name(), translatedLocationUrl);
    }
  }