File tree Expand file tree Collapse file tree 3 files changed +92
-0
lines changed
src/main/java/com/tutorialworks/simplehttp Expand file tree Collapse file tree 3 files changed +92
-0
lines changed Original file line number Diff line number Diff line change 1+ target /
2+ .idea /
3+ * .iml
Original file line number Diff line number Diff line change 1+ <?xml version =" 1.0" encoding =" UTF-8" ?>
2+ <project xmlns =" http://maven.apache.org/POM/4.0.0"
3+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
4+ xsi : schemaLocation =" http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" >
5+ <modelVersion >4.0.0</modelVersion >
6+
7+ <groupId >org.example</groupId >
8+ <artifactId >java-http-server-undertow</artifactId >
9+ <version >1.0-SNAPSHOT</version >
10+
11+ <properties >
12+ <project .build.sourceEncoding>UTF-8</project .build.sourceEncoding>
13+ <maven .compiler.source>11</maven .compiler.source>
14+ <maven .compiler.target>11</maven .compiler.target>
15+ </properties >
16+
17+ <dependencies >
18+ <dependency >
19+ <groupId >io.undertow</groupId >
20+ <artifactId >undertow-core</artifactId >
21+ <version >2.2.17.Final</version >
22+ </dependency >
23+ </dependencies >
24+
25+ <build >
26+ <plugins >
27+ <plugin >
28+ <groupId >org.apache.maven.plugins</groupId >
29+ <artifactId >maven-assembly-plugin</artifactId >
30+ <executions >
31+ <execution >
32+ <phase >package</phase >
33+ <goals >
34+ <goal >single</goal >
35+ </goals >
36+ <configuration >
37+ <archive >
38+ <manifest >
39+ <mainClass >com.tutorialworks.simplehttp.Application</mainClass >
40+ </manifest >
41+ </archive >
42+ <descriptorRefs >
43+ <descriptorRef >jar-with-dependencies</descriptorRef >
44+ </descriptorRefs >
45+ </configuration >
46+ </execution >
47+ </executions >
48+ </plugin >
49+ </plugins >
50+ </build >
51+
52+
53+
54+ </project >
Original file line number Diff line number Diff line change 1+ package com .tutorialworks .simplehttp ;
2+
3+ import io .undertow .Undertow ;
4+ import io .undertow .util .Headers ;
5+
6+ /**
7+ * Hello world!
8+ * Returns a simple web page on port 8080.
9+ */
10+ public class Application {
11+
12+ public static void main (String [] args ) {
13+ Undertow server = Undertow .builder ()
14+ // Set up the listener - you can change the port/host here
15+ // 0.0.0.0 means "listen on ALL available addresses"
16+ .addHttpListener (8080 , "0.0.0.0" )
17+
18+ .setHandler (exchange -> {
19+ // Sets the return Content-Type to text/html
20+ exchange .getResponseHeaders ()
21+ .put (Headers .CONTENT_TYPE , "text/html" );
22+
23+ // Returns a hard-coded HTML document
24+ exchange .getResponseSender ()
25+ .send ("<html>" +
26+ "<body>" +
27+ "<h1>Hello, world!</h1>" +
28+ "</body>" +
29+ "</html>" );
30+ }).build ();
31+
32+ // Boot the web server
33+ server .start ();
34+ }
35+ }
You can’t perform that action at this time.
0 commit comments