Skip to content

Commit

Permalink
Merge pull request #1 from evernat/master
Browse files Browse the repository at this point in the history
proposed changes for review in codecentric#450
  • Loading branch information
Daniël authored Sep 2, 2017
2 parents 6ff4a22 + 5149825 commit 46dbaa5
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 137 deletions.
22 changes: 3 additions & 19 deletions spring-boot-admin-docs/src/main/asciidoc/server-ui-modules.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ The Login module just provides you a login page and a logout button.
</dependency>
----

==== Javamelody UI Module ====
==== JavaMelody UI Module ====

This module adds a view that displays the javamelody overview for each
registered application
Expand All @@ -136,26 +136,10 @@ registered application
[source,xml,subs="verbatim,attributes"]
.pom.xml (javamelody client)
----
<!-- https://github.com/javamelody/javamelody/wiki/SpringBootStarter -->
<dependency>
<groupId>net.bull.javamelody</groupId>
<artifactId>javamelody-core</artifactId>
<artifactId>javamelody-spring-boot-starter</artifactId>
<version>${javamelody.version}</version>
</dependency>
----
+
The following Javaconfig fragment could be used to configure a javamelody client
[source,java]
@Bean
public FilterRegistrationBean javaMelody() {
final FilterRegistrationBean javaMelody = new FilterRegistrationBean();
final MonitoringFilter filter = monitoringFilter();
filter.setApplicationType("Spring Boot");
javaMelody.setFilter(filter);
javaMelody.setAsyncSupported(true);
javaMelody.setName("javamelody");
javaMelody.setDispatcherTypes(DispatcherType.REQUEST, DispatcherType.ASYNC);
javaMelody.addInitParameter(Parameter.LOG.getCode(), Boolean.toString(true));
javaMelody.addUrlPatterns("/*");
javaMelody.setFilter(filter);
return javaMelody;
}
23 changes: 18 additions & 5 deletions spring-boot-admin-server-ui-javamelody/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
<artifactId>spring-boot-admin-server-ui-javamelody</artifactId>

<properties>
<javamelody.version>1.67.0</javamelody.version>
<ehcache.version>2.6.0</ehcache.version>
<javamelody.version>1.69.0</javamelody.version>
</properties>


Expand All @@ -33,9 +32,23 @@
<version>${javamelody.version}</version>
</dependency>
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache-core</artifactId>
<version>${ehcache.version}</version>
<groupId>com.lowagie</groupId>
<artifactId>itext</artifactId>
<version>2.1.7</version>
<exclusions>
<exclusion>
<groupId>bouncycastle</groupId>
<artifactId>bcmail-jdk14</artifactId>
</exclusion>
<exclusion>
<groupId>bouncycastle</groupId>
<artifactId>bcprov-jdk14</artifactId>
</exclusion>
<exclusion>
<artifactId>bctsp-jdk14</artifactId>
<groupId>bouncycastle</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
package spring.boot.admin.javamelody.configuration;

import net.bull.javamelody.CollectorServlet;
import net.bull.javamelody.JavaMelodyService;
import net.bull.javamelody.MonitoringFilter;
import spring.boot.admin.javamelody.listener.JavaMelodyListener;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.servlet.Filter;

