Skip to content

Commit 71ae4f3

Browse files
committed
initial code push
Signed-off-by: Toby Corbin <[email protected]>
1 parent c49b7dc commit 71ae4f3

File tree

12 files changed

+305
-1
lines changed

12 files changed

+305
-1
lines changed

Dockerfile

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM ibmjava:8-sfj
2+
LABEL maintainer="Eclipse Codewind"
3+
4+
COPY target/[PROJ_NAME_PLACEHOLDER]-1.0-SNAPSHOT.jar /app.jar
5+
6+
ENV JAVA_OPTS=""
7+
ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /app.jar" ]

Dockerfile-tools

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM ibmjava:8-sdk
2+
3+
LABEL maintainer="Eclipse Codewind"
4+
5+
RUN apt-get update && apt-get install -y maven
6+
7+
ARG bx_dev_user=root
8+
ARG bx_dev_userid=1000
9+
RUN BX_DEV_USER=$bx_dev_user
10+
RUN BX_DEV_USERID=$bx_dev_userid
11+
RUN if [ $bx_dev_user != "root" ]; then useradd -ms /bin/bash -u $bx_dev_userid $bx_dev_user; fi

README.md

+53-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,53 @@
1-
# springJavaTemplate
1+
## Microservice
2+
Eclipse Codewind Microservice Starter for Spring
3+
4+
### Table of Contents
5+
- [Microservice](#microservice)
6+
- [Table of Contents](#table-of-contents)
7+
- [Summary](#summary)
8+
- [Requirements](#requirements)
9+
- [Configuration](#configuration)
10+
- [Project contents](#project-contents)
11+
- [Run](#run)
12+
- [Endpoints](#endpoints)
13+
- [Notices](#notices)
14+
15+
### Summary
16+
17+
The Eclipse Codewind Microservice Starter in Java provides a starting point for creating Java microservice applications running on [Spring](https://spring.io/).
18+
19+
### Requirements
20+
* [Maven](https://maven.apache.org/install.html)
21+
* Java 8: Any compliant JVM should work.
22+
* [Java 8 JDK from Oracle](http://www.oracle.com/technetwork/java/javase/downloads/index.html)
23+
* [Java 8 JDK from IBM (AIX, Linux, z/OS, IBM i)](http://www.ibm.com/developerworks/java/jdk/)
24+
25+
### Configuration
26+
Capabilities are provided through dependencies in the pom.xml file.
27+
28+
### Project contents
29+
The ports are set to the defaults of 8080 for http and 8443 for https and are exposed to the CLI in the cli-config.yml file.
30+
31+
### Run
32+
33+
To build and run the application:
34+
1. `mvn install`
35+
2. `java -jar ./target/[microclimate-project-name]-1.0-SNAPSHOT.jar`
36+
37+
To run the application in Docker use the Docker file called `Dockerfile`. If you do not want to install Maven locally you can use `Dockerfile-tools` to build a container with Maven installed.
38+
39+
### Endpoints
40+
41+
The application exposes the following endpoints:
42+
43+
The ports are set in the pom.xml file and exposed to the CLI in the cli-config.yml file.
44+
45+
46+
### Notices
47+
48+
This project was generated using:
49+
* generator-ibm-java v5.13.7
50+
* generator-ibm-service-enablement v3.1.2
51+
* generator-ibm-cloud-enablement v1.5.4
52+
* generator-ibm-java-spring v
53+

pom.xml

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>projects</groupId>
7+
<artifactId>[PROJ_NAME_PLACEHOLDER]</artifactId>
8+
<version>1.0-SNAPSHOT</version>
9+
10+
<properties>
11+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
12+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
13+
<maven.compiler.source>1.8</maven.compiler.source>
14+
<maven.compiler.target>1.8</maven.compiler.target>
15+
<java.version>1.8</java.version>
16+
<spring-cloud.version>Dalston.SR4</spring-cloud.version>
17+
18+
<app.name>[PROJ_NAME_PLACEHOLDER]</app.name>
19+
</properties>
20+
21+
<parent>
22+
<groupId>org.springframework.boot</groupId>
23+
<artifactId>spring-boot-starter-parent</artifactId>
24+
<version>1.5.15.RELEASE</version>
25+
</parent>
26+
27+
<dependencies>
28+
<dependency>
29+
<groupId>org.springframework.boot</groupId>
30+
<artifactId>spring-boot-starter-web</artifactId>
31+
</dependency>
32+
<dependency>
33+
<groupId>org.springframework.boot</groupId>
34+
<artifactId>spring-boot-actuator</artifactId>
35+
</dependency>
36+
<dependency>
37+
<groupId>org.springframework.cloud</groupId>
38+
<artifactId>spring-cloud-starter-hystrix</artifactId>
39+
</dependency>
40+
<dependency>
41+
<groupId>org.springframework.boot</groupId>
42+
<artifactId>spring-boot-starter-test</artifactId>
43+
<scope>test</scope>
44+
</dependency>
45+
<!-- Configure javametrics monitoring -->
46+
<dependency>
47+
<groupId>com.ibm.runtimetools</groupId>
48+
<artifactId>javametrics-spring</artifactId>
49+
<version>[1.1,2.0)</version>
50+
</dependency>
51+
<dependency>
52+
<groupId>com.ibm.runtimetools</groupId>
53+
<artifactId>javametrics-agent</artifactId>
54+
<version>[1.1,2.0)</version>
55+
</dependency>
56+
<dependency>
57+
<groupId>org.glassfish</groupId>
58+
<artifactId>javax.json</artifactId>
59+
<version>1.0.4</version>
60+
</dependency>
61+
</dependencies>
62+
63+
<dependencyManagement>
64+
<dependencies>
65+
<dependency>
66+
<groupId>org.springframework.cloud</groupId>
67+
<artifactId>spring-cloud-dependencies</artifactId>
68+
<version>${spring-cloud.version}</version>
69+
<type>pom</type>
70+
<scope>import</scope>
71+
</dependency>
72+
</dependencies>
73+
</dependencyManagement>
74+
75+
<build>
76+
<plugins>
77+
<plugin>
78+
<groupId>org.springframework.boot</groupId>
79+
<artifactId>spring-boot-maven-plugin</artifactId>
80+
</plugin>
81+
</plugins>
82+
</build>
83+
84+
</project>

src/main/java/application/Info.java

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package application;
2+
3+
import org.springframework.context.event.EventListener;
4+
import org.springframework.stereotype.Component;
5+
import org.springframework.boot.context.event.ApplicationReadyEvent;
6+
7+
@Component
8+
public class Info {
9+
10+
@EventListener(ApplicationReadyEvent.class)
11+
public void contextRefreshedEvent() {
12+
System.out.println("The following endpoints are available by default :-");
13+
System.out.println(" Health : http://localhost:8080/health");
14+
System.out.println(" Application : http://localhost:8080/v1/");
15+
}
16+
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package application;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
import org.springframework.context.annotation.ComponentScan;
6+
7+
@SpringBootApplication
8+
@ComponentScan(basePackages = {"application", "com.ibm.javametrics.spring"})
9+
public class SBApplication {
10+
11+
public static void main(String[] args) {
12+
SpringApplication.run(SBApplication.class, args);
13+
}
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package application.rest;
2+
3+
import org.springframework.boot.actuate.health.Health;
4+
import org.springframework.boot.actuate.health.HealthIndicator;
5+
import org.springframework.stereotype.Component;
6+
7+
@Component
8+
public class HealthEndpoint implements HealthIndicator {
9+
10+
@Override
11+
public Health health() {
12+
/*
13+
if (!healthy) {
14+
return Health.down().withDetail("Not healthy", 500).build();
15+
}
16+
*/
17+
return Health.up().build();
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package application.rest.v1;
2+
3+
import org.springframework.web.bind.annotation.RequestMapping;
4+
import org.springframework.web.bind.annotation.RestController;
5+
import org.springframework.http.HttpStatus;
6+
import org.springframework.http.ResponseEntity;
7+
import org.springframework.web.bind.annotation.ResponseBody;
8+
import java.util.ArrayList;
9+
import java.util.List;
10+
11+
@RestController
12+
public class Example {
13+
14+
15+
@RequestMapping("v1")
16+
public @ResponseBody ResponseEntity<String> example() {
17+
List<String> list = new ArrayList<>();
18+
//return a simple list of strings
19+
list.add("Congratulations, your application is up and running");
20+
return new ResponseEntity<String>(list.toString(), HttpStatus.OK);
21+
}
22+
23+
}

src/main/resources/application-local.properties

Whitespace-only changes.

src/main/resources/application.properties

Whitespace-only changes.

src/main/resources/public/index.html

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Eclipse Codewind Web Starter</title>
5+
<div align="center">
6+
<svg width="269px" height="71px" viewBox="0 0 269 71" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
7+
<defs>
8+
<polygon id="path-1" points="0.1383 0.893 71.245 0.893 71.245 72 0.1383 72"></polygon>
9+
</defs>
10+
<g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
11+
<g id="Desktop-HD" transform="translate(-80.000000, -19.000000)">
12+
<g id="header">
13+
<g id="codewind-logo" transform="translate(80.000000, 18.000000)">
14+
<path d="M19.8676,56.286 C18.4476,58.105 15.6076,59.79 11.3066,59.79 C4.8766,59.79 0.0006,54.82 0.0006,48.301 C0.0006,41.694 4.9236,36.771 11.6646,36.771 C15.6136,36.771 18.4476,38.812 19.1576,39.522 L17.4736,42.362 C16.8986,41.787 14.7686,40.057 11.7066,40.057 C7.8916,40.057 4.0786,42.896 4.0786,48.348 C4.0786,53.317 7.5816,56.51 11.7946,56.51 C15.3446,56.51 17.3806,55.09 18.4006,53.939 L19.8676,56.286 Z" id="Fill-1" fill="#0083C9"></path>
15+
<path d="M41.5131,48.3065 C41.5131,43.5185 38.0511,40.1035 33.9731,40.1035 C29.4951,40.1035 26.3451,43.5645 26.3451,48.4415 C26.3451,53.1415 29.9361,56.5555 33.8851,56.5555 C38.4091,56.5555 41.5131,53.2295 41.5131,48.3065 M33.9731,59.7895 C27.4081,59.7895 22.2671,54.7325 22.2671,48.3005 C22.2671,41.8235 27.4121,36.7715 34.0201,36.7715 C40.5851,36.7715 45.6381,41.9575 45.6381,48.3005 C45.6381,54.6435 40.5381,59.7895 33.9731,59.7895" id="Fill-3" fill="#0083C9"></path>
16+
<path d="M66.5726,42.7148 C65.4646,41.1598 63.0226,40.1448 60.6296,40.1448 C56.2396,40.1448 53.3536,43.3838 53.3536,48.5698 C53.3536,53.6278 57.0326,56.5098 61.2046,56.5098 C62.7596,56.5098 64.8426,56.1568 66.5726,55.0018 L66.5726,42.7148 Z M66.5726,22.8008 L70.4746,22.8008 L70.4746,56.9498 C67.6346,58.9028 64.3546,59.7898 61.2046,59.7898 C55.0846,59.7898 49.2286,56.0638 49.2286,48.5698 C49.2286,41.5178 53.8866,36.7718 60.4946,36.7718 C62.6656,36.7718 64.9716,37.4348 66.5726,38.7668 L66.5726,22.8008 Z" id="Fill-5" fill="#0083C9"></path>
17+
<path d="M92.6957,45.8192 C92.1207,42.4922 90.3007,39.9632 86.4877,39.9632 C83.2077,39.9632 80.3207,41.7352 79.4347,45.8192 L92.6957,45.8192 Z M95.9747,56.4632 C94.7317,58.1052 91.2757,59.7902 86.7937,59.7902 C80.1387,59.7902 75.3507,55.2652 75.3507,48.3892 C75.3507,41.6062 79.9167,36.7712 86.5697,36.7712 C93.3997,36.7712 96.6387,42.1392 96.6387,47.9022 L96.6387,49.0572 L79.2997,49.0572 C79.2997,49.5912 79.3877,50.1202 79.4347,50.3892 C80.2327,54.7782 83.7357,56.5552 87.6377,56.5552 C91.2757,56.5552 93.6227,54.9132 94.6017,53.8502 L95.9747,56.4632 Z" id="Fill-7" fill="#0083C9"></path>
18+
<polygon id="Fill-9" fill="#0083C9" points="120.5902 60.1474 113.9832 42.2274 107.4172 60.1474 107.3702 60.1474 98.8982 38.2844 101.0692 38.2844 107.4532 55.0064 113.9312 37.1754 113.9782 37.1754 120.6732 55.0064 127.0572 38.2844 129.0992 38.2844 120.6262 60.1474"></polygon>
19+
<path d="M133.3636,59.1728 L133.3636,38.2788 L135.3166,38.2788 L135.3166,59.1678 L133.3636,59.1678 L133.3636,59.1728 Z M134.3376,33.8488 C133.3636,33.8488 132.5656,33.0508 132.5656,32.1178 C132.5656,31.0558 133.3636,30.2988 134.3376,30.2988 C135.3586,30.2988 136.109625,31.0558 136.109625,32.1178 C136.1146,33.0458 135.3586,33.8488 134.3376,33.8488 L134.3376,33.8488 Z" id="Fill-11" fill="#0083C9"></path>
20+
<path d="M157.5785,59.1728 L157.5785,46.3998 C157.5785,41.5648 155.7185,39.7038 151.3245,39.7038 C147.9555,39.7038 145.4685,41.5648 144.4475,42.6318 L144.4475,59.1728 L142.4945,59.1728 L142.4945,38.2788 L144.4475,38.2788 L144.4475,40.5378 C145.6445,39.4768 147.9975,37.7448 151.6355,37.7448 C156.6455,37.7448 159.5275,40.1868 159.5275,45.5958 L159.5275,59.1678 L157.5785,59.1728 Z" id="Fill-13" fill="#0083C9"></path>
21+
<path d="M182.432,43.0722 C181.282,41.0312 178.265,39.5692 175.115,39.5692 C169.969,39.5692 166.512,43.0312 166.512,49.0622 C166.512,55.0072 170.861,57.8872 175.825,57.8872 C177.778,57.8872 180.26,57.3542 182.432,55.8042 L182.432,43.0722 Z M182.432,22.8012 L184.385,22.8012 L184.385,56.8202 C181.945,58.7742 178.887,59.7012 175.825,59.7012 C170.016,59.7012 164.471,56.3752 164.471,49.0572 C164.471,42.1392 168.86,37.7512 175.115,37.7512 C177.867,37.7512 180.701,38.7242 182.432,40.4142 L182.432,22.8012 Z" id="Fill-15" fill="#0083C9"></path>
22+
<polygon id="Fill-17" fill="#0083C9" points="239.475 65.3241 248.6 56.1981 238.63 41.1861"></polygon>
23+
<g id="Group-21" transform="translate(197.000000, 0.107100)">
24+
<mask id="mask-2" fill="white">
25+
<use xlink:href="#path-1"></use>
26+
</mask>
27+
<g id="Clip-20"></g>
28+
<path d="M32.5873,41.2395 L9.4603,38.6335 L10.9113,36.3115 L36.4063,35.5605 L32.5873,41.2395 Z M40.4433,36.1095 L41.4543,36.1095 L41.5633,39.1725 L47.1753,39.3695 L53.9993,53.6915 L71.2453,36.4465 L51.5433,16.7445 L42.2883,34.3685 L39.2153,28.2485 L49.2113,14.4125 L35.6913,0.8925 L0.1383,36.4465 L35.6913,72.0005 L38.8013,68.8905 L40.4433,36.1095 Z" id="Fill-19" fill="#0083C9" mask="url(#mask-2)"></path>
29+
</g>
30+
</g>
31+
</g>
32+
</g>
33+
</g>
34+
</svg>
35+
<meta name="viewport" content="width=device-width, initial-scale=1">
36+
</head>
37+
<body>
38+
<header id="flex-header">
39+
<div class="cloud-header"></div>
40+
<h1>Congratulations!</h1>
41+
<h2>You are currently running a Spring Java app built by Eclipse Codewind.</h2>
42+
</header>
43+
</div>
44+
</body>
45+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package application;
2+
3+
import static org.junit.Assert.assertTrue;
4+
5+
import org.junit.Test;
6+
import org.junit.runner.RunWith;
7+
8+
import org.springframework.beans.factory.annotation.Autowired;
9+
import org.springframework.boot.context.embedded.LocalServerPort;
10+
import org.springframework.boot.test.context.SpringBootTest;
11+
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
12+
import org.springframework.boot.test.web.client.TestRestTemplate;
13+
import org.springframework.test.context.junit4.SpringRunner;
14+
15+
@RunWith(SpringRunner.class)
16+
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
17+
public class HealthEndpointTest {
18+
19+
@Autowired
20+
private TestRestTemplate server;
21+
22+
@LocalServerPort
23+
private int port;
24+
25+
@Test
26+
public void testEndpoint() throws Exception {
27+
String endpoint = "http://localhost:" + port + "/health";
28+
String response = server.getForObject(endpoint, String.class);
29+
assertTrue("Invalid response from server : " + response, response.startsWith("{\"status\":\"UP\""));
30+
}
31+
32+
}

0 commit comments

Comments
 (0)