0

I am starting to use JAXRS to build a small application. I started with just a simple API that returns a hello world string on an API GET /api/hello. Here is my progress but I can't seem to let it recognize my API path.

Here is my project structure:

. ├── AWSCLIV2.pkg ├── Dockerfile ├── README.md ├── pom.xml └── src └── main ├── java │   └── com │   └── adsjwo │   ├── RestApplication.java │   └── models │   └── resources │   └── HelloResource.java ├── resources └── webapp ├── WEB-INF │   └── web.xml └── index.jsp 11 directories, 8 files 

RestApplication.java

@ApplicationPath("/api") public class RestApplication extends ResourceConfig { public RestApplication() { packages("com.adsjwo"); } } 

HelloResource.java

@Path("/hello") public class HelloResource { @GET @Produces(MediaType.TEXT_PLAIN) public String sayHello() { return "Hello from JAX-RS in Docker!"; } } 

web.xml

<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0"> <servlet-mapping> <servlet-name>Jersey REST Service</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping> </web-app> 

pom.xml

<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/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.adsjwo</groupId> <artifactId>jaxrs-docker</artifactId> <packaging>war</packaging> <version>1.0-SNAPSHOT</version> <name>jaxrs-docker Maven Webapp</name> <url>http://maven.apache.org</url> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> <!-- Jersey Core --> <dependency> <groupId>org.glassfish.jersey.containers</groupId> <artifactId>jersey-container-servlet</artifactId> <version>3.0.2</version> </dependency> <dependency> <groupId>org.glassfish.jersey.inject</groupId> <artifactId>jersey-hk2</artifactId> <version>3.0.2</version> </dependency> <dependency> <groupId>javax.ws.rs</groupId> <artifactId>javax.ws.rs-api</artifactId> <version>2.1.1</version> </dependency> <dependency> <groupId>com.sun.jersey</groupId> <artifactId>jersey-server</artifactId> <version>1.19.4</version> </dependency> </dependencies> <build> <finalName>jaxrs-docker</finalName> </build> </project> 

Dockerfile

# Use Tomcat as base image FROM tomcat:9.0 # Copy WAR file to Tomcat webapps directory COPY target/jaxrs-docker.war /usr/local/tomcat/webapps/ # Expose port 8080 EXPOSE 8080 # Start Tomcat CMD ["catalina.sh", "run"] 

After I run it in a docker and exposed 8080 port. None of the following curl requests yield the expected "Hello from JAX-RS in Docker!" or index.jsp.

curl http://localhost:8080/ curl http://localhost:8080/webapp/jaxrs-docker curl http://localhost:8080/jaxrs-docker curl http://localhost:8080/api/hello curl http://localhost:8080/jaxrs-docker/api/hello 

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.