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 2.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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.server;
  17. import javax.servlet.ServletException;
  18. import javax.servlet.http.HttpServletRequest;
  19. import com.vaadin.Application;
  20. import com.vaadin.server.ServletPortletHelper.ApplicationClassException;
  21. /**
  22. * This servlet connects a Vaadin Application to Web.
  23. *
  24. * @author Vaadin Ltd.
  25. * @since 5.0
  26. */
  27. @SuppressWarnings("serial")
  28. public class ApplicationServlet extends AbstractApplicationServlet {
  29. // Private fields
  30. private Class<? extends Application> applicationClass;
  31. /**
  32. * Called by the servlet container to indicate to a servlet that the servlet
  33. * is being placed into service.
  34. *
  35. * @param servletConfig
  36. * the object containing the servlet's configuration and
  37. * initialization parameters
  38. * @throws javax.servlet.ServletException
  39. * if an exception has occurred that interferes with the
  40. * servlet's normal operation.
  41. */
  42. @Override
  43. public void init(javax.servlet.ServletConfig servletConfig)
  44. throws javax.servlet.ServletException {
  45. super.init(servletConfig);
  46. // Loads the application class using the classloader defined in the
  47. // deployment configuration
  48. try {
  49. applicationClass = ServletPortletHelper
  50. .getApplicationClass(getDeploymentConfiguration());
  51. } catch (ApplicationClassException e) {
  52. throw new ServletException(e);
  53. }
  54. }
  55. @Override
  56. protected Application getNewApplication(HttpServletRequest request)
  57. throws ServletException {
  58. // Creates a new application instance
  59. try {
  60. final Application application = getApplicationClass().newInstance();
  61. application.addUIProvider(new DefaultUIProvider());
  62. return application;
  63. } catch (final IllegalAccessException e) {
  64. throw new ServletException("getNewApplication failed", e);
  65. } catch (final InstantiationException e) {
  66. throw new ServletException("getNewApplication failed", e);
  67. } catch (ClassNotFoundException e) {
  68. throw new ServletException("getNewApplication failed", e);
  69. }
  70. }
  71. @Override
  72. protected Class<? extends Application> getApplicationClass()
  73. throws ClassNotFoundException {
  74. return applicationClass;
  75. }
  76. }