// Always run, if you depend on this module, you will get this autoconfiguration
@Configuration
@ConditionalOnProperty(prefix = "javamelody", name = "collectserver.enabled", matchIfMissing = true)
Expand All @@ -19,18 +16,8 @@ public class JavamelodyAutoConfiguration {
private static final String CONTEXT_ROOT = "/javamelody";

@Bean
public JavaMelodyService javaMelodyService() {
return new JavaMelodyService();
}

@Bean
public FilterRegistrationBean filterRegistrationBean() {
final Filter javaMelodyFilter = new MonitoringFilter();

FilterRegistrationBean javaMelodyFilterBean = new FilterRegistrationBean(javaMelodyFilter);
javaMelodyFilterBean.addServletNames("monitoring");
javaMelodyFilterBean.addUrlPatterns("/*");
return javaMelodyFilterBean;
public JavaMelodyListener javaMelodyListener() {
return new JavaMelodyListener();
}

@Bean
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.bull.javamelody;
package spring.boot.admin.javamelody.listener;

import net.bull.javamelody.CollectorServlet;
import de.codecentric.boot.admin.event.ClientApplicationDeregisteredEvent;
import de.codecentric.boot.admin.event.ClientApplicationRegisteredEvent;
import de.codecentric.boot.admin.model.Application;
Expand All @@ -10,23 +11,22 @@
import java.io.IOException;

/**
* Service class in the javamelody package, so we can access the javamelody Parameters class in which we can
* register and unregister applications. Using the {@link EventListener annotations} we receive notifications from service discovery.
* Listener class to register and unregister applications. Using the {@link EventListener annotations} we receive notifications from service discovery.
*/
public class JavaMelodyService {
public class JavaMelodyListener {

private static final Logger LOGGER = LoggerFactory.getLogger(JavaMelodyService.class);
private static final Logger LOGGER = LoggerFactory.getLogger(JavaMelodyListener.class);

@EventListener
public void onClientApplicationRegistered(ClientApplicationRegisteredEvent event) {
final Application application = event.getApplication();
final String applicationName = application.getName() + "-" + application.getId();

try {
Parameters.addCollectorApplication(applicationName, Parameters.parseUrl(application.getServiceUrl()));
LOGGER.info("Added application {} to java melody", applicationName);
CollectorServlet.addCollectorApplication(applicationName, application.getServiceUrl());
LOGGER.info("Added application {} to javamelody", applicationName);
} catch (IOException e) {
LOGGER.warn("Failed to register application {} to java melody" + applicationName);
LOGGER.warn("Failed to register application {} to javamelody" + applicationName);
}
}

Expand All @@ -36,10 +36,10 @@ public void onClientApplicationDeregistered(ClientApplicationDeregisteredEvent e
final String applicationName = application.getName() + "-" + application.getId();

try {
Parameters.removeCollectorApplication(applicationName);
LOGGER.info("Removed application {} from java melody", applicationName);
CollectorServlet.removeCollectorApplication(applicationName);
LOGGER.info("Removed application {} from javamelody", applicationName);
} catch (IOException e) {
LOGGER.warn("Failed to unregister application {} from java melody" + applicationName);
LOGGER.warn("Failed to unregister application {} from javamelody" + applicationName);
}
}

Expand Down
2 changes: 1 addition & 1 deletion spring-boot-admin-server-ui-javamelody/src/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ module.run(function (ApplicationViews, $sce, $q) {

ApplicationViews.register({
order: 30,
title: $sce.trustAsHtml('<i class="fa fa-music fa-fw"></i>Javamelody'),
title: $sce.trustAsHtml('<i class="fa fa-music fa-fw"></i>JavaMelody'),
state: 'applications.javamelody',
show: function () {
var deferred = $q.defer();
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@

import org.junit.Before;
import org.junit.Test;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;

public class JavamelodyAutoConfigurationTest {

Expand All @@ -25,17 +23,4 @@ public void shouldRunAsServer() {
assertThat(servletRegistrationBean.getUrlMappings().iterator().next(), is("/javamelody"));
}

@Test
public void shouldRunAsClientAsWell() {
final FilterRegistrationBean filterRegistrationBean = javaMelodyConfiguration.filterRegistrationBean();

assertTrue(filterRegistrationBean.getInitParameters().isEmpty());

assertThat(filterRegistrationBean.getUrlPatterns().size(), is(1));
assertThat(filterRegistrationBean.getUrlPatterns().iterator().next(), is("/*"));

assertThat(filterRegistrationBean.getServletNames().size(), is(1));
assertThat(filterRegistrationBean.getServletNames().iterator().next(), is("monitoring"));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package spring.boot.admin.javamelody.listener;

import de.codecentric.boot.admin.event.ClientApplicationDeregisteredEvent;
import de.codecentric.boot.admin.event.ClientApplicationRegisteredEvent;
import de.codecentric.boot.admin.model.Application;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;

import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;

public class JavaMelodyListenerTest {

private JavaMelodyListener javaMelodyListener;

@Mock
private Application mockApplication;
@Mock
private ClientApplicationRegisteredEvent registerEvent;
@Mock
private ClientApplicationDeregisteredEvent deregisteredEvent;

@Before
public void setUp() throws Exception {
initMocks(this);
javaMelodyListener = new JavaMelodyListener();
}

/**
* Create one test in which registration and deregistration is tested.
*/
@Test
public void testRegisterAndDeregister() throws Exception {
when(mockApplication.getName()).thenReturn("testName");
when(mockApplication.getId()).thenReturn("testId");
when(mockApplication.getServiceUrl()).thenReturn("http://service-test.url");

when(registerEvent.getType()).thenReturn("testRegister");
when(registerEvent.getApplication()).thenReturn(mockApplication);

when(deregisteredEvent.getType()).thenReturn("testDeregister");
when(deregisteredEvent.getApplication()).thenReturn(mockApplication);

javaMelodyListener.onClientApplicationRegistered(registerEvent);

javaMelodyListener.onClientApplicationDeregistered(deregisteredEvent);
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<h1>Java melody overview</h1>
<h1>JavaMelody overview</h1>

<div class="container-fluid">
<iframe width="95%" height="600px" src="{{javaMelodyUrl}}"></iframe>
Expand Down

0 comments on commit 46dbaa5

Please sign in to comment.