minor cleanup work
This commit is contained in:
parent
df2a789fa2
commit
be4c05ad2d
|
@ -15,7 +15,6 @@
|
||||||
<version>1.2.3.RELEASE</version>
|
<version>1.2.3.RELEASE</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
|
|
@ -8,28 +8,28 @@ import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class CustomEndpoint implements Endpoint<List<String>> {
|
public class CustomEndpoint implements Endpoint<List<String>> {
|
||||||
|
|
||||||
public CustomEndpoint() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getId() {
|
|
||||||
return "customEndpoint";
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isEnabled() {
|
public CustomEndpoint() {
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isSensitive() {
|
}
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<String> invoke() {
|
public String getId() {
|
||||||
//Your logic to display the output
|
return "customEndpoint";
|
||||||
List<String> messages = new ArrayList<String>();
|
}
|
||||||
messages.add("This is message 1");
|
|
||||||
messages.add("This is message 2");
|
public boolean isEnabled() {
|
||||||
return messages;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isSensitive() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> invoke() {
|
||||||
|
// Your logic to display the output
|
||||||
|
List<String> messages = new ArrayList<String>();
|
||||||
|
messages.add("This is message 1");
|
||||||
|
messages.add("This is message 2");
|
||||||
|
return messages;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,15 +9,15 @@ import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class ListEndpoints extends AbstractEndpoint<List<Endpoint>> {
|
public class ListEndpoints extends AbstractEndpoint<List<Endpoint>> {
|
||||||
private List<Endpoint> endpoints;
|
private List<Endpoint> endpoints;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public ListEndpoints(List<Endpoint> endpoints) {
|
public ListEndpoints(List<Endpoint> endpoints) {
|
||||||
super("listEndpoints");
|
super("listEndpoints");
|
||||||
this.endpoints = endpoints;
|
this.endpoints = endpoints;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Endpoint> invoke() {
|
public List<Endpoint> invoke() {
|
||||||
return this.endpoints;
|
return this.endpoints;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -7,16 +7,16 @@ import org.springframework.stereotype.Component;
|
||||||
@Component
|
@Component
|
||||||
public class MyHealthCheck implements HealthIndicator {
|
public class MyHealthCheck implements HealthIndicator {
|
||||||
|
|
||||||
public Health health() {
|
public Health health() {
|
||||||
int errorCode = check(); // perform some specific health check
|
int errorCode = check(); // perform some specific health check
|
||||||
if (errorCode != 0) {
|
if (errorCode != 0) {
|
||||||
return Health.down().withDetail("Error Code", errorCode).withDetail("Description", "You custom MyHealthCheck endpoint is down").build();
|
return Health.down().withDetail("Error Code", errorCode).withDetail("Description", "You custom MyHealthCheck endpoint is down").build();
|
||||||
}
|
}
|
||||||
return Health.up().build();
|
return Health.up().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int check() {
|
public int check() {
|
||||||
// Your logic to check health
|
// Your logic to check health
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package org.baeldung.main;
|
package org.baeldung.main;
|
||||||
|
|
||||||
|
|
||||||
import org.baeldung.service.LoginService;
|
import org.baeldung.service.LoginService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
|
@ -11,20 +10,20 @@ import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@EnableAutoConfiguration
|
@EnableAutoConfiguration
|
||||||
@ComponentScan({"org.baeldung.endpoints", "org.baeldung.service", "org.baeldung.monitor.jmx"})
|
@ComponentScan({ "org.baeldung.endpoints", "org.baeldung.service", "org.baeldung.monitor.jmx" })
|
||||||
public class SpringBootActuatorApplication {
|
public class SpringBootActuatorApplication {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private LoginService service;
|
private LoginService service;
|
||||||
|
|
||||||
@RequestMapping("/")
|
@RequestMapping("/")
|
||||||
String home() {
|
String home() {
|
||||||
service.login("admin", "admin".toCharArray());
|
service.login("admin", "admin".toCharArray());
|
||||||
return "TADA!!! You are in Spring Boot Actuator test application.";
|
return "TADA!!! You are in Spring Boot Actuator test application.";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SpringApplication.run(SpringBootActuatorApplication.class, args);
|
SpringApplication.run(SpringBootActuatorApplication.class, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,9 +9,9 @@ import com.codahale.metrics.MetricRegistry;
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
public class MonitoringConfig {
|
public class MonitoringConfig {
|
||||||
@Autowired
|
@Autowired
|
||||||
private MetricRegistry registry;
|
private MetricRegistry registry;
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public JmxReporter jmxReporter() {
|
public JmxReporter jmxReporter() {
|
||||||
JmxReporter reporter = JmxReporter.forRegistry(registry).build();
|
JmxReporter reporter = JmxReporter.forRegistry(registry).build();
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
package org.baeldung.service;
|
package org.baeldung.service;
|
||||||
|
|
||||||
public interface LoginService {
|
public interface LoginService {
|
||||||
public boolean login(String userName, char[] password);
|
public boolean login(String userName, char[] password);
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,26 +7,23 @@ import org.springframework.stereotype.Service;
|
||||||
@Service
|
@Service
|
||||||
public class LoginServiceImpl implements LoginService {
|
public class LoginServiceImpl implements LoginService {
|
||||||
|
|
||||||
private CounterService counterService;
|
private CounterService counterService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public LoginServiceImpl(CounterService counterService) {
|
public LoginServiceImpl(CounterService counterService) {
|
||||||
this.counterService = counterService;
|
this.counterService = counterService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean login(String userName, char[] password) {
|
public boolean login(String userName, char[] password) {
|
||||||
boolean success;
|
boolean success;
|
||||||
if (userName.equals("admin") && "secret".toCharArray().equals(password))
|
if (userName.equals("admin") && "secret".toCharArray().equals(password)) {
|
||||||
{
|
counterService.increment("counter.login.success");
|
||||||
counterService.increment("counter.login.success");
|
success = true;
|
||||||
success = true;
|
} else {
|
||||||
}
|
counterService.increment("counter.login.failure");
|
||||||
else
|
success = false;
|
||||||
{
|
}
|
||||||
counterService.increment("counter.login.failure");
|
return success;
|
||||||
success = false;
|
}
|
||||||
}
|
|
||||||
return success;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue