I'm trying to create an MVC app using Java EE MVC API implementation - Ozark. I'm using Grizzly as embedded web server. Of course, with Ozark is a JAX-RS implementaion - Jersey.
This is my server class with run method being invoked by main method:
public class GrizzlyServer {
private static final Logger LOGGER = LoggerFactory.getLogger(GrizzlyServer.class);
private static final String APP_NAME = "Hello World";
private static URI baseUri;
private static final String PROTOCOL = "http://";
private static final String HOST = "localhost";
private static final String PATH = "app/";
private static final int DEFAULT_PORT = 8080;
private GrizzlyServer() {
}
private static int port(String[] args) {
if (args.length > 0) {
String port = args[0];
try {
return Integer.valueOf(port);
} catch (NumberFormatException exception) {
LOGGER.error("Invalid port number {}", port);
LOGGER.error("Default port number {} will be used", DEFAULT_PORT);
}
}
return DEFAULT_PORT;
}
public static HttpServer startServer(int port) {
final ResourceConfig rc = new ApplicationResourceConfig();
baseUri = UriBuilder.fromUri(PROTOCOL + HOST).port(port).path(PATH).build();
HttpServer httpServer = GrizzlyHttpServerFactory.createHttpServer(baseUri, rc);
return httpServer;
}
public static void run(String[] args) throws IOException {
int port = port(args);
try {
final HttpServer server = startServer(port);
LOGGER.info("{} started with WADL available at {}application.wadl", APP_NAME, baseUri);
LOGGER.info("Hit Enter to stop it...");
System.in.read();
server.shutdown();
} catch (IOException exception) {
LOGGER.error("{}", exception.getMessage());
LOGGER.error("Exit...");
System.exit(1);
}
}
}
This is my controller:
@Controller
@Path("hello-world")
public class HelloWorldController {
@GET
public String index() {
return "/WEB-INF/index.jsp";
}
}
My app structure looks like this:
java
resources
web
..WEB-INF
..index.jsp
If I run my app and open my browser, http://localhost:8080/app/hello-world, it displays the return string od my method index instead the contents of index.jsp:
/WEB-INF/index.jsp
These are the relevant dependencies (Jersey version: 2.26):
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-grizzly2-http</artifactId>
</dependency>
<!-- Dependency Injection -->
<dependency>
<groupId>org.glassfish.hk2</groupId>
<artifactId>hk2-api</artifactId>
<version>2.5.0-b50</version>
<exclusions>
<exclusion>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
</dependency>
<!-- MVC -->
<dependency>
<groupId>org.glassfish.ozark</groupId>
<artifactId>ozark</artifactId>
<version>1.0.0-m02</version>
</dependency>
Any help will be highly appreciated. Thanks...
You should define a class registering the jax-rs application with @ApplicationPath.