You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ApplicationServlet.java 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * Copyright 2011 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.terminal.gwt.server;
  17. import javax.servlet.ServletException;
  18. import javax.servlet.http.HttpServletRequest;
  19. import com.vaadin.Application;
  20. import com.vaadin.terminal.DefaultUIProvider;
  21. import com.vaadin.terminal.gwt.server.ServletPortletHelper.ApplicationClassException;
  22. /**
  23. * This servlet connects a Vaadin Application to Web.
  24. *
  25. * @author Vaadin Ltd.
  26. * @since 5.0
  27. */
  28. @SuppressWarnings("serial")
  29. public class ApplicationServlet extends AbstractApplicationServlet {
  30. // Private fields
  31. private Class<? extends Application> applicationClass;
  32. /**
  33. * Called by the servlet container to indicate to a servlet that the servlet
  34. * is being placed into service.
  35. *
  36. * @param servletConfig
  37. * the object containing the servlet's configuration and
  38. * initialization parameters
  39. * @throws javax.servlet.ServletException
  40. * if an exception has occurred that interferes with the
  41. * servlet's normal operation.
  42. */
  43. @Override
  44. public void init(javax.servlet.ServletConfig servletConfig)
  45. throws javax.servlet.ServletException {
  46. super.init(servletConfig);
  47. // Loads the application class using the classloader defined in the
  48. // deployment configuration
  49. try {
  50. applicationClass = ServletPortletHelper
  51. .getApplicationClass(getDeploymentConfiguration());
  52. } catch (ApplicationClassException e) {
  53. throw new ServletException(e);
  54. }
  55. }
  56. @Override
  57. protected Application getNewApplication(HttpServletRequest request)
  58. throws ServletException {
  59. // Creates a new application instance
  60. try {
  61. final Application application = getApplicationClass().newInstance();
  62. application.addUIProvider(new DefaultUIProvider());
  63. return application;
  64. } catch (final IllegalAccessException e) {
  65. throw new ServletException("getNewApplication failed", e);
  66. } catch (final InstantiationException e) {
  67. throw new ServletException("getNewApplication failed", e);
  68. } catch (ClassNotFoundException e) {
  69. throw new ServletException("getNewApplication failed", e);
  70. }
  71. }
  72. @Override
  73. protected Class<? extends Application> getApplicationClass()
  74. throws ClassNotFoundException {
  75. return applicationClass;
  76. }
  77. }