1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package fr.paris.lutece.portal.service.servlet;
35
36 import fr.paris.lutece.portal.service.init.LuteceInitException;
37 import fr.paris.lutece.portal.service.plugin.Plugin;
38 import fr.paris.lutece.portal.service.util.AppLogService;
39
40 import java.util.ArrayList;
41 import java.util.List;
42
43 import javax.servlet.ServletContext;
44 import javax.servlet.http.HttpServlet;
45
46
47
48
49 public final class ServletService
50 {
51 private static ServletServicevlet/ServletService.html#ServletService">ServletService _singleton = new ServletService( );
52 private static ServletContext _context;
53 private List<LuteceServlet> _listServlets = new ArrayList<>( );
54
55
56
57
58 private ServletService( )
59 {
60 }
61
62
63
64
65
66
67 public static ServletService getInstance( )
68 {
69 return _singleton;
70 }
71
72
73
74
75
76
77
78
79
80 public void registerServlet( ServletEntry entry, Plugin plugin )
81 {
82 try
83 {
84 HttpServlet servlet = (HttpServlet) Class.forName( entry.getServletClass( ) ).newInstance( );
85 LuteceServletervice/servlet/LuteceServlet.html#LuteceServlet">LuteceServlet s = new LuteceServlet( entry.getName( ), servlet, entry.getMappingUrlPattern( ), plugin, entry.getInitParameters( ) );
86 _listServlets.add( s );
87 AppLogService.info( "New Servlet registered : {}", entry.getName( ) );
88
89 for ( String strKey : entry.getInitParameters( ).keySet( ) )
90 {
91 AppLogService.info( " * init parameter - name : '{}' - value : '{}'", strKey, entry.getInitParameters( ).get( strKey ) );
92 }
93 }
94 catch( InstantiationException | IllegalAccessException | ClassNotFoundException e )
95 {
96 AppLogService.error( "Error registering a servlet : {}", e.getMessage( ), e );
97 }
98 }
99
100
101
102
103
104
105
106 public static void setServletContext( ServletContext servletContext )
107 {
108 _context = servletContext;
109 }
110
111
112
113
114
115
116
117
118
119 public static void init( ServletContext context ) throws LuteceInitException
120 {
121 AppLogService.info( "Initialize plugins servlets" );
122 _context = context;
123
124 for ( LuteceServlet servlet : ServletService.getInstance( ).getServlets( ) )
125 {
126
127 try
128 {
129 if ( servlet.getPlugin( ).isInstalled( ) )
130 {
131
132 LuteceServletConfigeceServletConfig.html#LuteceServletConfig">LuteceServletConfig servletConfig = new LuteceServletConfig( servlet.getName( ), _context, servlet.getInitParameters( ) );
133 servlet.getServlet( ).init( servletConfig );
134 AppLogService.info( " * servlet '{}' from plugin {} initialized.", servlet.getName( ), servlet.getPlugin( ).getName( ) );
135 }
136 }
137 catch( Exception e )
138 {
139 AppLogService.error( "Error execution init() method - Servlet {}", servlet.getName( ), e );
140 throw new LuteceInitException( "Error execution init() method - Servlet " + servlet.getName( ), e );
141 }
142 }
143 }
144
145
146
147
148
149
150 public List<LuteceServlet> getServlets( )
151 {
152 return _listServlets;
153 }
154 }