Commit 4a011458 by Johannes Edmeier

Add @AdminController for sba mvc controllers

To easily add new mvc controllers (e.g. from extensions) a new annotation `@AdminController` is added.
parent ae042803
......@@ -16,6 +16,7 @@
package de.codecentric.boot.admin.config;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
......@@ -59,6 +60,7 @@ import de.codecentric.boot.admin.registry.StatusUpdater;
import de.codecentric.boot.admin.registry.store.ApplicationStore;
import de.codecentric.boot.admin.registry.store.SimpleApplicationStore;
import de.codecentric.boot.admin.registry.web.RegistryController;
import de.codecentric.boot.admin.web.AdminController;
import de.codecentric.boot.admin.web.PrefixHandlerMapping;
import de.codecentric.boot.admin.web.servlet.resource.ConcatenatingResourceResolver;
import de.codecentric.boot.admin.web.servlet.resource.PreferMinifiedFilteringResourceResolver;
......@@ -149,8 +151,10 @@ public class AdminServerWebConfiguration extends WebMvcConfigurerAdapter
@Bean
public PrefixHandlerMapping prefixHandlerMapping() {
PrefixHandlerMapping prefixHandlerMapping = new PrefixHandlerMapping(registryController(),
journalController());
Map<String, Object> beans = applicationContext
.getBeansWithAnnotation(AdminController.class);
PrefixHandlerMapping prefixHandlerMapping = new PrefixHandlerMapping(
beans.values().toArray(new Object[beans.size()]));
prefixHandlerMapping.setPrefix(adminServerProperties().getContextPath());
return prefixHandlerMapping;
}
......
......@@ -32,13 +32,16 @@ import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
import de.codecentric.boot.admin.event.ClientApplicationEvent;
import de.codecentric.boot.admin.journal.ApplicationEventJournal;
import de.codecentric.boot.admin.web.AdminController;
/**
* REST-Controller for querying all client application events.
*
* @author Johannes Edmeier
*/
@AdminController
@ResponseBody
@RequestMapping("/api/journal")
public class JournalController {
private static final Logger LOGGER = LoggerFactory.getLogger(JournalController.class);
......@@ -50,12 +53,12 @@ public class JournalController {
this.eventJournal = eventJournal;
}
@RequestMapping(path = "/api/journal", produces = MimeTypeUtils.APPLICATION_JSON_VALUE)
@RequestMapping(produces = MimeTypeUtils.APPLICATION_JSON_VALUE)
public Collection<ClientApplicationEvent> getJournal() {
return eventJournal.getEvents();
}
@RequestMapping(path = "/api/journal", produces = "text/event-stream")
@RequestMapping(produces = "text/event-stream")
public SseEmitter getJournalEvents() {
final SseEmitter emitter = new SseEmitter();
emitter.onCompletion(new Runnable() {
......
......@@ -32,13 +32,16 @@ import de.codecentric.boot.admin.notify.filter.ApplicationIdNotificationFilter;
import de.codecentric.boot.admin.notify.filter.ApplicationNameNotificationFilter;
import de.codecentric.boot.admin.notify.filter.FilteringNotifier;
import de.codecentric.boot.admin.notify.filter.NotificationFilter;
import de.codecentric.boot.admin.web.AdminController;
/**
* REST-Controller for managing notification filters
*
* @author Johannes Edmeier
*/
@AdminController
@ResponseBody
@RequestMapping("/api/notifications/filters")
public class NotificationFilterController {
private FilteringNotifier filteringNotifier;
......@@ -46,13 +49,12 @@ public class NotificationFilterController {
this.filteringNotifier = filteringNotifier;
}
@RequestMapping(path = "/api/notifications/filters", method = {
RequestMethod.GET }, produces = MimeTypeUtils.APPLICATION_JSON_VALUE)
@RequestMapping(method = { RequestMethod.GET }, produces = MimeTypeUtils.APPLICATION_JSON_VALUE)
public Map<String, NotificationFilter> getFilters() {
return filteringNotifier.getNotificationFilters();
}
@RequestMapping(path = "/api/notifications/filters", method = {
@RequestMapping(method = {
RequestMethod.POST }, produces = MimeTypeUtils.APPLICATION_JSON_VALUE)
public ResponseEntity<?> addFilter(@RequestParam(name = "id", required = false) String id,
@RequestParam(name = "name", required = false) String name,
......@@ -66,7 +68,7 @@ public class NotificationFilterController {
}
}
@RequestMapping(path = "/api/notifications/filters/{id}", method = { RequestMethod.DELETE })
@RequestMapping(path = "/{id}", method = { RequestMethod.DELETE })
public ResponseEntity<?> deleteFilter(@PathVariable("id") String id) {
NotificationFilter deleted = filteringNotifier.removeFilter(id);
if (deleted != null) {
......
......@@ -30,11 +30,14 @@ import org.springframework.web.bind.annotation.ResponseBody;
import de.codecentric.boot.admin.model.Application;
import de.codecentric.boot.admin.registry.ApplicationRegistry;
import de.codecentric.boot.admin.web.AdminController;
/**
* REST controller for controlling registration of managed applications.
*/
@AdminController
@ResponseBody
@RequestMapping("/api/applications")
public class RegistryController {
private static final Logger LOGGER = LoggerFactory.getLogger(RegistryController.class);
......@@ -51,7 +54,7 @@ public class RegistryController {
* @param app The application infos.
* @return The registered application.
*/
@RequestMapping(value = "/api/applications", method = RequestMethod.POST)
@RequestMapping(method = RequestMethod.POST)
public ResponseEntity<Application> register(@RequestBody Application app) {
LOGGER.debug("Register application {}", app.toString());
Application registeredApp = registry.register(app);
......@@ -64,7 +67,7 @@ public class RegistryController {
* @param name the name to search for
* @return List
*/
@RequestMapping(value = "/api/applications", method = RequestMethod.GET)
@RequestMapping(method = RequestMethod.GET)
public Collection<Application> applications(
@RequestParam(value = "name", required = false) String name) {
LOGGER.debug("Deliver registered applications with name={}", name);
......@@ -81,7 +84,7 @@ public class RegistryController {
* @param id The application identifier.
* @return The registered application.
*/
@RequestMapping(value = "/api/applications/{id}", method = RequestMethod.GET)
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
public ResponseEntity<?> get(@PathVariable String id) {
LOGGER.debug("Deliver registered application with ID '{}'", id);
Application application = registry.getApplication(id);
......@@ -98,7 +101,7 @@ public class RegistryController {
* @param id The application id.
* @return the unregistered application.
*/
@RequestMapping(value = "/api/applications/{id}", method = RequestMethod.DELETE)
@RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
public ResponseEntity<?> unregister(@PathVariable String id) {
LOGGER.debug("Unregister application with ID '{}'", id);
Application application = registry.deregister(id);
......
/*
* Copyright 2016 the original author or authors.
*
* Licensed 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 de.codecentric.boot.admin.web;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Indicates that the annotated class is a mvn controller used whithin spring boot admin and
* contains handler mappings to be registered using {@link PrefixHandlerMapping}.
*
* @author Johannes Edmeier
*/
@Target({ ElementType.TYPE })
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface AdminController {
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment