ProxyAwareUriBuilderFactory { @Nonnull public UriBuilder newInstance() { if (baseUriBuilder == null) { @Nonnull UriBuilder uriBuilder; try { @Nonnull final String scheme = getScheme(); @Nonnull final String authority = getAuthority(); @Nonnull final String[] pathPrefix = getPathPrefix(); @Nonnull final URI baseUri = new URI(scheme, authority, null, null, null); uriBuilder = UriBuilder.fromUri(baseUri); for (final String segment : pathPrefix) { uriBuilder.path(segment); } } catch (final HeaderMissingException | InvalidHeaderValueException | URISyntaxException e) { LOG.error(NEW_INSTANCE_ERROR_MESSAGE, uriInfo.getRequestUri(), e); uriBuilder = UriBuilder.fromUri(uriInfo.getBaseUri()); } baseUriBuilder = uriBuilder; } return baseUriBuilder.clone(); } ProxyAwareUriBuilderFactory();   ProxyAwareUriBuilderFactory(
            @Nonnull final HttpServletRequest httpServletRequest,
            @Nonnull final UriInfo uriInfo); @Nonnull UriBuilder newInstance();  }
@Test public void testNewInstance() throws URISyntaxException { LOG.info("testNewInstance"); when(httpServletRequest.getHeader(HEADER_NAME_X_HTTPS)).thenReturn(HEADER_VALUE_X_HTTPS_TRUE); when(httpServletRequest.getHeader(HEADER_NAME_X_FORWARDED_HOST)).thenReturn(HEADER_VALUE_X_FORWARDED_HOST); when(httpServletRequest.getHeader(HEADER_NAME_X_ORIGINAL_URI)).thenReturn(HEADER_VALUE_X_ORIGINAL_URI); when(uriInfo.getRequestUri()).thenReturn(internalUri); final UriBuilder uriBuilder = impl.newInstance(); assertThat(uriBuilder, is(notNullValue())); final URI uri = uriBuilder.build(); assertThat(uri, is(notNullValue())); assertThat(uri, is(referenceExternalBaseUri)); }