AutomaticDispatcherUrlService implements DispatcherUrlService { @Override public String localize(String externalUrl) { String localBase = getLocalDispatcherUrl(); String dispatcherBase = getDispatcherUrl(); if (externalUrl.startsWith(dispatcherBase)) { return localBase + externalUrl.substring(dispatcherBase.length()); } else { return externalUrl; } }  @Override String getDispatcherUrl(); @Override String getLocalDispatcherUrl(); @Api void setLocalDispatcherUrl(String localDispatcherUrl); @Override String localize(String externalUrl);  }
@Test public void testLocalizeAutomatic() { AutomaticDispatcherUrlService adus = new AutomaticDispatcherUrlService(); MockHttpServletRequest mockRequest = new MockHttpServletRequest(); mockRequest.setScheme("http"); mockRequest.setServerName("myhost"); mockRequest.setServerPort(80); mockRequest.setLocalName("localhost"); mockRequest.setLocalPort(8080); mockRequest.setContextPath("/test"); mockRequest.addHeader(X_FORWARD_HOST_HEADER, "geomajas.org"); ServletRequestAttributes attributes = new ServletRequestAttributes(mockRequest); RequestContextHolder.setRequestAttributes(attributes); Assert.assertEquals("http: RequestContextHolder.setRequestAttributes(null); }