use of com.enonic.xp.web.vhost.impl.mapping.VirtualHostMapping in project xp by enonic.
the class VirtualHostResolverImplTest method testMatches_wrongHost.
@Test
public void testMatches_wrongHost() {
this.virtualHostMapping = new VirtualHostMapping("mymapping", "foo.no", "/", "/a", VirtualHostIdProvidersMapping.create().build(), 0);
when(virtualHostService.getVirtualHosts()).thenReturn(List.of(this.virtualHostMapping));
VirtualHostResolver virtualHostResolver = new VirtualHostResolverImpl(virtualHostService);
HttpServletRequest req = mock(HttpServletRequest.class);
when(req.getServerName()).thenReturn("localhost");
when(req.getRequestURI()).thenReturn("/a/b");
assertNull(virtualHostResolver.resolveVirtualHost(req));
}
use of com.enonic.xp.web.vhost.impl.mapping.VirtualHostMapping in project xp by enonic.
the class VirtualHostFilterTest method addMapping.
private void addMapping() {
final VirtualHostMapping mapping = new VirtualHostMapping("test", "enonic.com", "/rest", "/admin/rest", VirtualHostIdProvidersMapping.create().build(), 0);
this.virtualHosts.add(mapping);
}
use of com.enonic.xp.web.vhost.impl.mapping.VirtualHostMapping in project xp by enonic.
the class VirtualHostResolverImplTest method testMatches_wrongSource.
@Test
public void testMatches_wrongSource() {
this.virtualHostMapping = new VirtualHostMapping("mymapping", "foo.no", "/b", "/a", VirtualHostIdProvidersMapping.create().build(), 0);
when(virtualHostService.getVirtualHosts()).thenReturn(List.of(this.virtualHostMapping));
VirtualHostResolver virtualHostResolver = new VirtualHostResolverImpl(virtualHostService);
HttpServletRequest req = mock(HttpServletRequest.class);
when(req.getServerName()).thenReturn("foo.no");
when(req.getRequestURI()).thenReturn("/a");
assertNull(virtualHostResolver.resolveVirtualHost(req));
}
use of com.enonic.xp.web.vhost.impl.mapping.VirtualHostMapping in project xp by enonic.
the class VirtualHostFilter method doHandle.
@Override
protected void doHandle(final HttpServletRequest req, final HttpServletResponse res, final FilterChain chain) throws Exception {
if (virtualHostConfigService.isEnabled()) {
final VirtualHost virtualHost = virtualHostResolver.resolveVirtualHost(req);
if (virtualHost == null) {
LOG.warn("Virtual host mapping could not be resolved for host [" + req.getServerName() + "] and path [" + req.getRequestURI() + "]");
res.setStatus(HttpServletResponse.SC_NOT_FOUND);
} else {
VirtualHostHelper.setVirtualHost(req, virtualHost);
final String targetPath = VirtualHostInternalHelper.getFullTargetPath(virtualHost, req);
final RequestDispatcher dispatcher = req.getRequestDispatcher(targetPath);
dispatcher.forward(req, res);
}
} else {
final VirtualHostMapping defaultVirtualHostMapping = generateDefaultVirtualHostMapping(req);
VirtualHostHelper.setVirtualHost(req, defaultVirtualHostMapping);
chain.doFilter(req, res);
}
}
use of com.enonic.xp.web.vhost.impl.mapping.VirtualHostMapping in project xp by enonic.
the class VirtualHostConfigMap method buildMapping.
private VirtualHostMapping buildMapping(final String name) {
final String prefix = "mapping." + name + ".";
final String hostString = getString(prefix + "host");
final String host = hostString != null ? hostString : "localhost";
final String source = normalizePath(getString(prefix + "source"));
final String target = normalizePath(getString(prefix + "target"));
final VirtualHostIdProvidersMapping idProvidersMapping = getHostIdProvidersMapping(prefix);
final int order = getInt(prefix + "order", Integer.MAX_VALUE);
return new VirtualHostMapping(name, host, source, target, idProvidersMapping, order);
}
Aggregations