Skip to content

Commit 2c889c6

Browse files
committed
fix(webconsole): the webconsole now redirect to the slave.jsp when required (slave broker with startAsync="true")
1 parent 95eeb90 commit 2c889c6

3 files changed

Lines changed: 19 additions & 15 deletions

File tree

activemq-web-console/src/main/java/org/apache/activemq/web/filter/ApplicationContextFilter.java

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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);

assembly/src/release/conf/activemq.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
<!--
3232
The <broker> element is used to configure the ActiveMQ broker.
3333
-->
34-
<broker xmlns="http://activemq.apache.org/schema/core" brokerName="localhost" dataDirectory="${activemq.data}">
34+
<broker xmlns="http://activemq.apache.org/schema/core" brokerName="localhost" dataDirectory="${activemq.data}" id="broker">
3535

3636
<destinationPolicy>
3737
<policyMap>

assembly/src/release/conf/jetty.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@
209209
</bean>
210210

211211
<bean id="invokeStart" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean"
212-
depends-on="configureJetty, invokeConnectors">
212+
depends-on="broker, configureJetty, invokeConnectors">
213213
<property name="targetObject" ref="Server" />
214214
<property name="targetMethod" value="start" />
215215
</bean>

0 commit comments

Comments
 (0)