use of com.vaadin.flow.server.ServiceException 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.ServiceException in project flow by vaadin.
the class ApplicationRunnerServlet method createServletService.
@SuppressWarnings("serial")
@Override
protected VaadinServletService createServletService(DeploymentConfiguration deploymentConfiguration) throws ServiceException {
// service doesn't use router actually. UI class is responsible to show
// and update the content by itself with only root route available
VaadinServletService service = new VaadinServletService(this, deploymentConfiguration) {
@Override
public Router getRouter() {
Router router = new Router(getRouteRegistry()) {
@Override
public int navigate(UI ui, Location location, NavigationTrigger trigger, JsonValue state) {
ui.getPage().getHistory().pushState(null, location);
return HttpServletResponse.SC_OK;
}
};
return router;
}
};
service.init();
final SystemMessagesProvider provider = service.getSystemMessagesProvider();
service.setSystemMessagesProvider((SystemMessagesProvider) systemMessagesInfo -> {
if (systemMessagesInfo.getRequest() == null) {
return provider.getSystemMessages(systemMessagesInfo);
}
Object messages = systemMessagesInfo.getRequest().getAttribute(CUSTOM_SYSTEM_MESSAGES_PROPERTY);
if (messages instanceof SystemMessages) {
return (SystemMessages) messages;
}
return provider.getSystemMessages(systemMessagesInfo);
});
return service;
}
use of com.vaadin.flow.server.ServiceException in project flow by vaadin.
the class DefaultTemplateParserTest method setUp.
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
VaadinServletRequest request = Mockito.mock(VaadinServletRequest.class);
VaadinSession session = Mockito.mock(VaadinSession.class);
factory = (VaadinUriResolverFactory) vaadinRequest -> resolver;
Mockito.when(session.getAttribute(VaadinUriResolverFactory.class)).thenReturn(factory);
Mockito.when(service.getDependencyFilters()).thenReturn(Collections.emptyList());
WrappedHttpSession wrappedSession = Mockito.mock(WrappedHttpSession.class);
HttpSession httpSession = Mockito.mock(HttpSession.class);
Mockito.when(wrappedSession.getHttpSession()).thenReturn(httpSession);
servlet = new VaadinServlet() {
@Override
protected VaadinServletService createServletService() throws ServletException, ServiceException {
return service;
}
@Override
public ServletContext getServletContext() {
return servletContext;
}
};
Mockito.when(service.getServlet()).thenReturn(servlet);
Mockito.when(resolver.resolveVaadinUri("/bar.html")).thenReturn("bar.html");
Mockito.when(resolver.resolveVaadinUri("/bar1.html")).thenReturn("bar1.html");
Mockito.when(resolver.resolveVaadinUri("/bundle.html")).thenReturn("bundle.html");
Mockito.when(request.getWrappedSession()).thenReturn(wrappedSession);
Mockito.when(request.getServletPath()).thenReturn("");
Mockito.when(servletContext.getResourceAsStream("/bar.html")).thenReturn(new ByteArrayInputStream("<dom-module id='bar'></dom-module>".getBytes(StandardCharsets.UTF_8)));
Mockito.when(servletContext.getResourceAsStream("/bar1.html")).thenReturn(new ByteArrayInputStream("<dom-module id='foo'></dom-module>".getBytes(StandardCharsets.UTF_8)));
Mockito.when(servletContext.getResourceAsStream("/bundle.html")).thenReturn(getBundle(), getBundle(), getBundle());
CurrentInstance.set(VaadinRequest.class, request);
CurrentInstance.set(VaadinSession.class, session);
CurrentInstance.set(VaadinService.class, service);
}
use of com.vaadin.flow.server.ServiceException in project flow by vaadin.
the class SpringVaadinServletService method loadInstantiators.
@Override
protected Optional<Instantiator> loadInstantiators() throws ServiceException {
Optional<Instantiator> spiInstantiator = super.loadInstantiators();
List<Instantiator> springInstantiators = context.getBeansOfType(Instantiator.class).values().stream().filter(instantiator -> instantiator.init(this)).collect(Collectors.toList());
if (spiInstantiator.isPresent() && !springInstantiators.isEmpty()) {
throw new ServiceException("Cannot init VaadinService because there are multiple eligible " + "instantiator implementations: Java SPI registered instantiator " + spiInstantiator.get() + " and Spring instantiator beans: " + springInstantiators);
}
if (!spiInstantiator.isPresent() && springInstantiators.isEmpty()) {
Instantiator defaultInstantiator = new SpringInstantiator(this, context);
defaultInstantiator.init(this);
return Optional.of(defaultInstantiator);
}
return spiInstantiator.isPresent() ? spiInstantiator : springInstantiators.stream().findFirst();
}
Aggregations