| /******************************************************************************* |
| * Copyright (c) 2012, 2014 - Lunifera GmbH (Gross Enzersdorf, Austria), Loetz GmbH&Co.KG (69115 Heidelberg, Germany) |
| * |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License 2.0 |
| * which accompanies this distribution, and is available at |
| * https://www.eclipse.org/legal/epl-2.0/ |
| * |
| * SPDX-License-Identifier: EPL-2.0 |
| * |
| * Contributors: |
| * Florian Pirchner - initial API and implementation |
| * |
| *******************************************************************************/ |
| package org.eclipse.osbp.vaaclipse.addons.app.servlet; |
| |
| import javax.servlet.http.HttpServletRequest; |
| |
| import org.eclipse.e4.core.contexts.IEclipseContext; |
| import org.eclipse.osbp.runtime.common.session.IEclipseContextProvider; |
| import org.eclipse.osbp.runtime.common.session.ISession; |
| import org.eclipse.osbp.runtime.web.vaadin.databinding.VaadinObservables; |
| |
| import com.vaadin.server.DeploymentConfiguration; |
| import com.vaadin.server.ServiceException; |
| import com.vaadin.server.VaadinRequest; |
| import com.vaadin.server.VaadinServlet; |
| import com.vaadin.server.VaadinServletService; |
| import com.vaadin.server.VaadinSession; |
| import com.vaadin.ui.UI; |
| |
| /** |
| * The Class OSGiServletService. |
| */ |
| @SuppressWarnings("serial") |
| public class OSGiServletService extends VaadinServletService { |
| |
| /** The factory. */ |
| private final IVaadinSessionFactory factory; |
| |
| /** |
| * Instantiates a new OS gi servlet service. |
| * |
| * @param servlet |
| * the servlet |
| * @param deploymentConfiguration |
| * the deployment configuration |
| * @param factory |
| * the factory |
| * @throws ServiceException |
| * the service exception |
| */ |
| public OSGiServletService(VaadinServlet servlet, DeploymentConfiguration deploymentConfiguration, |
| IVaadinSessionFactory factory) throws ServiceException { |
| super(servlet, deploymentConfiguration); |
| |
| this.factory = factory; |
| } |
| |
| /* |
| * (non-Javadoc) |
| * |
| * @see |
| * com.vaadin.server.VaadinServletService#getConfiguredWidgetset(com.vaadin. |
| * server.VaadinRequest) |
| */ |
| @Override |
| public String getConfiguredWidgetset(VaadinRequest request) { |
| return super.getConfiguredWidgetset(request); |
| } |
| |
| /* |
| * (non-Javadoc) |
| * |
| * @see |
| * com.vaadin.server.VaadinService#createVaadinSession(com.vaadin.server. |
| * VaadinRequest) |
| */ |
| @Override |
| protected VaadinSession createVaadinSession(VaadinRequest request) throws ServiceException { |
| return factory.createSession(request, getCurrentServletRequest()); |
| } |
| |
| /* |
| * (non-Javadoc) |
| * |
| * @see |
| * com.vaadin.server.VaadinService#findUI(com.vaadin.server.VaadinRequest) |
| */ |
| public UI findUI(VaadinRequest request) { |
| UI instance = super.findUI(request); |
| |
| // activate the realm for the current ui and thread |
| VaadinObservables.activateRealm(instance); |
| |
| if (instance instanceof IEclipseContextProvider) { |
| IEclipseContext appContext = ((IEclipseContextProvider) instance).getEclipseContext(); |
| ISession.makeCurrent(appContext); |
| } |
| |
| return instance; |
| } |
| |
| /** |
| * Creates new instances of vaadin sessions. |
| */ |
| public interface IVaadinSessionFactory { |
| |
| /** |
| * Returns a new instance of a vaadin session. |
| * |
| * @param request |
| * the request |
| * @param httpServletRequest |
| * the http servlet request |
| * @return the vaadin session |
| */ |
| VaadinSession createSession(VaadinRequest request, HttpServletRequest httpServletRequest); |
| } |
| } |