Skip to content
Snippets Groups Projects
Commit 39f96795 authored by Tor-Einar Skog's avatar Tor-Einar Skog
Browse files

Added static welcome pages

parent 8e14a50f
Branches
No related tags found
No related merge requests found
package no.bioforsk.vips.coremanager.service;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
......@@ -14,6 +23,7 @@ import javax.ws.rs.WebApplicationException;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response;
import no.bioforsk.vips.core.service.ModelResource;
import no.bioforsk.vips.coremanager.session.ControllerGetter;
......@@ -23,6 +33,7 @@ import no.bioforsk.vips.coremanager.entity.VipsCoreUser;
import no.bioforsk.vips.entity.ModelConfiguration;
import no.bioforsk.vips.entity.Result;
import no.bioforsk.vips.model.Model;
import no.bioforsk.vips.util.ServletUtil;
import org.jboss.resteasy.client.jaxrs.ResteasyWebTarget;
......@@ -40,6 +51,15 @@ public class ManagerResourceImpl implements ManagerResource{
private final Integer VIPS_BATCH_SYSTEM_USER_ID = -10;
private InputStream getStaticFileAsInputStream(ServletContext servletContext, String filePath)
{
return servletContext.getResourceAsStream("/WEB-INF/" + filePath.replaceAll("\\.\\.", ""));
}
/**
*
* @return list of all models available, using default language (English)
......@@ -286,6 +306,68 @@ public class ManagerResourceImpl implements ManagerResource{
return resource;
}
/**
* Handle "index.html" requests
* @param request
* @return
*/
@GET
@Path("")
@Produces("text/html;charset=UTF-8")
public Response redirectToWelcome(@Context HttpServletRequest request)
{
try {
URI redirect = new URI("http://" + ServletUtil.getNormalizedServerNameAndPort(request) + ServletUtil.getContextPath(request) + "/statichtml/index.html");
return Response.seeOther(redirect).build();
} catch (URISyntaxException ex) {
Logger.getLogger(ManagerResourceImpl.class.getName()).log(Level.SEVERE, null, ex);
return Response.serverError().entity(ex).build();
}
}
/**
* Serve static HTML files. Place them in "WEB-INF/statichtml"
* @param servletContext
* @param fileName
* @return
*/
@GET
@Path("statichtml/{fileName}")
@Produces("text/html;charset=UTF-8")
public Response serveStaticHtml(@Context ServletContext servletContext,@PathParam("fileName") String fileName)
{
return Response.ok(this.getStaticFileAsInputStream(servletContext, "statichtml/" + fileName)).build();
}
/**
* Serve static image file. Place images in "WEB-INF/staticpng"
* @param servletContext
* @param fileName
* @return
*/
@GET
@Path("staticpng/{fileName}")
@Produces("image/png")
public Response serveStaticPng(@Context ServletContext servletContext, @PathParam("fileName") String fileName)
{
return Response.ok(this.getStaticFileAsInputStream(servletContext, "staticpng/" + fileName)).build();
}
/**
* Serve static CSS. Place css files in "WEB-INF/staticcss"
* @param servletContext
* @param fileName
* @return
*/
@GET
@Path("staticcss/{fileName}")
@Produces("text/css")
public Response serveStaticCss(@Context ServletContext servletContext, @PathParam("fileName") String fileName)
{
return Response.ok(this.getStaticFileAsInputStream(servletContext, "staticcss/" + fileName)).build();
}
}
/*
Document : stylesheet
Created on : Sep 25, 2013, 10:27:12 AM
Author : treinar
Description:
Purpose of the stylesheet follows.
*/
body{
font-family: sans-serif;
}
<!DOCTYPE html>
<html>
<head>
<title>VIPSCoreManager</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="../staticcss/stylesheet.css" rel="stylesheet" media="screen" />
</head>
<body>
<p><img src="../staticpng/logo_vips.png" alt="VIPS logo"/></p>
<h1>VIPSCoreManager</h1>
<p>
The VIPS Core Manager is a REST service for executing forecast models
for acricultural pests and diseases. It is being developed by
<a href="http://www.bioforsk.no/ikbViewer/page/en/home" target="new">Bioforsk</a>.
If you came here by accident, but still is interested in knowing more,
then we suggest you
<a href="http://www.bioforsk.no/ikbViewer/page/en/contact-us">contact us</a>
for information.
</p>
<h2>Usage instructions</h2>
<h3>Meta data resources</h3>
<p>
Translations exist for most resources (currently Norwegian only). Add
language code after the resource, e.g. "/nb". Default is always English.
</p>
<ul>
<li>[ServerName]/models: <a href="../models">List of models</a></li>
<li>Description of each model: [ServerName]/models/[MODELID]/description .
E.g: <a href="../models/NAERSTADMO/description">Description of Nærstad model</a>.
Or the same <a href="../models/NAERSTADMO/description/nb">description in Norwegian</a>.
</li>
<li>Usage instructions for each model: [ServerName]/models/[MODELID]/usage.
E.g: <a href="../models/NAERSTADMO/usage">Usage for Nærstad model</a>.
Or the same <a href="../models/NAERSTADMO/usage/nb">usage instructions in Norwegian</a>.
</li>
<li>Sample configuration for each model: [ServerName]/models/[MODELID]/sampleconfig .
E.g: <a href="../models/NAERSTADMO/sampleconfig">Sample configuration for Nærstad model</a>.
</li>
</ul>
<h3>Execute a model</h3>
<p>
The model expects a POST request to [SERVERNAME]/models/{modelId}/run.
The POST request must send the JSON (see sampleconfig for what to send),
and will in return receive results in JSON format back. See sample below.
</p>
<h4>Sample result from the Nærstad model</h4>
<pre>
[
{"resultValidTime":"2012-08-20T22:00:00.000+0000","keys":["RISK"],"allValues":{"RISK":"7.83"}},
{"resultValidTime":"2012-08-20T23:00:00.000+0000","keys":["RISK"],"allValues":{"RISK":"5.1"}},
{"resultValidTime":"2012-08-21T00:00:00.000+0000","keys":["RISK"],"allValues":{"RISK":"3.75"}},
{"resultValidTime":"2012-08-21T01:00:00.000+0000","keys":["RISK"],"allValues":{"RISK":"2.91"}},
{"resultValidTime":"2012-08-21T02:00:00.000+0000","keys":["RISK"],"allValues":{"RISK":"2.47"}},
{"resultValidTime":"2012-08-21T03:00:00.000+0000","keys":["RISK"],"allValues":{"RISK":"2.72"}},
{"resultValidTime":"2012-08-21T04:00:00.000+0000","keys":["RISK"],"allValues":{"RISK":"2.57"}},
{"resultValidTime":"2012-08-21T05:00:00.000+0000","keys":["RISK"],"allValues":{"RISK":"0"}},
{"resultValidTime":"2012-08-21T06:00:00.000+0000","keys":["RISK"],"allValues":{"RISK":"0"}},
{"resultValidTime":"2012-08-21T07:00:00.000+0000","keys":["RISK"],"allValues":{"RISK":"0"}},
{"resultValidTime":"2012-08-21T08:00:00.000+0000","keys":["RISK"],"allValues":{"RISK":"0"}},
{"resultValidTime":"2012-08-21T09:00:00.000+0000","keys":["RISK"],"allValues":{"RISK":"0"}},
{"resultValidTime":"2012-08-21T10:00:00.000+0000","keys":["RISK"],"allValues":{"RISK":"0"}},
{"resultValidTime":"2012-08-21T11:00:00.000+0000","keys":["RISK"],"allValues":{"RISK":"0"}},
{"resultValidTime":"2012-08-21T12:00:00.000+0000","keys":["RISK"],"allValues":{"RISK":"0"}},
{"resultValidTime":"2012-08-21T13:00:00.000+0000","keys":["RISK"],"allValues":{"RISK":"0"}}
]
</pre>
</body>
</html>
src/main/webapp/WEB-INF/staticpng/logo_vips.png

1018 B

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 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_2_5.xsd">
<display-name>VIPSCoreManager</display-name>
<!--welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list-->
<filter>
<filter-name>CORS</filter-name>
<filter-class>com.thetransactioncompany.cors.CORSFilter</filter-class>
<filter-name>CORS</filter-name>
<filter-class>com.thetransactioncompany.cors.CORSFilter</filter-class>
<init-param>
<param-name>cors.supportedMethods</param-name>
<param-value>GET, POST, HEAD, PUT, DELETE, OPTIONS</param-value>
......@@ -19,7 +22,7 @@
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- Require HTTPS for all connections -->
<security-constraint>
<!--security-constraint>
<web-resource-collection>
<web-resource-name>Automatic SLL Forwarding</web-resource-name>
<url-pattern>/*</url-pattern>
......@@ -29,5 +32,5 @@
CONFIDENTIAL
</transport-guarantee>
</user-data-constraint>
</security-constraint>
</security-constraint-->
</web-app>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment