Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions activemq-web-console/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@
<groupId>${project.groupId}</groupId>
<artifactId>activemq-stomp</artifactId>
</dependency>

<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>activemq-spring</artifactId>
Expand All @@ -241,10 +242,10 @@
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<artifactId>spring-context</artifactId>
</dependency>

<!-- web container -->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.activemq.web;

import java.io.IOException;
import java.util.Arrays;
import java.util.Map;
import java.util.Optional;

import static java.util.Map.entry;

import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import org.apache.activemq.web.controller.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.ServletRequestDataBinder;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

/**
* Servlet that routes requests to the appropriate controller class and injects the request parameters into it.
*/
public class ActionServlet extends HttpServlet {

private static final Logger LOG = LoggerFactory.getLogger(ActionServlet.class);

private static final Map<String, Class<? extends Controller>> routes = Map.ofEntries(
entry("/createDestination.action", CreateDestination.class),
entry("/deleteDestination.action", DeleteDestination.class),
entry("/createSubscriber.action", CreateSubscriber.class),
entry("/deleteSubscriber.action", DeleteSubscriber.class),
entry("/sendMessage.action", SendMessage.class),
entry("/purgeDestination.action", PurgeDestination.class),
entry("/deleteMessage.action", DeleteMessage.class),
entry("/copyMessage.action", CopyMessage.class),
entry("/moveMessage.action", MoveMessage.class),
entry("/deleteJob.action", DeleteJob.class),
entry("/retryMessage.action", RetryMessage.class),
entry("/pauseDestination.action", PauseDestination.class),
entry("/resumeDestination.action", ResumeDestination.class)
);

private WebApplicationContext context;

@Override
public void init() throws ServletException {
super.init();
context = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
if (context == null) {
throw new IllegalStateException("Failed to initialize Web Application Context");
}
LOG.info("Action Servlet initialized");
}

@Override
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
try {
LOG.info("Received request for action with path {}", request.getRequestURI());

final String actionPath = getAction(request);
final Optional<Controller> maybeController = getHandler(actionPath);
if (maybeController.isEmpty()) {
// Path does not route to any request
LOG.warn("No action is mapped to path: {} ({})", request.getRequestURI(), actionPath);
response.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}

final Controller controller = maybeController.get();

checkMethodIsSupported(controller, request);
injectRequestDataIntoController(controller, request);

LOG.info("Handling action: {} with {}", actionPath, controller);

controller.handleRequest(request, response);
} catch (Exception e) {
throw new ServletException(e);
}
}

private String getAction(final HttpServletRequest request) {
String path = request.getRequestURI();
if (path.contains("/")) {
path = path.substring(path.lastIndexOf("/"));
}
return path;
}

private Optional<Controller> getHandler(final String path) {
return Optional.ofNullable(routes.get(path)).map(context::getBean);
}

private void checkMethodIsSupported(final Controller controller, final HttpServletRequest request) {
if (controller instanceof DestinationFacade destination) {
if (!Arrays.asList(destination.getSupportedHttpMethods()).contains(request.getMethod())) {
throw new UnsupportedOperationException("Unsupported method " + request.getMethod());
}
}
}

