Skip to content

Commit 2b91f01

Browse files
authored
fix(webconsole): the webconsole now redirect to the slave.jsp when required (#1931)
* fix(webconsole): the webconsole now redirect to the slave.jsp when required (slave broker with startAsync="true") * fix(assembly): add id="broker" to sample configs so jetty.xml depends-on resolves The BrokerXmlConfigStartTest loads all activemq-*.xml sample configs which import jetty.xml. Since jetty.xml now has depends-on="broker" on the invokeStart bean, the sample configs need a matching bean id.
1 parent 17b1885 commit 2b91f01

File tree

6 files changed

+22
-18
lines changed

6 files changed

+22
-18
lines changed

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>

assembly/src/release/examples/conf/activemq-demo.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
- Change the brokerName attribute to something unique
4848
-->
4949

50-
<broker xmlns="http://activemq.apache.org/schema/core" brokerName="amq-broker" useJmx="true">
50+
<broker xmlns="http://activemq.apache.org/schema/core" brokerName="amq-broker" useJmx="true" id="broker">
5151

5252
<!--
5353
Examples of destination-specific policies using destination

assembly/src/release/examples/conf/activemq-security.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
</bean>
6464
-->
6565

66-
<broker useJmx="true" persistent="false" xmlns="http://activemq.apache.org/schema/core" >
66+
<broker useJmx="true" persistent="false" xmlns="http://activemq.apache.org/schema/core" id="broker">
6767

6868
<managementContext>
6969
<managementContext createConnector="true">

assembly/src/release/examples/conf/activemq-stomp.xml

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

4949
<!--
5050
For better performances use VM cursor and small memory limit.

0 commit comments

Comments
 (0)