Bonjour,
J'ai mis en place un filtre qui extrait et stocke la première partie l'URL et laisse continuer le traitement avec une HttpServletRequest qui utilise le reste de l'URL d'origine. Ceci permet aux utilisateurs d'accéder à mon application en précisant depuis l'URL le nom de leur société (Afin d'avoir une même application sur un même serveur pour N clients).
Grâce à ce filtre, l'accès à http:\\server\MaSociete\home.html est identique à http:\\server\home.html. Le filtre fonctionne et délègue bien la suite du traitement avec l'url remaniée mais Spring semble ne pas déduire correctement la vue Jsp à afficher. En effet, au lieu d'aller la rechercher dans \WEB-INF\views\*.jsp il la cherche directement dans le root (il cherche donc home.html dans mon exemple d'URL).
Voici mon filtre :
Et dans les logs, je constate que le dispatcher trouve le contrôleur à invoker (j'essaye d'accéder à la page /ui/home.html) :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
35
36
37
38
39
40
41
42
43
44
45
46 public void doFilter(final ServletRequest req, final ServletResponse resp, final FilterChain chain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) req; String uri = request.getRequestURI(); LOG.fine("Filtering request ["+uri+"]."); if ( !uri.startsWith("/ui") && uri.indexOf("/", 1)!=-1 && request.getParameter("ORGANIZATION")==null) { LOG.fine("IOrganisation name integrated from ["+uri+"]."); chain.doFilter(new OrganizationHttpServletRequest(request), resp); } else { LOG.fine("Request ["+uri+"] skipped."); chain.doFilter(request, resp); } } // ... private final static class OrganizationHttpServletRequest extends HttpServletRequestWrapper { public OrganizationHttpServletRequest(final HttpServletRequest request) { super(request); final String originalUri = request.getRequestURI(); final int index = originalUri.indexOf("/", 1); final Map<String, String> temp = new HashMap<String, String>(); temp.put("ORIGINAL_URI", originalUri); if ( index!=-1 ) { cleanUri = originalUri.substring(index); temp.put("ORGANIZATION", originalUri.substring(1, index)); } else { cleanUri = originalUri; } parameters = Collections.unmodifiableMap(temp); } @Override public String getRequestURI() { return cleanUri; } @Override public String getServletPath() { return cleanUri; }
J'ai crée la JSP dans "\WEB-INF\views\home.jsp" mais elle n'est jamais affichée par contre une page placée dans "\ui\home.html" est affichée...4-oct.-2010 14:23:44 be.gervaisb.myapp.web.filters.OrganizationIntegrationFilter doFilter
FIN: Filtering request [/org/ui/home.html].
04-oct.-2010 14:23:44 be.gervaisb.myapp.web.filters.OrganizationIntegrationFilter doFilter
FIN: IOrganisation name integrated from [/org/ui/home.html].
04-oct.-2010 14:23:44 org.springframework.web.servlet.DispatcherServlet doService
FIN: DispatcherServlet with name 'web' processing GET request for [/ui/home.html]
04-oct.-2010 14:23:44 org.springframework.web.servlet.handler.AbstractUrlHandlerMapping lookupHandler
FIN: Matching patterns for request [/ui/home.html] are [/ui/home.*]
04-oct.-2010 14:23:44 org.springframework.web.servlet.handler.AbstractUrlHandlerMapping lookupHandler
FIN: URI Template variables for request [/ui/home.html] are {}
04-oct.-2010 14:23:44 org.springframework.web.servlet.handler.AbstractUrlHandlerMapping getHandlerInternal
FIN: Mapping [/ui/home.html] to HandlerExecutionChain with handler [be.gervaisb.ogam.edu.web.ui.controllers.HomeController@12beeec] and 3 interceptors
04-oct.-2010 14:23:44 org.springframework.web.servlet.DispatcherServlet doDispatch
FIN: Last-Modified value for [/ui/home.html] is: -1
04-oct.-2010 14:23:44 org.springframework.web.bind.annotation.support.HandlerMethodInvoker invokeHandlerMethod
FIN: Invoking request handler method: public org.springframework.web.servlet.ModelAndView be.gervaisb.myapp.web.ui.controllers.HomeController.display()
Le container est Jetty et j'utilise Spring 3.0.3. Le dispatcher est configuré pour intercepter toutes les requêtes sur "*.html"
Merci pour votre aide
Partager