-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a servletSpec setting to choose among runners
- Loading branch information
1 parent
3724a34
commit d97ffe0
Showing
72 changed files
with
1,949 additions
and
8 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
File renamed without changes.
File renamed without changes.
18 changes: 18 additions & 0 deletions
18
runners/3.0/src/main/java/com/earldouglas/WebappComponentsRunner.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,18 @@ | ||
package com.earldouglas; | ||
|
||
import java.io.IOException; | ||
|
||
/** Launches a webapp composed of in-place resources, classes, and libraries. */ | ||
public class WebappComponentsRunner { | ||
|
||
/** | ||
* Load configuration from the file in the first argument, and use it to start a new | ||
* WebappComponentsRunner. | ||
* | ||
* @param args the configuration filename to load and run | ||
* @throws IOException if something goes wrong | ||
*/ | ||
public static void main(final String[] args) throws IOException { | ||
throw new RuntimeException("unsupported"); | ||
} | ||
} |
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.
71 changes: 71 additions & 0 deletions
71
runners/3.1/src/main/java/com/earldouglas/WarConfiguration.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,71 @@ | ||
package com.earldouglas; | ||
|
||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.Properties; | ||
|
||
public class WarConfiguration { | ||
|
||
/** The port to use for the server, e.g. 8080 */ | ||
public final int port; | ||
|
||
/** The .war file to serve. */ | ||
public final File warFile; | ||
|
||
/** | ||
* Read configuration from a file at the specified location. | ||
* | ||
* @param configurationFilename the configuration filename to load | ||
* @throws IOException if something goes wrong | ||
* @return WarConfiguration a loaded configuration | ||
*/ | ||
public static WarConfiguration load(final String configurationFilename) throws IOException { | ||
return WarConfiguration.load(new File(configurationFilename)); | ||
} | ||
|
||
/** | ||
* Read configuration from a file at the specified location. | ||
* | ||
* <p>The format of the file is a Properties file with the following fields: | ||
* | ||
* <ul> | ||
* <li>port | ||
* <li>warFile | ||
* </ul> | ||
* | ||
* <p>Example: | ||
* | ||
* <pre> | ||
* port=8989 | ||
* warFile=path/to/warfile.war | ||
* </pre> | ||
* | ||
* @param configurationFile the configuration file to load | ||
* @throws IOException if something goes wrong | ||
* @return WarConfiguration a loaded configuration | ||
*/ | ||
public static WarConfiguration load(final File configurationFile) throws IOException { | ||
|
||
final InputStream inputStream = new FileInputStream(configurationFile); | ||
|
||
final Properties properties = new Properties(); | ||
properties.load(inputStream); | ||
|
||
return new WarConfiguration( | ||
Integer.parseInt(properties.getProperty("port")), | ||
new File(properties.getProperty("warFile"))); | ||
} | ||
|
||
/** | ||
* Construct a new configuration from the given parameters. | ||
* | ||
* @param port the port to use for the server, e.g. 8080 | ||
* @param warFile the .war file to serve | ||
*/ | ||
public WarConfiguration(final int port, final File warFile) { | ||
this.port = port; | ||
this.warFile = warFile; | ||
} | ||
} |
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,22 @@ | ||
package com.earldouglas; | ||
|
||
public class WarRunner { | ||
|
||
/** | ||
* Load configuration from the file in the first argument, and use it to start a new WarRunner. | ||
* | ||
* @param args the configuration filename to load and run | ||
* @throws Exception if something goes wrong | ||
*/ | ||
public static void main(final String[] args) throws Exception { | ||
|
||
final WarConfiguration warConfiguration = WarConfiguration.load(args[0]); | ||
|
||
final String[] warRunnerArgs = | ||
new String[] { | ||
"--port", Integer.toString(warConfiguration.port), warConfiguration.warFile.getPath(), | ||
}; | ||
|
||
webapp.runner.launch.Main.main(warRunnerArgs); | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
Empty file.
Empty file.
Empty file.
Empty file.
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 @@ | ||
<marquee>bar</marquee> |
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 @@ | ||
div.raz { font-weight: bold; } |
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 @@ | ||
<blink>foo</blink> |
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,2 @@ | ||
port=8988 | ||
warFile=src/test/fakeproject/src/main/webapp |
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 @@ | ||
hostname=localhost | ||
port=8989 | ||
contextPath= | ||
emptyWebappDir=target/empty | ||
emptyClassesDir=target/empty | ||
resourceMap=bar.html->src/test/fakeproject/src/main/webapp/bar.html,\ | ||
foo.html->src/test/fakeproject/src/main/webapp/foo.html,\ | ||
baz/raz.css->src/test/fakeproject/src/main/webapp/baz/raz.css |
64 changes: 64 additions & 0 deletions
64
runners/3.1/src/test/scala/com/earldouglas/HttpClient.scala
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,64 @@ | ||
package com.earldouglas | ||
|
||
import java.net.HttpURLConnection | ||
import java.net.URI | ||
import scala.collection.JavaConverters._ | ||
import scala.io.Source | ||
|
||
object HttpClient { | ||
|
||
case class Response( | ||
status: Int, | ||
headers: Map[String, String], | ||
body: String | ||
) | ||
|
||
def request( | ||
method: String, | ||
url: String, | ||
headers: Map[String, String], | ||
body: Option[String] | ||
): Response = { | ||
|
||
val c = | ||
new URI(url) | ||
.toURL() | ||
.openConnection() | ||
.asInstanceOf[HttpURLConnection] | ||
|
||
c.setInstanceFollowRedirects(false) | ||
c.setRequestMethod(method) | ||
c.setDoInput(true) | ||
c.setDoOutput(body.isDefined) | ||
|
||
headers foreach { case (k, v) => | ||
c.setRequestProperty(k, v) | ||
} | ||
|
||
body foreach { b => | ||
c.getOutputStream.write(b.getBytes("UTF-8")) | ||
} | ||
|
||
val response = | ||
Response( | ||
status = c.getResponseCode(), | ||
headers = c | ||
.getHeaderFields() | ||
.asScala | ||
.filter({ case (k, _) => k != null }) | ||
.map({ case (k, v) => (k, v.asScala.mkString(",")) }) | ||
.toMap - "Date" - "Content-Length" - "Server", | ||
body = Source.fromInputStream { | ||
if (c.getResponseCode() < 400) { | ||
c.getInputStream | ||
} else { | ||
c.getErrorStream | ||
} | ||
}.mkString | ||
) | ||
|
||
c.disconnect() | ||
|
||
response | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
runners/3.1/src/test/scala/com/earldouglas/WarConfigurationTest.scala
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,24 @@ | ||
package com.earldouglas | ||
|
||
import org.scalatest.BeforeAndAfterAll | ||
import org.scalatest.funsuite.AnyFunSuite | ||
import org.scalatest.matchers.should.Matchers | ||
|
||
import java.io.File | ||
|
||
class WarConfigurationTest | ||
extends AnyFunSuite | ||
with Matchers | ||
with BeforeAndAfterAll { | ||
|
||
test("load") { | ||
|
||
val configuration: WarConfiguration = | ||
WarConfiguration.load("src/test/resources/war.properties") | ||
|
||
configuration.port shouldBe 8988 | ||
|
||
configuration.warFile shouldBe | ||
new File("src/test/fakeproject/src/main/webapp") | ||
} | ||
} |
Oops, something went wrong.