-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
simple-app
project and update company-web-server
to use pooli…
…ng (#11) * Add setup/usage instructions for company-web-server and rename docs to swagger Signed-off-by: Sanjula Ganepola <[email protected]> * Add simple-app Signed-off-by: Sanjula Ganepola <[email protected]> * Update README Signed-off-by: Sanjula Ganepola <[email protected]> * fix demo type table Signed-off-by: Sanjula Ganepola <[email protected]> * Add more endpoints Signed-off-by: Sanjula Ganepola <[email protected]> * Add endpoint for tracing Signed-off-by: Sanjula Ganepola <[email protected]> * Update to v0.0.4 and fix demo types Signed-off-by: Sanjula Ganepola <[email protected]> * Upgrade to 0.04, switch to use pool, and fix imports Signed-off-by: Sanjula Ganepola <[email protected]> * fix run app command Signed-off-by: Sanjula Ganepola <[email protected]> * fix indentation Signed-off-by: Sanjula Ganepola <[email protected]> * fix note not rendering Signed-off-by: Sanjula Ganepola <[email protected]> * fix Signed-off-by: Sanjula Ganepola <[email protected]> * Update LICENSE Co-authored-by: Jonathan <[email protected]> * Update instructions Co-authored-by: Jonathan <[email protected]> * minor fixes Signed-off-by: Sanjula Ganepola <[email protected]> --------- Signed-off-by: Sanjula Ganepola <[email protected]> Co-authored-by: Jonathan <[email protected]>
- Loading branch information
1 parent
b2c8a9c
commit 9e1da38
Showing
37 changed files
with
791 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"recommendations": [ | ||
"vscjava.vscode-java-pack", | ||
"GitHub.vscode-github-actions", | ||
"wayou.vscode-todo-highlight", | ||
"streetsidesoftware.code-spell-checker" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
{ | ||
"java.configuration.updateBuildConfiguration": "automatic" | ||
} | ||
"java.configuration.updateBuildConfiguration": "automatic", | ||
"files.insertFinalNewline": true, | ||
"editor.codeActionsOnSave": { | ||
"source.organizeImports": "always" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,57 @@ | ||
# Company Web Server | ||
|
||
Company web server to manage departments, employees, and sales | ||
Jetty company web server to manage departments, employees, and sales | ||
|
||
## Setup | ||
|
||
1. Ensure the [Mapepire Server](https://mapepire-ibmi.github.io/guides/sysadmin) is installed and running on the IBM i. | ||
|
||
2. Create the `SAMPLE` schema on the IBM i: | ||
|
||
```sql | ||
QSYS.CREATE_SQL_SAMPLE('sample') | ||
``` | ||
|
||
3. Clone the repository and build the application: | ||
|
||
```sh | ||
git clone https://github.com/Mapepire-IBMi/samples.git | ||
cd java/company-web-server | ||
mvn clean package | ||
``` | ||
|
||
4. Start the company web server: | ||
|
||
```sh | ||
cd target | ||
java -jar company-web-server-1.0-SNAPSHOT-jar-with-dependencies.jar | ||
``` | ||
|
||
5. Start a web server to launch the Swagger UI: | ||
|
||
```sh | ||
npm install -g http-server | ||
cd swagger | ||
http-server --cors | ||
``` | ||
|
||
6. Access the Swagger UI at http://localhost:8080 in the browser. | ||
|
||
## Usage | ||
|
||
1. Connect to a database using the `/connect` endpoint. | ||
|
||
2. Set the server trace level using the `/tracing` endpoint. | ||
|
||
3. Experiment with the various endpoints: | ||
|
||
| Method | Endpoint | Description | | ||
| ------ | ----------------------- | --------------------------------------------------------- | | ||
| `GET` | `/departments` | Get a list of departments | | ||
| `GET` | `/departments/{deptNo}` | Get a department by department number | | ||
| `GET` | `/employees` | Get a list of employees | | ||
| `GET` | `/employees/{empNo}` | Get an employee by employee number | | ||
| `GET` | `/sales` | Get a list of sales | | ||
| `GET` | `/sales/{salesPerson}` | Get a list of sales associated with a sales person | | ||
|
||
4. Disconnect from the database using the `/disconnect` endpoint. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 25 additions & 20 deletions
45
java/company-web-server/src/main/java/io/github/company/Database.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,43 @@ | ||
package io.github.company; | ||
|
||
import java.util.List; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
// import io.github.mapapire.Pool; | ||
import io.github.mapapire.SqlJob; | ||
// import io.github.mapapire.PoolOptions; | ||
import io.github.mapapire.types.DaemonServer; | ||
import io.github.mapapire.types.QueryResult; | ||
import io.github.mapepire_ibmi.Pool; | ||
import io.github.mapepire_ibmi.types.DaemonServer; | ||
import io.github.mapepire_ibmi.types.PoolOptions; | ||
import io.github.mapepire_ibmi.types.QueryOptions; | ||
import io.github.mapepire_ibmi.types.QueryResult; | ||
import io.github.mapepire_ibmi.types.ServerTraceLevel; | ||
|
||
public class Database { | ||
// private static Pool pool; | ||
private static SqlJob job; | ||
private static Pool pool; | ||
|
||
public static void connect(String host, int port, String user, String password) throws Exception { | ||
DaemonServer creds = new DaemonServer(host, port, user, password, true, ""); | ||
// pool = new Pool(new PoolOptions(creds, 5, 1)); | ||
// pool.waitForJob().get(); | ||
// pool.init().get(); | ||
pool = new Pool(new PoolOptions(creds, 5, 1)); | ||
pool.waitForJob().get(); | ||
pool.init().get(); | ||
} | ||
|
||
public static boolean getReadyJob() { | ||
return pool.getReadyJob() != null; | ||
} | ||
|
||
job = new SqlJob(); | ||
job.connect(creds).get(); | ||
public static <T> CompletableFuture<QueryResult<T>> execute(String sql) throws Exception { | ||
return pool.execute(sql); | ||
} | ||
|
||
public static boolean isConnected() { | ||
return job != null; | ||
public static <T> CompletableFuture<QueryResult<T>> prepareAndExecute(String sql, List<Object> parameters) | ||
throws Exception { | ||
return pool.execute(sql, new QueryOptions(false, false, parameters)); | ||
} | ||
|
||
public static <T> CompletableFuture<QueryResult<T>> query(String sql) throws Exception { | ||
// return pool.execute(sql); | ||
return job.execute(sql); | ||
public static void setTraceLevel(ServerTraceLevel level) throws Exception { | ||
pool.getReadyJob().setTraceLevel(level).get(); | ||
} | ||
|
||
public static void disconnect() { | ||
// pool.end(); | ||
job.close(); | ||
pool.end(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
java/company-web-server/src/main/java/io/github/company/servlets/TracingServlet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package io.github.company.servlets; | ||
|
||
import java.io.IOException; | ||
|
||
import javax.servlet.http.HttpServlet; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.node.ObjectNode; | ||
|
||
import io.github.company.Database; | ||
import io.github.mapepire_ibmi.types.ServerTraceLevel; | ||
|
||
public class TracingServlet extends HttpServlet { | ||
private static final ObjectMapper objectMapper = new ObjectMapper(); | ||
|
||
@Override | ||
protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws IOException { | ||
resp.setContentType("application/json"); | ||
resp.setCharacterEncoding("UTF-8"); | ||
ObjectNode jsonResponse = objectMapper.createObjectNode(); | ||
|
||
try { | ||
String level = req.getParameter("level"); | ||
Database.setTraceLevel(ServerTraceLevel.fromValue(level)); | ||
|
||
resp.setStatus(HttpServletResponse.SC_OK); | ||
jsonResponse.put("message", "Successfully set server trace level."); | ||
} catch (Exception e) { | ||
resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); | ||
jsonResponse.put("error", "Internal server error. Reason: " + e.toString()); | ||
} | ||
|
||
resp.getWriter().write(objectMapper.writeValueAsString(jsonResponse)); | ||
} | ||
} |
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.