private void injectRequestDataIntoController(final Controller controller, final HttpServletRequest request) {
final ServletRequestDataBinder binder = new ServletRequestDataBinder(controller);
binder.bind(request);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.activemq.web.controller;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

/**
* Controller implementations contain the logic responsible for handling an HTTP Request.
*/
public interface Controller {
void handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception;
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,35 @@
import org.apache.activemq.web.DestinationFacade;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;
import org.springframework.stereotype.Component;
import org.springframework.web.context.annotation.RequestScope;

/**
* Copies a message from one to another queue
*/
@Component
@RequestScope
public class CopyMessage extends DestinationFacade implements Controller {
private String messageId;
private String destination;
private static final Logger log = LoggerFactory.getLogger(CopyMessage.class);

public CopyMessage(BrokerFacade brokerFacade) {
public CopyMessage(final BrokerFacade brokerFacade) {
super(brokerFacade);
}

public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
@Override
public void handleRequest(final HttpServletRequest request, final HttpServletResponse response) throws Exception {
if (messageId != null) {
QueueViewMBean queueView = getQueueView();
if (queueView != null) {
log.info(getJMSDestination() + "(" + messageId + ")" + " copy to " + destination);
log.info("{} ({}) copy to {}", getJMSDestination(), messageId, destination);
queueView.copyMessageTo(messageId, destination);
} else {
log.warn("No queue named: " + getPhysicalDestinationName());
log.warn("No queue named: {}", getPhysicalDestinationName());
}
}
return redirectToDestinationView();
response.sendRedirect("browse.jsp?JMSDestination=" + getJMSDestination());
}

public String getMessageId() {
Expand All @@ -59,8 +62,6 @@ public String getMessageId() {
public void setMessageId(String messageId) {
this.messageId = messageId;
}



public String getDestination() {
return destination;
Expand All @@ -69,5 +70,4 @@ public String getDestination() {
public void setDestination(String destination) {
this.destination = destination;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,23 @@

import org.apache.activemq.web.BrokerFacade;
import org.apache.activemq.web.DestinationFacade;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;
import org.springframework.stereotype.Component;
import org.springframework.web.context.annotation.RequestScope;

/**
*
*
*/
@Component
@RequestScope
public class CreateDestination extends DestinationFacade implements Controller {

public CreateDestination(BrokerFacade brokerFacade) {
super(brokerFacade);
}

public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
public void handleRequest(final HttpServletRequest request, final HttpServletResponse response) throws Exception {
addDestination();
return redirectToBrowseView();
response.sendRedirect(isQueue() ? "queues.jsp" : "topics.jsp");
}

public String[] getSupportedHttpMethods() {
return new String[]{"POST"};
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,15 @@

import org.apache.activemq.web.BrokerFacade;
import org.apache.activemq.web.DurableSubscriberFacade;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;
import org.springframework.stereotype.Component;
import org.springframework.web.context.annotation.RequestScope;

/**
*
*
*/
@Component
@RequestScope
public class CreateSubscriber extends DurableSubscriberFacade implements Controller {
private String selector;

public CreateSubscriber(BrokerFacade brokerFacade) {
public CreateSubscriber(final BrokerFacade brokerFacade) {
super(brokerFacade);
}

Expand All @@ -46,16 +44,15 @@ public void setSelector(String selector) {
this.selector = selector;
}

public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
if (selector != null && selector.length() == 0) {
public void handleRequest(final HttpServletRequest request, final HttpServletResponse response) throws Exception {
if (selector != null && selector.isEmpty()) {
selector = null;
}
getBrokerAdmin().createDurableSubscriber(getClientId(), getSubscriberName(), getValidDestination(), selector);
return new ModelAndView("redirect:subscribers.jsp");
response.sendRedirect("subscribers.jsp");
}

public String[] getSupportedHttpMethods() {
return new String[]{"POST"};
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,19 @@

import org.apache.activemq.web.BrokerFacade;
import org.apache.activemq.web.DestinationFacade;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;
import org.springframework.stereotype.Component;
import org.springframework.web.context.annotation.RequestScope;

/**
*
*
*/
@Component
@RequestScope
public class DeleteDestination extends DestinationFacade implements Controller {

public DeleteDestination(BrokerFacade brokerFacade) {
public DeleteDestination(final BrokerFacade brokerFacade) {
super(brokerFacade);
}

public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
public void handleRequest(final HttpServletRequest request, final HttpServletResponse response) throws Exception {
removeDestination();
return redirectToBrowseView();
response.sendRedirect(isQueue() ? "queues.jsp" : "topics.jsp");
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -23,39 +23,37 @@
import org.apache.activemq.web.DestinationFacade;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;
import org.springframework.stereotype.Component;
import org.springframework.web.context.annotation.RequestScope;

/**
*
*/
@Component
@RequestScope
public class DeleteJob extends DestinationFacade implements Controller {
private String jobId;
private static final Logger LOG = LoggerFactory.getLogger(DeleteJob.class);

public DeleteJob(BrokerFacade brokerFacade) {
public DeleteJob(final BrokerFacade brokerFacade) {
super(brokerFacade);
}

public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
public void handleRequest(final HttpServletRequest request, final HttpServletResponse response) throws Exception {
if (jobId != null) {
JobSchedulerViewMBean jobScheduler = getBrokerFacade().getJobScheduler();
if (jobScheduler != null) {
jobScheduler.removeJob(jobId);
LOG.info("Removed scheduled Job " + jobId);
LOG.info("Removed scheduled Job {}", jobId);
} else {
LOG.warn("Scheduler not configured");
}
}
return new ModelAndView("redirect:scheduled.jsp");
response.sendRedirect("scheduled.jsp");
}

public String getJobId() {
return jobId;
}

public void setJobId(String id) {
this.jobId=id;
public void setJobId(final String id) {
this.jobId = id;
}

}
Loading