├── src └── main │ ├── java │ ├── .gitkeep │ └── org │ │ └── openshift │ │ ├── JaxrsConfig.java │ │ ├── InsultResource.java │ │ └── InsultGenerator.java │ ├── resources │ └── .gitkeep │ └── webapp │ ├── .index.html.un~ │ └── index.jsp ├── README.md ├── pom.xml └── insults.sql /src/main/java/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/webapp/.index.html.un~: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ailisp/book-insultapp/master/src/main/webapp/.index.html.un~ -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | OpenShift 3 Java EE Insult Application 2 | ==================== 3 | 4 | This repository contains a sample application for the book *Getting Started with Java on OpenShift* 5 | 6 | -------------------------------------------------------------------------------- /src/main/java/org/openshift/JaxrsConfig.java: -------------------------------------------------------------------------------- 1 | package org.openshift; 2 | import javax.ws.rs.ApplicationPath; 3 | import javax.ws.rs.core.Application; 4 | @ApplicationPath("/api") 5 | public class JaxrsConfig extends Application{ } 6 | -------------------------------------------------------------------------------- /src/main/webapp/index.jsp: -------------------------------------------------------------------------------- 1 | <%@page import="org.openshift.InsultGenerator"%> 2 | <%@ page language="java" contentType="text/html; charset=ISO-8859-1" 3 | pageEncoding="ISO-8859-1"%> 4 | 5 | 6 | 7 | 8 | Insult Generator 9 | 10 | 11 | <% 12 | out.println(new InsultGenerator().generateInsult()); 13 | %> 14 | 15 | 16 | -------------------------------------------------------------------------------- /src/main/java/org/openshift/InsultResource.java: -------------------------------------------------------------------------------- 1 | package org.openshift; 2 | import java.util.HashMap; 3 | import javax.enterprise.context.RequestScoped; 4 | import javax.ws.rs.GET; 5 | import javax.ws.rs.Path; 6 | import javax.ws.rs.Produces; 7 | @RequestScoped @Path("/insult") 8 | public class InsultResource { 9 | @GET() 10 | @Produces("application/json") 11 | public HashMap getInsult() { 12 | HashMap theInsult = new HashMap(); 13 | theInsult.put("insult", new InsultGenerator().generateInsult()); 14 | return theInsult; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/org/openshift/InsultGenerator.java: -------------------------------------------------------------------------------- 1 | package org.openshift; 2 | import java.sql.Connection; 3 | import java.sql.DriverManager; 4 | import java.sql.ResultSet; 5 | import java.sql.Statement; 6 | 7 | public class InsultGenerator { 8 | public String generateInsult() { 9 | String vowels = "AEIOU"; 10 | String article = "an"; 11 | String theInsult = ""; 12 | try { 13 | String databaseURL = "jdbc:postgresql://"; 14 | databaseURL += System.getenv("POSTGRESQL_SERVICE_HOST"); 15 | databaseURL += "/" + System.getenv("POSTGRESQL_DATABASE"); 16 | String username = System.getenv("POSTGRESQL_USER"); 17 | String password = System.getenv("PGPASSWORD"); 18 | Connection connection = DriverManager.getConnection(databaseURL, username, 19 | password); 20 | if (connection != null) { 21 | String SQL = "select a.string AS first, b.string AS second, c.string AS noun from short_adjective a , long_adjective b, noun c ORDER BY random() limit 1"; Statement stmt = connection.createStatement(); 22 | ResultSet rs = stmt.executeQuery(SQL); 23 | while (rs.next()) { 24 | if (vowels.indexOf(rs.getString("first").charAt(0)) == -1) { 25 | article = "a"; 26 | } 27 | theInsult = String.format("Thou art %s %s %s %s!", article, 28 | rs.getString("first"), rs.getString("second"), rs.getString("noun")); 29 | } 30 | rs.close(); 31 | connection.close(); 32 | } 33 | } catch (Exception e) { 34 | return "Database connection problem!"; } 35 | return theInsult; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | org.openshift 6 | war 7 | 1.0 8 | InsultApp 9 | 10 | 11 | UTF-8 12 | 1.8 13 | 1.8 14 | 15 | 16 | 17 | 18 | org.postgresql 19 | postgresql 20 | 42.2.5 21 | 22 | 23 | 24 | javax 25 | javaee-api 26 | 7.0 27 | provided 28 | 29 | 30 | 31 | 32 | 33 | 34 | org.apache.maven.plugins 35 | maven-war-plugin 36 | 2.6 37 | 38 | false 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | openshift 51 | 52 | InsultApp 53 | 54 | 55 | org.apache.maven.plugins 56 | maven-war-plugin 57 | 2.6 58 | 59 | false 60 | target 61 | ROOT 62 | 63 | 64 | 65 | 66 | 67 | 68 | InsultApp 69 | 70 | -------------------------------------------------------------------------------- /insults.sql: -------------------------------------------------------------------------------- 1 | DROP TABLE IF EXISTS short_adjective; 2 | DROP TABLE IF EXISTS long_adjective; 3 | DROP TABLE IF EXISTS noun; 4 | 5 | BEGIN; 6 | 7 | CREATE TABLE short_adjective (id serial PRIMARY KEY, string varchar); 8 | CREATE TABLE long_adjective (id serial PRIMARY KEY, string varchar); 9 | CREATE TABLE noun (id serial PRIMARY KEY, string varchar); 10 | 11 | INSERT INTO short_adjective (string) VALUES ('artless'); 12 | INSERT INTO short_adjective (string) VALUES ('bawdy'); 13 | INSERT INTO short_adjective (string) VALUES ('beslubbering'); 14 | INSERT INTO short_adjective (string) VALUES ('bootless'); 15 | INSERT INTO short_adjective (string) VALUES ('churlish'); 16 | INSERT INTO short_adjective (string) VALUES ('cockered'); 17 | INSERT INTO short_adjective (string) VALUES ('clouted'); 18 | INSERT INTO short_adjective (string) VALUES ('craven'); 19 | INSERT INTO short_adjective (string) VALUES ('currish'); 20 | INSERT INTO short_adjective (string) VALUES ('dankish'); 21 | INSERT INTO short_adjective (string) VALUES ('dissembling'); 22 | INSERT INTO short_adjective (string) VALUES ('droning'); 23 | INSERT INTO short_adjective (string) VALUES ('errant'); 24 | INSERT INTO short_adjective (string) VALUES ('fawning'); 25 | INSERT INTO short_adjective (string) VALUES ('fobbing'); 26 | INSERT INTO short_adjective (string) VALUES ('froward'); 27 | INSERT INTO short_adjective (string) VALUES ('frothy'); 28 | INSERT INTO short_adjective (string) VALUES ('gleeking'); 29 | INSERT INTO short_adjective (string) VALUES ('goatish'); 30 | INSERT INTO short_adjective (string) VALUES ('gorbellied'); 31 | INSERT INTO short_adjective (string) VALUES ('impertinent'); 32 | INSERT INTO short_adjective (string) VALUES ('infectious'); 33 | INSERT INTO short_adjective (string) VALUES ('jarring'); 34 | INSERT INTO short_adjective (string) VALUES ('loggerheaded'); 35 | INSERT INTO short_adjective (string) VALUES ('lumpish'); 36 | INSERT INTO short_adjective (string) VALUES ('mammering'); 37 | INSERT INTO short_adjective (string) VALUES ('mangled'); 38 | INSERT INTO short_adjective (string) VALUES ('mewling'); 39 | INSERT INTO short_adjective (string) VALUES ('paunchy'); 40 | INSERT INTO short_adjective (string) VALUES ('pribbling'); 41 | INSERT INTO short_adjective (string) VALUES ('puking'); 42 | INSERT INTO short_adjective (string) VALUES ('puny'); 43 | INSERT INTO short_adjective (string) VALUES ('qualling'); 44 | INSERT INTO short_adjective (string) VALUES ('rank'); 45 | INSERT INTO short_adjective (string) VALUES ('reeky'); 46 | INSERT INTO short_adjective (string) VALUES ('roguish'); 47 | INSERT INTO short_adjective (string) VALUES ('ruttish'); 48 | INSERT INTO short_adjective (string) VALUES ('saucy'); 49 | INSERT INTO short_adjective (string) VALUES ('spleeny'); 50 | INSERT INTO short_adjective (string) VALUES ('spongy'); 51 | INSERT INTO short_adjective (string) VALUES ('surly'); 52 | INSERT INTO short_adjective (string) VALUES ('tottering'); 53 | INSERT INTO short_adjective (string) VALUES ('unmuzzled'); 54 | INSERT INTO short_adjective (string) VALUES ('vain'); 55 | INSERT INTO short_adjective (string) VALUES ('venomed'); 56 | INSERT INTO short_adjective (string) VALUES ('villainous'); 57 | INSERT INTO short_adjective (string) VALUES ('warped'); 58 | INSERT INTO short_adjective (string) VALUES ('wayward'); 59 | INSERT INTO short_adjective (string) VALUES ('weedy'); 60 | INSERT INTO short_adjective (string) VALUES ('yeasty'); 61 | 62 | INSERT INTO long_adjective (string) VALUES ('base-court'); 63 | INSERT INTO long_adjective (string) VALUES ('bat-fowling'); 64 | INSERT INTO long_adjective (string) VALUES ('beef-witted'); 65 | INSERT INTO long_adjective (string) VALUES ('beetle-headed'); 66 | INSERT INTO long_adjective (string) VALUES ('boil-brained'); 67 | INSERT INTO long_adjective (string) VALUES ('clapper-clawed'); 68 | INSERT INTO long_adjective (string) VALUES ('clay-brained'); 69 | INSERT INTO long_adjective (string) VALUES ('common-kissing'); 70 | INSERT INTO long_adjective (string) VALUES ('crook-pated'); 71 | INSERT INTO long_adjective (string) VALUES ('dismal-dreaming'); 72 | INSERT INTO long_adjective (string) VALUES ('dizzy-eyed'); 73 | INSERT INTO long_adjective (string) VALUES ('doghearted'); 74 | INSERT INTO long_adjective (string) VALUES ('dread-bolted'); 75 | INSERT INTO long_adjective (string) VALUES ('earth-vexing'); 76 | INSERT INTO long_adjective (string) VALUES ('elf-skinned'); 77 | INSERT INTO long_adjective (string) VALUES ('fat-kidneyed'); 78 | INSERT INTO long_adjective (string) VALUES ('fen-sucked'); 79 | INSERT INTO long_adjective (string) VALUES ('flap-mouthed'); 80 | INSERT INTO long_adjective (string) VALUES ('fly-bitten'); 81 | INSERT INTO long_adjective (string) VALUES ('folly-fallen'); 82 | INSERT INTO long_adjective (string) VALUES ('fool-born'); 83 | INSERT INTO long_adjective (string) VALUES ('full-gorged'); 84 | INSERT INTO long_adjective (string) VALUES ('guts-griping'); 85 | INSERT INTO long_adjective (string) VALUES ('half-faced'); 86 | INSERT INTO long_adjective (string) VALUES ('hasty-witted'); 87 | INSERT INTO long_adjective (string) VALUES ('hedge-born'); 88 | INSERT INTO long_adjective (string) VALUES ('hell-hated'); 89 | INSERT INTO long_adjective (string) VALUES ('idle-headed'); 90 | INSERT INTO long_adjective (string) VALUES ('ill-breeding'); 91 | INSERT INTO long_adjective (string) VALUES ('ill-nurtured'); 92 | INSERT INTO long_adjective (string) VALUES ('knotty-pated'); 93 | INSERT INTO long_adjective (string) VALUES ('milk-livered'); 94 | INSERT INTO long_adjective (string) VALUES ('motley-minded'); 95 | INSERT INTO long_adjective (string) VALUES ('onion-eyed'); 96 | INSERT INTO long_adjective (string) VALUES ('plume-plucked'); 97 | INSERT INTO long_adjective (string) VALUES ('pottle-deep'); 98 | INSERT INTO long_adjective (string) VALUES ('pox-marked'); 99 | INSERT INTO long_adjective (string) VALUES ('reeling-ripe'); 100 | INSERT INTO long_adjective (string) VALUES ('rough-hewn'); 101 | INSERT INTO long_adjective (string) VALUES ('rude-growing'); 102 | INSERT INTO long_adjective (string) VALUES ('rump-fed'); 103 | INSERT INTO long_adjective (string) VALUES ('shard-borne'); 104 | INSERT INTO long_adjective (string) VALUES ('sheep-biting'); 105 | INSERT INTO long_adjective (string) VALUES ('spur-galled'); 106 | INSERT INTO long_adjective (string) VALUES ('swag-bellied'); 107 | INSERT INTO long_adjective (string) VALUES ('tardy-gaited'); 108 | INSERT INTO long_adjective (string) VALUES ('tickle-brained'); 109 | INSERT INTO long_adjective (string) VALUES ('toad-spotted'); 110 | INSERT INTO long_adjective (string) VALUES ('unchin-snouted'); 111 | INSERT INTO long_adjective (string) VALUES ('weather-bitten'); 112 | 113 | INSERT INTO noun (string) VALUES ('apple-john'); 114 | INSERT INTO noun (string) VALUES ('baggage'); 115 | INSERT INTO noun (string) VALUES ('barnacle'); 116 | INSERT INTO noun (string) VALUES ('bladder'); 117 | INSERT INTO noun (string) VALUES ('boar-pig'); 118 | INSERT INTO noun (string) VALUES ('bugbear'); 119 | INSERT INTO noun (string) VALUES ('bum-bailey'); 120 | INSERT INTO noun (string) VALUES ('canker-blossom'); 121 | INSERT INTO noun (string) VALUES ('clack-dish'); 122 | INSERT INTO noun (string) VALUES ('clotpole'); 123 | INSERT INTO noun (string) VALUES ('coxcomb'); 124 | INSERT INTO noun (string) VALUES ('codpiece'); 125 | INSERT INTO noun (string) VALUES ('death-token'); 126 | INSERT INTO noun (string) VALUES ('dewberry'); 127 | INSERT INTO noun (string) VALUES ('flap-dragon'); 128 | INSERT INTO noun (string) VALUES ('flax-wench'); 129 | INSERT INTO noun (string) VALUES ('flirt-gill'); 130 | INSERT INTO noun (string) VALUES ('foot-licker'); 131 | INSERT INTO noun (string) VALUES ('fustilarian'); 132 | INSERT INTO noun (string) VALUES ('giglet'); 133 | INSERT INTO noun (string) VALUES ('gudgeon'); 134 | INSERT INTO noun (string) VALUES ('haggard'); 135 | INSERT INTO noun (string) VALUES ('harpy'); 136 | INSERT INTO noun (string) VALUES ('hedge-pig'); 137 | INSERT INTO noun (string) VALUES ('horn-beast'); 138 | INSERT INTO noun (string) VALUES ('hugger-mugger'); 139 | INSERT INTO noun (string) VALUES ('joithead'); 140 | INSERT INTO noun (string) VALUES ('lewdster'); 141 | INSERT INTO noun (string) VALUES ('lout'); 142 | INSERT INTO noun (string) VALUES ('maggot-pie'); 143 | INSERT INTO noun (string) VALUES ('malt-worm'); 144 | INSERT INTO noun (string) VALUES ('mammet'); 145 | INSERT INTO noun (string) VALUES ('measle'); 146 | INSERT INTO noun (string) VALUES ('minnow'); 147 | INSERT INTO noun (string) VALUES ('miscreant'); 148 | INSERT INTO noun (string) VALUES ('moldwarp'); 149 | INSERT INTO noun (string) VALUES ('mumble-news'); 150 | INSERT INTO noun (string) VALUES ('nut-hook'); 151 | INSERT INTO noun (string) VALUES ('pigeon-egg'); 152 | INSERT INTO noun (string) VALUES ('pignut'); 153 | INSERT INTO noun (string) VALUES ('puttock'); 154 | INSERT INTO noun (string) VALUES ('pumpion'); 155 | INSERT INTO noun (string) VALUES ('ratsbane'); 156 | INSERT INTO noun (string) VALUES ('scut'); 157 | INSERT INTO noun (string) VALUES ('skainsmate'); 158 | INSERT INTO noun (string) VALUES ('strumpet'); 159 | INSERT INTO noun (string) VALUES ('varlot'); 160 | INSERT INTO noun (string) VALUES ('vassal'); 161 | INSERT INTO noun (string) VALUES ('whey-face'); 162 | INSERT INTO noun (string) VALUES ('wagtail'); 163 | 164 | COMMIT; --------------------------------------------------------------------------------