Skip to content

Commit

Permalink
Initial import
Browse files Browse the repository at this point in the history
Signed-off-by: Kevin Grigorenko <[email protected]>
  • Loading branch information
kgibm committed Feb 12, 2024
1 parent ab6db1b commit 9ca8096
Show file tree
Hide file tree
Showing 12 changed files with 368 additions and 3 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions
name: OnPush
on: push
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Compile and Package the Maven repository
run: mvn package
36 changes: 36 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions
name: Release
on:
push:
tags:
- '*'
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Compile and Package the Maven repository
run: mvn package
# https://docs.github.com/en/rest/releases/releases#create-a-release
# https://docs.github.com/en/rest/releases/assets#upload-a-release-asset
- name: Create release and upload assets
run: |
RELEASE="$(curl \
--silent \
--show-error \
--fail \
--request POST \
--url https://api.github.com/repos/${{github.repository}}/releases \
--data '{"tag_name":"${{github.ref_name}}","name":"${{github.repository}} ${{github.ref_name}}","draft":false,"prerelease":false}' \
--header "Accept: application/vnd.github.v3+json" \
--header "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" | jq '.id')" && \
curl \
--silent \
--show-error \
--fail \
--request POST \
--url https://uploads.github.com/repos/${{github.repository}}/releases/${RELEASE}/assets?name=helloworldjsp.war \
--header "Accept: application/vnd.github.v3+json" \
--header "Content-Type: $(file -b --mime-type target/helloworldjsp.war)" \
--header "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
--data-binary @target/helloworldjsp.war
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target
4 changes: 2 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
https://www.apache.org/licenses/

TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION

Expand Down Expand Up @@ -192,7 +192,7 @@
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
https://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,
Expand Down
46 changes: 45 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,46 @@
# helloworldjsp
Hello World JSP application

`helloworldjsp` is a [JavaServer Pages](https://openliberty.io/docs/latest/reference/feature/jsp-2.2.html) application.

## Download or Run

Download `helloworldjsp.war` from <https://github.com/IBM/helloworldjsp/releases/latest>

This application requires at least the following features to be installed:

```
<featureManager>
<feature>jsp-2.2</feature>
<featureManager>
```

Add the application to the `dropins` folder and then access at <http://localhost:9080/helloworldjsp/> or <https://localhost:9443/helloworldjsp/>

## Development

1. Pre-requisities:
1. Java >= 8 is required on your `PATH`; for example, [IBM Semeru Runtimes](https://developer.ibm.com/languages/java/semeru-runtimes/downloads/)
1. [Apache Maven](https://maven.apache.org/download.cgi) is required on your `PATH`.
1. Build the WAR file:
```
mvn clean install
```
1. The file should be under `target/helloworldjsp.war`
1. Or build and run Liberty:
```
mvn clean install liberty:run
```
1. Wait for the message, "server is ready to run a smarter planet". For example:
```
CWWKF0011I: The helloworldjspServer server is ready to run a smarter planet. The helloworldjspServer server started in 1.023 seconds.
```
1. Open your browser to the HTTP or HTTPS page:
* <http://localhost:9080/>
* <https://localhost:9443/>
### Eclipse
To develop in Eclipse:
1. Install the Eclipse flavor: [Eclipse IDE for Enterprise Java and Web Developers](https://www.eclipse.org/downloads/packages/)
1. Start Eclipse and click File } Import... } Maven } Existing Maven Projects
125 changes: 125 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
(C) Copyright IBM Corporation 2024.
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.
-->
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>helloworldjsp</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>

<parent>
<groupId>io.openliberty.tools</groupId>
<artifactId>liberty-maven-app-parent</artifactId>
<version>3.10</version>
</parent>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<packaging.type>minify,runnable</packaging.type>
</properties>

<profiles>
<profile>
<id>usr-package</id>
<properties>
<packaging.type>usr</packaging.type>
</properties>
</profile>
</profiles>

<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>

<!-- Test -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.10.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5</artifactId>
<version>5.3.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>2.0.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
<version>2.0.12</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.4.0</version>
<configuration>
<packagingExcludes>pom.xml</packagingExcludes>
</configuration>
</plugin>
<plugin>
<groupId>io.openliberty.tools</groupId>
<artifactId>liberty-maven-plugin</artifactId>
<version>3.10</version>
<configuration>
<assemblyArtifact>
<groupId>io.openliberty</groupId>
<artifactId>openliberty-runtime</artifactId>
<version>[24.0.0.1,)</version>
<type>zip</type>
</assemblyArtifact>
<serverName>${project.artifactId}Server</serverName>
<include>${packaging.type}</include>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.2.5</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
34 changes: 34 additions & 0 deletions src/main/java/com/example/HelloServlet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*******************************************************************************
* (c) Copyright IBM Corporation 2024.
*
* 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 com.example;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet(urlPatterns="/helloworld")
public class HelloServlet extends HttpServlet {
private static final long serialVersionUID = 1L;

protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/plain");
response.getWriter().append("Hello World Servlet @ " + String.format("%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS.%1$tL", new java.util.Date()) + "\n");
}
}
27 changes: 27 additions & 0 deletions src/main/liberty/config/server.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
(C) Copyright IBM Corporation 2024.
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.
-->
<server>
<featureManager>
<feature>jsp-2.2</feature>
<!-- So that Liberty exposes a TLS port. -->
<feature>transportSecurity-1.0</feature>
</featureManager>

