Skip to content

Instantly share code, notes, and snippets.

@LeBezout
Last active June 25, 2019 09:21
Show Gist options
  • Select an option

  • Save LeBezout/b5da8518fef42296a68bb18fb98a79af to your computer and use it in GitHub Desktop.

Select an option

Save LeBezout/b5da8518fef42296a68bb18fb98a79af to your computer and use it in GitHub Desktop.

Revisions

  1. LeBezout renamed this gist May 30, 2018. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. LeBezout revised this gist May 30, 2018. 2 changed files with 62 additions and 0 deletions.
    8 changes: 8 additions & 0 deletions aaplication.properties
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    spring.application.name=demoendpoint
    #spring.aop.proxy-target-class=true
    management.endpoints.enabled-by-default=true
    management.endpoints.web.exposure.include=*
    logging.level.root=warn
    logging.level.org.springframework=info
    logging.level.com.example=info
    server.port=8081
    54 changes: 54 additions & 0 deletions pom.xml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,54 @@
    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example</groupId>
    <artifactId>demo-endpoint</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>demo-endpoint</name>
    <description>Demo project for Spring Boot</description>

    <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.2.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
    </properties>

    <dependencies>
    <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
    <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-test</artifactId>
    <scope>test</scope>
    </dependency>
    </dependencies>

    <build>
    <plugins>
    <plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    </plugin>
    </plugins>
    </build>


    </project>
  3. LeBezout created this gist May 30, 2018.
    54 changes: 54 additions & 0 deletions MyCustomEndpoint.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,54 @@
    package com.example.demoendpoint;

    import java.util.Arrays;
    import java.util.Collections;
    import java.util.HashMap;
    import java.util.List;
    import java.util.Map;

    import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
    import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
    import org.springframework.boot.actuate.endpoint.annotation.Selector;
    import org.springframework.stereotype.Component;
    import org.springframework.util.Assert;

    @Component
    @Endpoint(id="my-params")
    public class MyCustomEndpoint {
    @ReadOperation
    public Map<String, List<Parameter>> showParameters() {
    Map<String, List<Parameter>> params = new HashMap<>();
    params.put("cat1", Arrays.asList(new Parameter("url", "toto"), new Parameter("user", "titi")));
    params.put("cat2", Arrays.asList(new Parameter("key.1", "secret"), new Parameter("key.2", "sE3reT")));
    params.put("cat3", Arrays.asList(new Parameter("other1", "foo"), new Parameter("other2", "bar")));
    return params;
    }
    @ReadOperation
    public List<Parameter> showParametersByCategory(@Selector String category) {
    Assert.notNull(category, "category must not be null");
    switch (category) {
    case "cat1" : return Arrays.asList(new Parameter("url", "toto"), new Parameter("user", "titi"));
    case "cat2" : return Arrays.asList(new Parameter("key.1", "secret"), new Parameter("key.2", "sE3reT"));
    case "cat3" : return Arrays.asList(new Parameter("other1", "foo"), new Parameter("other2", "bar"));
    default : return Collections.emptyList();
    }
    }

    private static class Parameter {
    private final String name;
    private final String value;

    Parameter(String name, String value) {
    this.name = name;
    this.value = value;
    }

    public String getName() {
    return name;
    }

    public String getValue() {
    return value;
    }
    }
    }