Skip to content

Commit a5c0a77

Browse files
committed
Minor changes and embedded driver
1 parent 49e355d commit a5c0a77

File tree

8 files changed

+280
-907
lines changed

8 files changed

+280
-907
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,3 +362,4 @@ jdk_8_maven/em/external/rest/spring-batch-rest/target
362362
/jdk_21_maven/em/external/rest-gui/webgoat/target
363363

364364
/jdk_8_maven/cs/rest/original/swagger-petstore/target
365+
/jdk_8_maven/em/embedded/rest/swagger-petstore/target

jdk_8_maven/cs/rest/original/swagger-petstore/inflector.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
controllerPackage: io.swagger.petstore.controller
22
modelPackage: io.swagger.petstore.model
3-
swaggerUrl: openapi.yaml
3+
swaggerUrl: webapp/openapi.yaml
44

55
exposedSpecOptions:
66
useOriginalNotParsed: true

jdk_8_maven/cs/rest/original/swagger-petstore/pom.xml

Lines changed: 79 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,25 @@
3939
<defaultGoal>install</defaultGoal>
4040
<directory>target</directory>
4141
<finalName>${project.artifactId}-sut</finalName>
42+
<!-- MODIFIED-->
43+
<resources>
44+
<resource>
45+
<directory>src/main/webapp</directory>
46+
<targetPath>webapp</targetPath>
47+
<includes>
48+
<include>**/*</include>
49+
</includes>
50+
</resource>
51+
<resource>
52+
<directory>${project.basedir}</directory>
53+
<includes>
54+
<include>webapp/openapi.yaml</include>
55+
<include>inflector.yaml</include>
56+
</includes>
57+
</resource>
58+
</resources>
59+
<!-- MODIFIED-->
60+
4261
<plugins>
4362
<!-- MODIFIED-->
4463
<plugin>
@@ -97,29 +116,29 @@
97116
</execution>
98117
</executions>
99118
</plugin>
100-
<plugin>
101-
<artifactId>maven-dependency-plugin</artifactId>
102-
<executions>
103-
<execution>
104-
<phase>package</phase>
105-
<goals>
106-
<goal>copy-dependencies</goal>
107-
<goal>copy</goal>
108-
</goals>
109-
<configuration>
110-
<outputDirectory>${project.build.directory}/lib</outputDirectory>
111-
<artifactItems>
112-
<artifactItem>
113-
<groupId>org.eclipse.jetty</groupId>
114-
<artifactId>jetty-runner</artifactId>
115-
<version>${jetty-version}</version>
116-
<destFileName>jetty-runner.jar</destFileName>
117-
</artifactItem>
118-
</artifactItems>
119-
</configuration>
120-
</execution>
121-
</executions>
122-
</plugin>
119+
<!-- <plugin>-->
120+
<!-- <artifactId>maven-dependency-plugin</artifactId>-->
121+
<!-- <executions>-->
122+
<!-- <execution>-->
123+
<!-- <phase>package</phase>-->
124+
<!-- <goals>-->
125+
<!-- <goal>copy-dependencies</goal>-->
126+
<!-- <goal>copy</goal>-->
127+
<!-- </goals>-->
128+
<!-- <configuration>-->
129+
<!-- <outputDirectory>${project.build.directory}/lib</outputDirectory>-->
130+
<!-- <artifactItems>-->
131+
<!-- <artifactItem>-->
132+
<!-- <groupId>org.eclipse.jetty</groupId>-->
133+
<!-- <artifactId>jetty-runner</artifactId>-->
134+
<!-- <version>${jetty-version}</version>-->
135+
<!-- <destFileName>jetty-runner.jar</destFileName>-->
136+
<!-- </artifactItem>-->
137+
<!-- </artifactItems>-->
138+
<!-- </configuration>-->
139+
<!-- </execution>-->
140+
<!-- </executions>-->
141+
<!-- </plugin>-->
123142
<plugin>
124143
<groupId>org.apache.maven.plugins</groupId>
125144
<artifactId>maven-jar-plugin</artifactId>
@@ -138,26 +157,27 @@
138157
</archive>
139158
</configuration>
140159
</plugin>
141-
<plugin>
142-
<groupId>org.eclipse.jetty</groupId>
143-
<artifactId>jetty-maven-plugin</artifactId>
144-
<version>${jetty-version}</version>
145-
<configuration>
146-
<monitoredDirName>.</monitoredDirName>
147-
<scanTargets>
148-
<scanTarget>inflector.yaml</scanTarget>
149-
</scanTargets>
150-
<scanIntervalSeconds>1</scanIntervalSeconds>
151-
<webApp>
152-
<contextPath>/</contextPath>
153-
</webApp>
154-
<webAppSourceDirectory>target/${project.artifactId}-${project.version}</webAppSourceDirectory>
155-
<httpConnector>
156-
<port>8080</port>
157-
<idleTimeout>60000</idleTimeout>
158-
</httpConnector>
159-
</configuration>
160-
</plugin>
160+
<!-- MODIFIED-->
161+
<!-- <plugin>-->
162+
<!-- <groupId>org.eclipse.jetty</groupId>-->
163+
<!-- <artifactId>jetty-maven-plugin</artifactId>-->
164+
<!-- <version>${jetty-version}</version>-->
165+
<!-- <configuration>-->
166+
<!-- <monitoredDirName>.</monitoredDirName>-->
167+
<!-- <scanTargets>-->
168+
<!-- <scanTarget>inflector.yaml</scanTarget>-->
169+
<!-- </scanTargets>-->
170+
<!-- <scanIntervalSeconds>1</scanIntervalSeconds>-->
171+
<!-- <webApp>-->
172+
<!-- <contextPath>/</contextPath>-->
173+
<!-- </webApp>-->
174+
<!-- <webAppSourceDirectory>target/${project.artifactId}-${project.version}</webAppSourceDirectory>-->
175+
<!-- <httpConnector>-->
176+
<!-- <port>8080</port>-->
177+
<!-- <idleTimeout>60000</idleTimeout>-->
178+
<!-- </httpConnector>-->
179+
<!-- </configuration>-->
180+
<!-- </plugin>-->
161181
<plugin>
162182
<groupId>com.googlecode.maven-download-plugin</groupId>
163183
<artifactId>download-maven-plugin</artifactId>
@@ -266,22 +286,23 @@
266286
<artifactId>swagger-parser</artifactId>
267287
<version>${swagger-parser-version}</version>
268288
</dependency>
289+
<!--MODIFIED-->
269290

270-
<dependency>
271-
<groupId>javax.xml.bind</groupId>
272-
<artifactId>jaxb-api</artifactId>
273-
<version>2.3.1</version>
274-
</dependency>
275-
<dependency>
276-
<groupId>com.sun.xml.bind</groupId>
277-
<artifactId>jaxb-core</artifactId>
278-
<version>2.3.0.1</version>
279-
</dependency>
280-
<dependency>
281-
<groupId>com.sun.xml.bind</groupId>
282-
<artifactId>jaxb-impl</artifactId>
283-
<version>2.3.1</version>
284-
</dependency>
291+
<!-- <dependency>-->
292+
<!-- <groupId>javax.xml.bind</groupId>-->
293+
<!-- <artifactId>jaxb-api</artifactId>-->
294+
<!-- <version>2.3.1</version>-->
295+
<!-- </dependency>-->
296+
<!-- <dependency>-->
297+
<!-- <groupId>com.sun.xml.bind</groupId>-->
298+
<!-- <artifactId>jaxb-core</artifactId>-->
299+
<!-- <version>2.3.0.1</version>-->
300+
<!-- </dependency>-->
301+
<!-- <dependency>-->
302+
<!-- <groupId>com.sun.xml.bind</groupId>-->
303+
<!-- <artifactId>jaxb-impl</artifactId>-->
304+
<!-- <version>2.3.1</version>-->
305+
<!-- </dependency>-->
285306
<dependency>
286307
<groupId>com.bugsnag</groupId>
287308
<version>[3.0,4.0)</version>

jdk_8_maven/cs/rest/original/swagger-petstore/src/main/java/io/swagger/petstore/Main.java

Lines changed: 58 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,64 @@
55
import org.apache.catalina.startup.Tomcat;
66

77
import java.io.File;
8+
import java.net.URL;
9+
import java.nio.file.Files;
810

911
public class Main {
12+
Tomcat tomcat;
13+
14+
public void startServer(int port) throws Exception {
15+
tomcat = new Tomcat();
16+
tomcat.setPort(port);
17+
tomcat.getConnector();
18+
URL webappUrl = Main.class.getClassLoader().getResource("webapp");
19+
20+
String webappDirLocation;
21+
22+
// Handle the case where the webapp is inside a JAR
23+
if (webappUrl.getProtocol().equals("jar")) {
24+
// Extract the JAR file path and the entry path
25+
String jarPath = webappUrl.getPath().substring(5, webappUrl.getPath().indexOf("!"));
26+
String entryPath = webappUrl.getPath().substring(webappUrl.getPath().indexOf("!") + 2);
27+
28+
// Create a temporary directory to extract the webapp resources
29+
File tempDir = Files.createTempDirectory("webapp").toFile();
30+
tempDir.deleteOnExit();
31+
32+
// Extract the JAR entry to the temporary directory
33+
try (java.util.jar.JarFile jar = new java.util.jar.JarFile(new File(jarPath))) {
34+
java.util.Enumeration<java.util.jar.JarEntry> entries = jar.entries();
35+
while (entries.hasMoreElements()) {
36+
java.util.jar.JarEntry entry = entries.nextElement();
37+
if (entry.getName().startsWith(entryPath) && !entry.isDirectory()) {
38+
File file = new File(tempDir, entry.getName().substring(entryPath.length()));
39+
file.getParentFile().mkdirs();
40+
try (java.io.InputStream is = jar.getInputStream(entry);
41+
java.io.FileOutputStream fos = new java.io.FileOutputStream(file)) {
42+
while (is.available() > 0) {
43+
fos.write(is.read());
44+
}
45+
}
46+
}
47+
}
48+
}
49+
50+
webappDirLocation = tempDir.getAbsolutePath();
51+
} else {
52+
// Handle the case where the webapp is in the filesystem
53+
webappDirLocation = new File(webappUrl.toURI()).getAbsolutePath();
54+
}
55+
tomcat.addWebapp("", new File(webappDirLocation).getAbsolutePath());
56+
57+
System.out.println("Swagger Petstore running at http://localhost:" + port);
58+
tomcat.start();
59+
}
60+
61+
public Tomcat getTomcat() {
62+
return tomcat;
63+
}
64+
65+
1066
public static void main(String[] args) throws Exception {
1167
int port = 8080;
1268

@@ -18,15 +74,8 @@ public static void main(String[] args) throws Exception {
1874
}
1975
}
2076

21-
Tomcat tomcat = new Tomcat();
22-
tomcat.setPort(port);
23-
tomcat.getConnector();
24-
25-
String webappDirLocation = "src/main/webapp";
26-
tomcat.addWebapp("", new File(webappDirLocation).getAbsolutePath());
77+
Main app = new Main();
78+
app.startServer(port);
2779

28-
System.out.println("Swagger Petstore running at http://localhost:" + port);
29-
tomcat.start();
30-
tomcat.getServer().await();
3180
}
3281
}

0 commit comments

Comments
 (0)