Skip to content

Commit 4893bdc

Browse files
authored
Add support for webservers that aren't Vertx (#2104)
1 parent e705793 commit 4893bdc

File tree

53 files changed

+1258
-1041
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1258
-1041
lines changed

.semgrepignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,4 @@ example/order/src/main/scala/org/finos/vuu/order/oms/impl/InMemOmsApi.scala
4343
example/virtualized-table/src/main/scala/org/finos/vuu/example/virtualtable/bigdatacache/FakeBigDataCache.scala
4444
example/apache-ignite/src/main/resources/certs/key.pem
4545
example/apache-ignite/src/main/resources/certs/cert.pem
46+
example/http2-server/src/test/resources/certs/key.pem

example/apache-ignite/src/main/scala/org/finos/vuu/example/ignite/IgniteVuuMain.scala

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@ import org.finos.vuu.core.module.TableDefContainer
1111
import org.finos.vuu.core.module.metrics.MetricsModule
1212
import org.finos.vuu.example.ignite.loader.IgniteOrderGenerator
1313
import org.finos.vuu.example.ignite.module.IgniteOrderDataModule
14-
import org.finos.vuu.net.auth.{Authenticator, LoginTokenService}
15-
import org.finos.vuu.net.http.{AbsolutePathWebRoot, VuuHttp2ServerOptions}
14+
import org.finos.vuu.net.auth.LoginTokenService
1615
import org.finos.vuu.plugin.virtualized.VirtualizedTablePlugin
17-
import org.finos.vuu.state.MemoryBackedVuiStateStore
1816

