<%-- Document : index Created on : Sep 17, 2016, 6:42:16 AM Author : jbf --%> <%@page import="java.net.URLEncoder"%> <%@page import="org.json.JSONException"%> <%@page import="java.util.Enumeration"%> <%@page import="java.io.File"%> <%@page import="org.das2.datum.DatumRange"%> <%@page import="org.json.JSONObject"%> <%@page import="org.json.JSONArray"%> <%@page import="org.autoplot.hapiserver.HapiServerSupport"%> <%@page import="org.autoplot.hapiserver.Util"%> <%@page contentType="text/html" pageEncoding="UTF-8"%> HAPI Server JSP Demo

This is a HAPI Server.

More information about this type of server is found at GitHub. This implementation of the HAPI server uses Autoplot URIs to load data, more information about Autoplot can be found here. <% String me= "https://jfaden.net/HapiServerDemo/hapi"; %>
The HAPI server verifier will test this HAPI server for correctness. <% Util.maybeInitialize( getServletContext() ); if ( Util.getHapiHome()==null ) { String HAPI_SERVER_HOME= getServletContext().getInitParameter("HAPI_SERVER_HOME"); Util.setHapiHome( new File( HAPI_SERVER_HOME ) ); } String ip = request.getRemoteAddr(); if (ip.equals("127.0.0.1")) { Enumeration hh= request.getHeaders("X-Forwarded-For"); if ( hh.hasMoreElements() ) { ip = hh.nextElement(); } } if ( ip.equals("127.0.0.1") || ip.equals("0:0:0:0:0:0:0:1") ) { String s= request.getRequestURI(); int i= s.indexOf("/",1); s= s.substring(0,i); out.println( String.format( "
This is run from localhost, set logging with SetLogLevel. ", s )); out.println( "Requests from localhost will have performance monitored, which can degrade performance.

"); } %> Click on sparkline graphics to see the example time range.

Some example requests:

Catalog Show the catalog of available data sets.
Capabilities Capabilities of the server. For example, can it use binary streams to transfer data?
About More about this server, like contact info.

<% try { String HAPI_SERVER_HOME= getServletContext().getInitParameter("HAPI_SERVER_HOME"); Util.setHapiHome( new File( HAPI_SERVER_HOME ) ); JSONArray dss= HapiServerSupport.getCatalog(); for ( int i=0; imisconfigured: "+id+" ("+Util.fileSystemSafeName(id)+")

\n" ); continue; } JSONObject info= HapiServerSupport.readJSON( infoFile ); DatumRange availableRange= HapiServerSupport.getRange(info); DatumRange exampleRange= HapiServerSupport.getExampleRange(info); if ( exampleRange!=null ) { title= title+ " (available "+availableRange + ", example range "+exampleRange + " shown)"; } String exampleTimeRange= exampleRange==null ? null : String.format( "time.min=%s&time.max=%s", exampleRange.min().toString(), exampleRange.max().toString() ); out.println( String.format( "

%s

", title ) ); if ( exampleRange!=null ) { out.println( String.format("[Info] [Data]", ds.getString("id"), ds.getString("id"), exampleTimeRange ) ); } else { out.println( String.format("[Info] [Data]", ds.getString("id"), ds.getString("id") ) ); } String autoplotServer= "https://jfaden.net/AutoplotServlet"; //String autoplotServer= "http://localhost:8084/AutoplotServlet"; out.println(" "); JSONArray parameters= info.getJSONArray("parameters"); for ( int j=0; j0 ) out.print(" "); try { String pname= parameters.getJSONObject(j).getString("name"); out.print( String.format( "%s", ds.getString("id"), pname, exampleTimeRange, pname ) ); if ( j>0 ) { //sparklines // vap +hapi :https ://jfaden.net /HapiServerDemo /hapi ?id=?parameters=Temperature //?url=vap%2Bhapi%3Ahttps%3A%2F%2Fjfaden.net%2FHapiServerDemo%2Fhapi%3Fid%3DpoolTemperature%26timerange%3D2020-08-06&format=image%2Fpng&width=70&height=20&column=0%2C100%25&row=0%2C100%25&timeRange=2003-mar&renderType=&color=%23000000&symbolSize=&fillColor=%23aaaaff&foregroundColor=%23000000&backgroundColor=none StringBuilder sb= new StringBuilder(); sb.append("uri="); StringBuilder ub= new StringBuilder(); ub.append("vap+hapi:"+me); ub.append("?"); ub.append("id="+id); ub.append("¶meters="+pname); ub.append("&timerange="+exampleRange.toString().replaceAll(" ","+") ); sb.append( URLEncoder.encode(ub.toString()) ); sb.append("&format=image%2Fpng"); sb.append("&width=70"); sb.append("&height=16"); sb.append("&row=0%25-1px%2C100%25"); sb.append("&column=0%25-1px%2C100%25"); sb.append("&timerange="+URLEncoder.encode(exampleRange.toString()) ); out.print( ""); out.print( "" ); out.print( ""); //out.print( "" ); } } catch ( JSONException ex ) { out.print( "???" ); } } } } catch ( JSONException ex ) { out.print("

Something has gone wrong, see logs or send an email to faden at cottagesystems.com"); out.println("
"+ex.getMessage()); out.println("
"+out.toString()); } %>

<% long l= org.das2.qds.RecordIterator.TIME_STAMP; // load RecordIterator class first, or we'll get a negative time. %> deployed <%= Util.getDurationForHumans( System.currentTimeMillis() - l ) %> ago

version <%= Util.serverVersion() %>
HAPI protocol version <%= Util.hapiVersion() %>