use of com.vaadin.flow.server.VaadinServlet in project flow by vaadin.
the class ServletHelperTest method setup.
@Before
public void setup() throws ServletException {
servlet = new VaadinServlet();
servlet.init(new MockServletConfig());
}
use of com.vaadin.flow.server.VaadinServlet in project flow by vaadin.
the class VaadinServiceTest method createService.
private static VaadinService createService() {
ServletConfig servletConfig = new MockServletConfig();
VaadinServlet servlet = new VaadinServlet();
try {
servlet.init(servletConfig);
} catch (ServletException e) {
throw new RuntimeException(e);
}
VaadinService service = servlet.getService();
return service;
}
use of com.vaadin.flow.server.VaadinServlet in project flow by vaadin.
the class WebJarServerTest method init.
@Before
public void init() throws Exception {
DeploymentConfiguration configuration = Mockito.mock(DeploymentConfiguration.class);
Mockito.when(configuration.getDevelopmentFrontendPrefix()).thenReturn(Constants.FRONTEND_URL_DEV_DEFAULT);
VaadinServletService servletService = Mockito.mock(VaadinServletService.class);
ServletContext servletContext = Mockito.mock(ServletContext.class);
servlet = new VaadinServlet() {
@Override
protected VaadinServletService createServletService() throws ServletException, ServiceException {
return servletService;
}
@Override
public ServletContext getServletContext() {
return servletContext;
}
};
Mockito.when(servletService.getDeploymentConfiguration()).thenReturn(configuration);
Mockito.when(configuration.areWebJarsEnabled()).thenReturn(true);
servlet.init(Mockito.mock(ServletConfig.class));
Field webJarServerField = VaadinServlet.class.getDeclaredField("webJarServer");
webJarServerField.setAccessible(true);
webJarServer = (WebJarServer) webJarServerField.get(servlet);
// webJarServer = new WebJarServer(configuration);
// context = Mockito.mock(ServletContext.class);
Mockito.when(servletContext.getResource(GRID_WEBJAR)).thenReturn(new URL("http://localhost:8080" + GRID_DEPENDENCY));
}
use of com.vaadin.flow.server.VaadinServlet in project flow by vaadin.
the class DefaultTemplateParser method getTemplateContent.
@Override
public TemplateData getTemplateContent(Class<? extends PolymerTemplate<?>> clazz, String tag) {
VaadinServlet servlet = VaadinServlet.getCurrent();
boolean logEnabled = LOG_CACHE.get(clazz).compareAndSet(false, true);
List<Dependency> dependencies = AnnotationReader.getAnnotationsFor(clazz, HtmlImport.class).stream().map(htmlImport -> new Dependency(Type.HTML_IMPORT, htmlImport.value(), htmlImport.loadMode())).collect(Collectors.toList());
FilterContext filterContext = new FilterContext(VaadinSession.getCurrent());
for (DependencyFilter filter : VaadinService.getCurrent().getDependencyFilters()) {
dependencies = filter.filter(new ArrayList<>(dependencies), filterContext);
}
for (Dependency dependency : dependencies) {
if (dependency.getType() != Type.HTML_IMPORT) {
continue;
}
String url = dependency.getUrl();
String path = servlet.resolveResource(url);
if (logEnabled) {
getLogger().debug("Html import path '{}' is resolved to '{}'", url, path);
}
try (InputStream content = servlet.getResourceAsStream(path)) {
if (content == null) {
throw new IllegalStateException(String.format("Can't find resource '%s' " + "via the servlet context", url));
}
Element templateElement = parseHtmlImport(content, url, tag);
if (logEnabled && templateElement != null) {
getLogger().debug("Found a template file containing template " + "definition for the tag '{}' by the path '{}'", tag, url);
}
if (templateElement != null) {
return new TemplateData(url, templateElement);
}
} catch (IOException exception) {
// ignore exception on close()
if (logEnabled) {
getLogger().warn("Couldn't close template input stream", exception);
}
}
}
throw new IllegalStateException(String.format("Couldn't find the " + "definition of the element with tag '%s' " + "in any template file declared using @'%s' annotations. " + "Check the availability of the template files in your WAR " + "file or provide alternative implementation of the " + "method getTemplateContent() which should return an element " + "representing the content of the template file", tag, HtmlImport.class.getSimpleName()));
}
use of com.vaadin.flow.server.VaadinServlet in project flow by vaadin.
the class WebpackHandlerTest method vaadinServlet_forDifferentRequests_shouldHaveCorrectResponse.
@Test
public void vaadinServlet_forDifferentRequests_shouldHaveCorrectResponse() throws Exception {
HttpServletRequest request = prepareRequest("/VAADIN/foo.js");
HttpServletResponse response = prepareResponse();
final String globalResponse = "{ \"VAADIN/foo.js\": " + "\"VAADIN/foo.js\" }";
int port = prepareHttpServer(0, HTTP_OK, globalResponse);
VaadinServlet servlet = prepareServlet(port);
servlet.service(request, response);
assertEquals(HTTP_OK, responseStatus);
httpServer.stop(0);
prepareHttpServer(port, HTTP_NOT_MODIFIED, "");
servlet.service(request, response);
assertEquals(HTTP_NOT_MODIFIED, responseStatus);
httpServer.stop(0);
exception.expect(ConnectException.class);
servlet.service(request, response);
}
Aggregations