1917
/*
2018
//to allow self signed certs
@@ -33,10 +31,6 @@ object IgniteVuuMain extends App with StrictLogging {
3331
logger.info("[VUU] Starting...")
3432
val runAsIgniteServer = false
3533

36-
val store = new MemoryBackedVuiStateStore()
37-
38-
//store.add(VuiState(VuiHeader("chris", "latest", "chris.latest", clock.now()), VuiJsonState("{ uiState : ['chris','foo'] }")))
39-
4034
lifecycle.autoShutdownHook()
4135

4236
val loginTokenService = LoginTokenService.apply(VuuUser("test"))
@@ -54,11 +48,6 @@ object IgniteVuuMain extends App with StrictLogging {
5448
SaveOrdersInIgnite()
5549

5650
val config = VuuServerConfig(
57-
VuuHttp2ServerOptions()
58-
.withWebRoot(AbsolutePathWebRoot(webRoot, directoryListings = true))
59-
.withSsl(VuuSSLByCertAndKey(certPath, keyPath))
60-
.withBindAddress("0.0.0.0")
61-
.withPort(8443),
6251
VuuWebSocketOptions()
6352
.withUri("websocket")
6453
.withWsPort(8090)

example/http2-server/pom.xml

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<parent>
6+
<groupId>org.finos.vuu</groupId>
7+
<artifactId>example</artifactId>
8+
<version>1.1.0-SNAPSHOT</version>
9+
</parent>
10+
11+
<artifactId>http2-server</artifactId>
12+
<name>${project.artifactId}</name>
13+
14+
<dependencies>
15+
<dependency>
16+
<groupId>org.finos.vuu</groupId>
17+
<artifactId>vuu</artifactId>
18+
<version>1.1.0-SNAPSHOT</version>
19+
</dependency>
20+
21+
<dependency>
22+
<groupId>org.scala-lang</groupId>
23+
<artifactId>scala3-library_3</artifactId>
24+
<version>${scala.version}</version>
25+
</dependency>
26+
27+
<dependency>
28+
<groupId>io.vertx</groupId>
29+
<artifactId>vertx-core</artifactId>
30+
<version>${vertx.version}</version>
31+
</dependency>
32+
33+
<dependency>
34+
<groupId>io.vertx</groupId>
35+
<artifactId>vertx-web</artifactId>
36+
<version>${vertx.version}</version>
37+
</dependency>
38+
39+
<dependency>
40+
<groupId>io.vertx</groupId>
41+
<artifactId>vertx-web-client</artifactId>
42+
<version>${vertx.version}</version>
43+
<scope>test</scope>
44+
</dependency>
45+
46+
<dependency>
47+
<groupId>ch.qos.logback</groupId>
48+
<artifactId>logback-classic</artifactId>
49+
<version>${logback.version}</version>
50+
<scope>test</scope>
51+
</dependency>
52+
53+
<dependency>
54+
<groupId>org.scalatest</groupId>
55+
<artifactId>scalatest_3</artifactId>
56+
<version>${scalatest.version}</version>
57+
<scope>test</scope>
58+
<exclusions>
59+
<exclusion>
60+
<groupId>org.scala-lang</groupId>
61+
<artifactId>scala3-library_3</artifactId>
62+
</exclusion>
63+
</exclusions>
64+
</dependency>
65+
66+
<dependency>
67+
<groupId>org.scalamock</groupId>
68+
<artifactId>scalamock_3</artifactId>
69+
<version>${scalamock.version}</version>
70+
<scope>test</scope>
71+
<exclusions>
72+
<exclusion>
73+
<groupId>org.scala-lang</groupId>
74+
<artifactId>scala3-library_3</artifactId>
75+
</exclusion>
76+
</exclusions>
77+
</dependency>
78+
79+
</dependencies>
80+
81+
<build>
82+
<sourceDirectory>src/main/java</sourceDirectory>
83+
<testSourceDirectory>src/test/java</testSourceDirectory>
84+
85+
<plugins>
86+
87+
<plugin>
88+
<groupId>org.apache.maven.plugins</groupId>
89+
<artifactId>maven-source-plugin</artifactId>
90+
<executions>
91+
<execution>
92+
<phase>compile</phase>
93+
<goals><goal>jar</goal></goals>
94+
</execution>
95+
</executions>
96+
</plugin>
97+
98+
<plugin>
99+
<groupId>org.apache.maven.plugins</groupId>
100+
<artifactId>maven-release-plugin</artifactId>
101+
</plugin>
102+
103+
<plugin>
104+
<groupId>org.apache.maven.plugins</groupId>
105+
<artifactId>maven-javadoc-plugin</artifactId>
106+
<executions>
107+
<execution>
108+
<id>attach-javadocs</id>
109+
<goals>
110+
<goal>jar</goal>
111+
</goals>
112+
</execution>
113+
</executions>
114+
</plugin>
115+
116+
<plugin>
117+
<groupId>net.alchim31.maven</groupId>
118+
<artifactId>scala-maven-plugin</artifactId>
119+
<executions>
120+
<execution>
121+
<goals>
122+
<goal>compile</goal>
123+
<goal>testCompile</goal>
124+
</goals>
125+
</execution>
126+
</executions>
127+
<configuration>
128+
<sourceDir>src/main/scala</sourceDir>
129+
<testSourceDir>src/test/scala</testSourceDir>
130+
<args>
131+
<arg>-deprecation</arg>
132+
</args>
133+
<jvmArgs>
134+
<jvmArg>-Xms64m</jvmArg>
135+
<jvmArg>-Xmx1024m</jvmArg>
136+
</jvmArgs>
137+
</configuration>
138+
</plugin>
139+
140+
<plugin>
141+
<groupId>org.apache.maven.plugins</groupId>
142+
<artifactId>maven-jar-plugin</artifactId>
143+
<executions>
144+
<execution>
145+
<goals>
146+
<goal>test-jar</goal>
147+
</goals>
148+
</execution>
149+
</executions>
150+
</plugin>
151+
152+
<!-- disable surefire -->
153+
<plugin>
154+
<groupId>org.apache.maven.plugins</groupId>
155+
<artifactId>maven-surefire-plugin</artifactId>
156+
<configuration>
157+
<!--skipTests>true</skipTests-->
158+
</configuration>
159+
</plugin>
160+
161+
<!-- enable scalatest -->
162+
<plugin>
163+
<groupId>org.scalatest</groupId>
164+
<artifactId>scalatest-maven-plugin</artifactId>
165+
<configuration>
166+
<reportsDirectory>${project.build.directory}/surefire-reports</reportsDirectory>
167+
<junitxml>.</junitxml>
168+
<filereports>test-reports.txt</filereports>
169+
</configuration>
170+
<executions>
171+
<execution>
172+
<id>test</id>
173+
<goals>
174+
<goal>test</goal>
175+
</goals>
176+
</execution>
177+
</executions>
178+
</plugin>
179+
180+
</plugins>
181+
</build>
182+
183+
</project>
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package org.finos.vuu.http2.server
2+
3+
import io.vertx.core.{Vertx, VertxOptions}
4+
import org.finos.vuu.http2.server.config.VuuHttp2ServerOptions
5+
import org.finos.vuu.http2.server.vertx.VertxHttp2Server
6+
import org.finos.vuu.net.http.HttpServer
7+
import org.finos.vuu.net.rest.RestService
8+
9+
trait Http2Server extends HttpServer {
10+
11+
def isRunning: Boolean
12+
13+
def getPort: Int
14+
15+
}
16+
17+
object Http2Server {
18+
19+
def apply(options: VuuHttp2ServerOptions): Http2Server = {
20+
Http2ServerImpl(options)
21+
}
22+
23+
def apply(options: VuuHttp2ServerOptions, services: List[RestService]): Http2Server = {
24+
Http2ServerImpl(options, services)
25+
}
26+
27+
}
28+
29+
private case class Http2ServerImpl(options: VuuHttp2ServerOptions = VuuHttp2ServerOptions(),
30+
services: List[RestService] = List.empty) extends Http2Server {
31+
32+
private final val vertxHttp2Server = new VertxHttp2Server(options, services)
33+
private val vertx = Vertx.vertx(new VertxOptions())
34+
35+
override def doStart(): Unit = {
36+
vertx.deployVerticle(vertxHttp2Server)
37+
.toCompletionStage
38+
.toCompletableFuture
39+
.get()
40+
}
41+
42+
override def doStop(): Unit = {
43+
vertx.close()
44+
}
45+
46+
override def doInitialize(): Unit = {
47+
//Nothing to do
48+
}
49+
50+
override def doDestroy(): Unit = {
51+
//Nothing to do
52+
}
53+
54+
override val lifecycleId: String = "Http2ServerImpl"
55+
56+
override def isRunning: Boolean = vertxHttp2Server.isRunning
57+
58+
override def getPort: Int = vertxHttp2Server.getPort
59+
60+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package org.finos.vuu.http2.server
2+
3+
import org.finos.vuu.http2.server.config.VuuHttp2ServerOptions
4+
import org.finos.vuu.net.http.{HttpServer, HttpServerFactory}
5+
import org.finos.vuu.net.rest.RestService
6+
7+
trait VuuHttp2ServerFactory extends HttpServerFactory
8+
9+
object VuuHttp2ServerFactory {
10+
11+
def apply() = VuuHttp2ServerFactoryImpl(VuuHttp2ServerOptions())
12+
13+
def apply(options: VuuHttp2ServerOptions) = VuuHttp2ServerFactoryImpl(options)
14+
15+
}
16+
17+
private case class VuuHttp2ServerFactoryImpl(options: VuuHttp2ServerOptions) extends HttpServerFactory {
18+
19+
override def create(services: List[RestService]): HttpServer = Http2Server(options, services)
20+
21+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package org.finos.vuu.http2.server.config
2+
3+
sealed trait HttpServerWebRootType
4+
5+
object WebRootDisabled extends HttpServerWebRootType
6+
7+
object ClassPathWebRoot extends HttpServerWebRootType
8+
9+
case class AbsolutePathWebRoot(path: String, directoryListings: Boolean = false) extends HttpServerWebRootType
10+
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package org.finos.vuu.http2.server.config
2+
3+
import org.finos.vuu.core.{VuuSSLDisabled, VuuSSLOptions}
4+
5+
trait VuuHttp2ServerOptions {
6+
7+
def sslOptions: VuuSSLOptions
8+
9+
def webRoot: HttpServerWebRootType
10+
11+
def port: Int
12+
13+
def withSslDisabled(): VuuHttp2ServerOptions
14+
15+
def withSsl(vuuSSLOptions: VuuSSLOptions): VuuHttp2ServerOptions
16+
17+
def withWebRoot(webRoot: HttpServerWebRootType): VuuHttp2ServerOptions
18+
19+
def withPort(port: Int): VuuHttp2ServerOptions
20+
21+
}
22+
23+
object VuuHttp2ServerOptions {
24+
def apply(): VuuHttp2ServerOptions = {
25+
VuuHttp2ServerOptionsImpl(port = 8080)
26+
}
27+
}
28+
29+
private case class VuuHttp2ServerOptionsImpl(sslOptions: VuuSSLOptions = VuuSSLDisabled,
30+
webRoot: HttpServerWebRootType = WebRootDisabled,
31+
port: Int) extends VuuHttp2ServerOptions {
32+
33+
def withPort(port: Int): VuuHttp2ServerOptions = {
34+
this.copy(port = port)
35+
}
36+
37+
override def withSslDisabled(): VuuHttp2ServerOptions = this.withSsl(VuuSSLDisabled)
38+
39+
def withSsl(sslOptions: VuuSSLOptions): VuuHttp2ServerOptions = {
40+
this.copy(sslOptions = sslOptions)
41+
}
42+
43+
def withWebRoot(webRoot: HttpServerWebRootType): VuuHttp2ServerOptions = {
44+
this.copy(webRoot = webRoot)
45+
}
46+
47+
}

0 commit comments

Comments
 (0)