Skip to content

Commit 472940e

Browse files
committed
Add the application sources from archived openshift-quickstarts repository which are referenced in our tests
1 parent d9b0f95 commit 472940e

File tree

10 files changed

+773
-0
lines changed

10 files changed

+773
-0
lines changed

undertow-jdbc/pom.xml

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ JBoss, Home of Professional Open Source.
4+
~ Copyright 2012 Red Hat, Inc., and individual contributors
5+
~ as indicated by the @author tags.
6+
~
7+
~ Licensed under the Apache License, Version 2.0 (the "License");
8+
~ you may not use this file except in compliance with the License.
9+
~ You may obtain a copy of the License at
10+
~
11+
~ http://www.apache.org/licenses/LICENSE-2.0
12+
~
13+
~ Unless required by applicable law or agreed to in writing, software
14+
~ distributed under the License is distributed on an "AS IS" BASIS,
15+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
~ See the License for the specific language governing permissions and
17+
~ limitations under the License.
18+
-->
19+
20+
<project xmlns="http://maven.apache.org/POM/4.0.0"
21+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
22+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
23+
<modelVersion>4.0.0</modelVersion>
24+
25+
<groupId>org.openshift.quickstarts.undertow</groupId>
26+
<artifactId>jdbc</artifactId>
27+
<version>1.0.0.Final</version>
28+
29+
<name>Undertow JDBC Example</name>
30+
<description>Undertow JDBC Example for OpenShift Java S2I</description>
31+
32+
<properties>
33+
<maven.compiler.source>1.8</maven.compiler.source>
34+
<maven.compiler.target>1.8</maven.compiler.target>
35+
36+
<version.undertow>2.2.19.Final</version.undertow>
37+
<version.jboss.logmanager>2.0.3.Final-redhat-1</version.jboss.logmanager>
38+
</properties>
39+
40+
<dependencies>
41+
42+
<dependency>
43+
<groupId>io.undertow</groupId>
44+
<artifactId>undertow-core</artifactId>
45+
<version>${version.undertow}</version>
46+
</dependency>
47+
48+
<dependency>
49+
<groupId>io.undertow</groupId>
50+
<artifactId>undertow-servlet</artifactId>
51+
<version>${version.undertow}</version>
52+
</dependency>
53+
54+
<dependency>
55+
<groupId>org.jboss.logmanager</groupId>
56+
<artifactId>jboss-logmanager</artifactId>
57+
<version>${version.jboss.logmanager}</version>
58+
</dependency>
59+
60+
<!-- Database drivers -->
61+
<dependency>
62+
<groupId>mysql</groupId>
63+
<artifactId>mysql-connector-java</artifactId>
64+
<version>8.0.28</version>
65+
</dependency>
66+
<dependency>
67+
<groupId>org.postgresql</groupId>
68+
<artifactId>postgresql</artifactId>
69+
<version>42.4.1</version>
70+
</dependency>
71+
72+
</dependencies>
73+
74+
<profiles>
75+
<profile>
76+
<id>fat-jar</id>
77+
<activation>
78+
<activeByDefault>true</activeByDefault>
79+
</activation>
80+
<build>
81+
<finalName>undertow-jdbc</finalName>
82+
<plugins>
83+
<plugin>
84+
<groupId>org.apache.maven.plugins</groupId>
85+
<artifactId>maven-shade-plugin</artifactId>
86+
<executions>
87+
<execution>
88+
<phase>package</phase>
89+
<goals>
90+
<goal>shade</goal>
91+
</goals>
92+
</execution>
93+
</executions>
94+
</plugin>
95+
<plugin>
96+
<groupId>org.apache.maven.plugins</groupId>
97+
<artifactId>maven-jar-plugin</artifactId>
98+
<configuration>
99+
<archive>
100+
<manifest>
101+
<mainClass>org.openshift.quickstarts.undertow.servlet.ServletServer</mainClass>
102+
</manifest>
103+
</archive>
104+
</configuration>
105+
</plugin>
106+
</plugins>
107+
</build>
108+
</profile>
109+
<profile>
110+
<id>flat-classpath-jar</id>
111+
<build>
112+
<finalName>undertow-jdbc</finalName>
113+
<plugins>
114+
<plugin>
115+
<artifactId>maven-dependency-plugin</artifactId>
116+
<executions>
117+
<execution>
118+
<phase>generate-sources</phase>
119+
<goals>
120+
<goal>copy-dependencies</goal>
121+
</goals>
122+
<configuration>
123+
<outputDirectory>${project.build.directory}/lib</outputDirectory>
124+
<useRepositoryLayout>true</useRepositoryLayout>
125+
</configuration>
126+
</execution>
127+
<execution>
128+
<id>build-classpath</id>
129+
<phase>generate-resources</phase>
130+
<goals>
131+
<goal>build-classpath</goal>
132+
</goals>
133+
<configuration>
134+
<outputFile>${project.build.directory}/lib/classpath</outputFile>
135+
<localRepoProperty>lib</localRepoProperty>
136+
</configuration>
137+
</execution>
138+
</executions>
139+
</plugin>
140+
</plugins>
141+
</build>
142+
</profile>
143+
</profiles>
144+
</project>
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
2+
#
3+
# JBoss, Home of Professional Open Source.
4+
# Copyright 2012 Red Hat, Inc., and individual contributors
5+
# as indicated by the @author tags.
6+
#
7+
# Licensed under the Apache License, Version 2.0 (the "License");
8+
# you may not use this file except in compliance with the License.
9+
# You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
#
19+
20+
# Additional logger names to configure (root logger is always configured)
21+
loggers=org.xnio.listener,org.xnio.ssl,org.apache,io.undertow.util.TestHttpClient
22+
23+
# Root logger configuration
24+
logger.level=${test.level:ERROR}
25+
logger.handlers=CONSOLE
26+
27+
# Console handler configuration
28+
handler.CONSOLE=org.jboss.logmanager.handlers.ConsoleHandler
29+
handler.CONSOLE.properties=autoFlush,target
30+
handler.CONSOLE.target=SYSTEM_ERR
31+
handler.CONSOLE.level=ALL
32+
handler.CONSOLE.autoFlush=true
33+
handler.CONSOLE.formatter=PATTERN
34+
35+
# The log format pattern
36+
formatter.PATTERN=org.jboss.logmanager.formatters.PatternFormatter
37+
formatter.PATTERN.properties=pattern
38+
formatter.PATTERN.pattern=%d{HH:mm:ss,SSS} %-5p (%t) [%c] <%F:%L> %m%n
39+
40+
logger.org.xnio.listener.level=DEBUG
41+
42+
logger.org.xnio.ssl.level=DEBUG
43+
44+
logger.org.apache.level=WARN
45+
logger.org.apache.useParentHandlers=false
46+
logger.io.undertow.util.TestHttpClient.level=WARN
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
/*
2+
* JBoss, Home of Professional Open Source.
3+
* Copyright 2014 Red Hat, Inc., and individual contributors
4+
* as indicated by the @author tags.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
package org.openshift.quickstarts.undertow.servlet;
20+
21+
import java.io.IOException;
22+
import java.io.PrintWriter;
23+
import java.sql.Connection;
24+
import java.sql.DriverManager;
25+
import java.sql.ResultSet;
26+
import java.sql.SQLException;
27+
import java.sql.Statement;
28+
29+
import javax.servlet.ServletConfig;
30+
import javax.servlet.ServletException;
31+
import javax.servlet.http.HttpServlet;
32+
import javax.servlet.http.HttpServletRequest;
33+
import javax.servlet.http.HttpServletResponse;
34+
35+
/**
36+
* @author Doug Palmer
37+
*/
38+
public class PhoneBookServlet extends HttpServlet {
39+
40+
public static final String NAME = "name";
41+
public static final String NUMBER = "number";
42+
public static final String TABLE = "phonebook";
43+
44+
private String username;
45+
private String password;
46+
private String url;
47+
private String driver;
48+
49+
@Override
50+
public void init(final ServletConfig config) throws ServletException {
51+
super.init(config);
52+
53+
url = config.getInitParameter("url");
54+
driver = config.getInitParameter("driver");
55+
username = config.getInitParameter("username");
56+
password = config.getInitParameter("password");
57+
58+
try {
59+
switch (driver) {
60+
case "mysql":
61+
Class.forName("com.mysql.jdbc.Driver");
62+
break;
63+
case "postgresql":
64+
Class.forName("org.postgresql.Driver");
65+
break;
66+
}
67+
String create = "CREATE TABLE IF NOT EXISTS " + TABLE + " (" + NAME + " VARCHAR(20)," + NUMBER +" VARCHAR(10))";
68+
Connection con = DriverManager.getConnection(url, username, password);
69+
Statement stmt = con.createStatement();
70+
stmt.execute(create);
71+
} catch (Exception ex)
72+
{
73+
throw new ServletException(ex);
74+
}
75+
}
76+
77+
@Override
78+
protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {
79+
try {
80+
PrintWriter writer = resp.getWriter();
81+
Connection con = DriverManager.getConnection(url, username, password);
82+
Statement stmt = con.createStatement();
83+
84+
String name = req.getParameter(NAME);
85+
if(name == null) {
86+
throw new ServletException("Parameter " + NAME + " is required");
87+
}
88+
String number = req.getParameter(NUMBER);
89+
if(number == null) {
90+
String select = "SELECT * FROM " + TABLE + " WHERE " + NAME +"='" + name + "'";
91+
ResultSet result = stmt.executeQuery(select);
92+
result.next();
93+
number = result.getString(NUMBER);
94+
writer.write("Number for " + name + " is " + number);
95+
}
96+
else {
97+
String insert = "INSERT INTO " + TABLE + " VALUES ('"+ name + "','" + number +"')";
98+
stmt.execute(insert);
99+
writer.write("Stored " + number + " for " + name);
100+
}
101+
con.close();
102+
writer.close();
103+
}
104+
catch (SQLException ex) {
105+
throw new ServletException(ex);
106+
}
107+
}
108+
109+
@Override
110+
protected void doPost(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {
111+
doGet(req, resp);
112+
}
113+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* JBoss, Home of Professional Open Source.
3+
* Copyright 2014 Red Hat, Inc., and individual contributors
4+
* as indicated by the @author tags.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
package org.openshift.quickstarts.undertow.servlet;
20+
21+
import io.undertow.Handlers;
22+
import io.undertow.Undertow;
23+
import io.undertow.server.HttpHandler;
24+
import io.undertow.server.handlers.PathHandler;
25+
import io.undertow.servlet.api.DeploymentInfo;
26+
import io.undertow.servlet.api.DeploymentManager;
27+
28+
import static io.undertow.servlet.Servlets.defaultContainer;
29+
import static io.undertow.servlet.Servlets.deployment;
30+
import static io.undertow.servlet.Servlets.servlet;
31+
32+
/**
33+
* @author Doug Palmer
34+
*/
35+
public class ServletServer {
36+
public static final String MYAPP = "/";
37+
38+
public static void main(final String[] args) {
39+
String driver = System.getenv("DB_DRIVER");
40+
String host = System.getenv("OPENJDK_APP_" + driver.toUpperCase() + "_SERVICE_HOST");
41+
String port = System.getenv("OPENJDK_APP_" + driver.toUpperCase() + "_SERVICE_PORT");
42+
String database = System.getenv("DB_DATABASE");
43+
String username = System.getenv("DB_USERNAME");
44+
String password = System.getenv("DB_PASSWORD");
45+
String url = "jdbc:" + driver + "://" + host + ":" + port + "/" + database;
46+
47+
try {
48+
49+
DeploymentInfo servletBuilder = deployment()
50+
.setClassLoader(ServletServer.class.getClassLoader())
51+
.setContextPath(MYAPP)
52+
.setDeploymentName("test.war")
53+
.addServlets(
54+
servlet("PhoneBookServlet", PhoneBookServlet.class)
55+
.addInitParam("url", url)
56+
.addInitParam("driver", driver)
57+
.addInitParam("username", username)
58+
.addInitParam("password", password)
59+
.addMapping("/*"));
60+
61+
DeploymentManager manager = defaultContainer().addDeployment(servletBuilder);
62+
manager.deploy();
63+
64+
HttpHandler servletHandler = manager.start();
65+
PathHandler path = Handlers.path(Handlers.redirect(MYAPP))
66+
.addPrefixPath(MYAPP, servletHandler);
67+
Undertow server = Undertow.builder()
68+
.addHttpListener(8080, "0.0.0.0")
69+
.setHandler(path)
70+
.build();
71+
server.start();
72+
} catch (Exception e) {
73+
throw new RuntimeException(e);
74+
}
75+
}
76+
}

0 commit comments

Comments
 (0)