@@ -66,6 +66,7 @@ public class ApplicationContextFilter implements Filter {
6666 private String applicationContextName = "applicationContext" ;
6767 private String requestContextName = "requestContext" ;
6868 private String requestName = "request" ;
69+ private String slavePage = "slave.jsp" ;
6970
7071 public void init (FilterConfig config ) throws ServletException {
7172 this .servletContext = config .getServletContext ();
@@ -84,19 +85,22 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha
8485 Map requestContextWrapper = createRequestContextWrapper (request );
8586 String path = ((HttpServletRequest )request ).getRequestURI ();
8687 // handle slave brokers
87- // try {
88- // if ( !(path.endsWith("css") || path.endsWith("png") || path.endsWith("ico") || path.endsWith(slavePage))
89- // && ((BrokerFacade)requestContextWrapper.get("brokerQuery")).isSlave()) {
90- // ((HttpServletResponse)response).sendRedirect(slavePage);
91- // return;
92- // }
93- // } catch (Exception e) {
94- // LOG.warn(path + ", failed to access BrokerFacade: reason: " + e.getLocalizedMessage());
95- // if (LOG.isDebugEnabled()) {
96- // LOG.debug(request.toString(), e);
97- // }
98- // throw new IOException(e);
99- // }
88+ try {
89+ boolean isSlave = ((BrokerFacade ) requestContextWrapper .get ("brokerQuery" )).getBrokerAdmin ().isSlave ();
90+ if (isSlave && !(path .endsWith ("css" ) || path .endsWith ("png" ) || path .endsWith ("ico" ) || path .endsWith (slavePage ))) {
91+ ((HttpServletResponse ) response ).sendRedirect (slavePage );
92+ return ;
93+ } else if (!isSlave && path .endsWith (slavePage )) {
94+ ((HttpServletResponse ) response ).sendRedirect (((HttpServletRequest ) request ).getContextPath () + "/index.jsp" );
95+ return ;
96+ }
97+ } catch (Exception e ) {
98+ LOG .warn (path + ", failed to access BrokerFacade: reason: " + e .getLocalizedMessage ());
99+ if (LOG .isDebugEnabled ()) {
100+ LOG .debug (request .toString (), e );
101+ }
102+ throw new IOException (e );
103+ }
100104 request .setAttribute (requestContextName , requestContextWrapper );
101105 request .setAttribute (requestName , request );
102106 chain .doFilter (request , response );
0 commit comments