initial commit with apps from course repo
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
package com.redhat.training.openshift.hello;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
|
||||
@Path("/")
|
||||
public class HelloResource {
|
||||
|
||||
@GET
|
||||
@Path("/hello")
|
||||
@Produces("text/plain")
|
||||
public String hello() {
|
||||
String hostname = System.getenv().getOrDefault("HOSTNAME", "unknown");
|
||||
String message = System.getenv().getOrDefault("APP_MSG", null);
|
||||
String response = "";
|
||||
if (message == null)
|
||||
response = "Hello world from host "+hostname+"\n";
|
||||
else
|
||||
response = "Hello world from host ["+hostname+"]. Message received = "+message+"\n";
|
||||
return response;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.redhat.training.openshift.hello;
|
||||
|
||||
import javax.ws.rs.ApplicationPath;
|
||||
import javax.ws.rs.core.Application;
|
||||
|
||||
@ApplicationPath("/api")
|
||||
public class JaxRsActivator extends Application {
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.redhat.training.openshift.hello;
|
||||
|
||||
import org.jboss.shrinkwrap.api.ShrinkWrap;
|
||||
import org.jboss.shrinkwrap.api.asset.ClassLoaderAsset;
|
||||
import org.wildfly.swarm.Swarm;
|
||||
import org.wildfly.swarm.undertow.WARArchive;
|
||||
|
||||
public class Main {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
// Instantiate the container
|
||||
Swarm swarm = new Swarm(args);
|
||||
|
||||
// Create one or more deployments
|
||||
WARArchive deployment = ShrinkWrap.create(WARArchive.class);
|
||||
|
||||
// Add resource to deployment
|
||||
deployment.addPackage(Main.class.getPackage());
|
||||
deployment.addAllDependencies();
|
||||
|
||||
// Add Web resources
|
||||
deployment.addAsWebInfResource(
|
||||
new ClassLoaderAsset("WEB-INF/web.xml", Main.class.getClassLoader()), "web.xml");
|
||||
deployment.addAsWebInfResource(
|
||||
new ClassLoaderAsset("WEB-INF/beans.xml", Main.class.getClassLoader()), "beans.xml");
|
||||
|
||||
swarm.start().deploy(deployment);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
5
hello-swarm/app-src/src/main/resources/WEB-INF/beans.xml
Normal file
5
hello-swarm/app-src/src/main/resources/WEB-INF/beans.xml
Normal file
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
|
||||
http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd" bean-discovery-mode="all">
|
||||
</beans>
|
||||
6
hello-swarm/app-src/src/main/resources/WEB-INF/web.xml
Normal file
6
hello-swarm/app-src/src/main/resources/WEB-INF/web.xml
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
|
||||
|
||||
</web-app>
|
||||
Reference in New Issue
Block a user