<httpEndpoint host="*" httpPort="9080" httpsPort="9443" id="defaultHttpEndpoint" />

<webApplication id="helloworldjsp" location="helloworldjsp.war" name="helloworldjsp" contextRoot="/" />
</server>
9 changes: 9 additions & 0 deletions src/main/webapp/META-INF/web.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_HelloWorld" version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<display-name>Hello World JSP</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>
14 changes: 14 additions & 0 deletions src/main/webapp/helloworld.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<%@ page contentType="text/html; charset=UTF-8" %>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Hello World</title>
<meta charset="UTF-8">
<meta name="theme-color" content="#ffffff">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="Hello World">
</head>
<body>
<p>Hello World JSP @ <%= String.format("%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS.%1$tL", new java.util.Date()) %></p>
</body>
</html>
17 changes: 17 additions & 0 deletions src/main/webapp/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>Hello World</title>
<meta charset="UTF-8">
<meta name="theme-color" content="#ffffff">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="Hello World">
</head>
<body>
<h1>Hello World</h1>
<ul>
<li><a href="helloworld.jsp">JSP</a></li>
<li><a href="helloworld">Servlet</a></li>
</ul>
</body>
</html>
48 changes: 48 additions & 0 deletions src/test/java/com/example/it/EndpointIT.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*******************************************************************************
* (c) Copyright IBM Corporation 2024.
*
* 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 com.example.it;

import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.apache.hc.client5.http.classic.methods.HttpGet;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.client5.http.impl.classic.HttpClients;
import org.apache.hc.core5.http.io.entity.EntityUtils;
import org.apache.hc.core5.http.message.StatusLine;
import org.apache.hc.core5.http.HttpStatus;

public class EndpointIT {
private static String URL;

@BeforeAll
public static void init() {
URL = "http://localhost:9080/helloworld";
}

@Test
public void testServlet() throws Exception {
try (final CloseableHttpClient httpclient = HttpClients.createDefault()) {
final HttpGet httpget = new HttpGet(URL);
httpclient.execute(httpget, response -> {
assertEquals(HttpStatus.SC_OK, response.getCode(), "HTTP GET failed");
String responseText = EntityUtils.toString(response.getEntity());
assertTrue(responseText.contains("Hello World"), "Unexpected response body");
return null;
});
}
}
}

0 comments on commit 9ca8096

Please sign in to comment.