Skip to content

Commit

Permalink
updated pom.xml, adding system.properties, and html files/resources
Browse files Browse the repository at this point in the history
  • Loading branch information
nestrada2 committed Feb 12, 2024
1 parent c67f9e6 commit 422b94c
Show file tree
Hide file tree
Showing 18 changed files with 403 additions and 81 deletions.
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: java $JAVA_OPTS -jar target/dependency/jetty-runner.jar --port $PORT target/*.jar
26 changes: 21 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
<!-- assumes SearchEngine and SearchEngineTest are in the same directory -->
<sourceDirectory>src/main/java</sourceDirectory>
<testSourceDirectory>../project-tests/src/test/java</testSourceDirectory>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
<!-- <resources>-->
<!-- <resource>-->
<!-- <directory>src/main/resources</directory>-->
<!-- </resource>-->
<!-- </resources>-->

<plugins>
<plugin>
Expand Down Expand Up @@ -63,6 +63,12 @@
<version>3.0.0-M7</version>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.3.1</version>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
Expand All @@ -84,6 +90,16 @@
</execution>
</executions>
</plugin>

<plugin>
<groupId>com.heroku.sdk</groupId>
<artifactId>heroku-maven-plugin</artifactId>
<version>3.0.7</version>

<configuration>
<appName>rooster-search</appName>
</configuration>
</plugin>
</plugins>
</build>

Expand Down
42 changes: 14 additions & 28 deletions src/main/java/edu/usfca/cs272/SearchEngineServer.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
package edu.usfca.cs272;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Set;

import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.apache.commons.text.StringEscapeUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletHandler;

import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Set;

/**
* A simple example of using Jetty and servlets to use an HTML form.
Expand Down Expand Up @@ -97,7 +95,7 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response)
log.info(request);

// String html = fileToString("/../../../../resources/getSearch.html");
String html = fileToString("getSearch.html");
String html = fileToString("/getSearch.html");

processingQueryData(request, response, html);
}
Expand All @@ -119,7 +117,7 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response)
log.info(request);

// String html = fileToString("../../../../resources/doGet.html");
String html = fileToString("resources/doGet.html");
String html = fileToString("/doGet.html");

// Send the Response Object back to the User
PrintWriter out = response.getWriter();
Expand All @@ -135,7 +133,7 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
log.info(request);

// String html = fileToString("../../../../resources/doPost.html");
String html = fileToString("resources/doPost.html");
String html = fileToString("/doPost.html");

processingQueryData(request, response, html);
}
Expand Down Expand Up @@ -240,20 +238,8 @@ public static void processingQueryData(HttpServletRequest request, HttpServletRe
public static String fileToString(String fileName)
{
String content = "";
try (BufferedReader reader = new BufferedReader(new FileReader(fileName))) {
StringBuilder stringBuilder = new StringBuilder();
String line = null;
String ls = System.getProperty("line.separator");
while ((line = reader.readLine()) != null) {
stringBuilder.append(line);
stringBuilder.append(ls);
}
// delete the last new line separator
stringBuilder.deleteCharAt(stringBuilder.length() - 1);
reader.close();

content = stringBuilder.toString();
return content;
try (var in = SearchEngineServer.class.getResourceAsStream(fileName)) {
return new String(in.readAllBytes(), StandardCharsets.UTF_8);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Expand Down
23 changes: 23 additions & 0 deletions src/main/resources/doGet.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="utf-8">
<title>%1$s</title>
</head>

<body>
<h1>%1$s</h1>

<form method="post" action="/post_search">
<p>
<input type="text" name="query" size="50"></input>
</p>

<p>
<button>Search</button>
</p>
</form>

</body>
</html>
19 changes: 19 additions & 0 deletions src/main/resources/doPost.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="utf-8">
<title>%1$s</title>
</head>

<body>
<h1>%1$s</h1>

<pre>
%2$s
</pre>

<p>(<a href="/post_search">back to form</a>)</p>

</body>
</html>
Loading

0 comments on commit 422b94c

Please sign in to comment.