Thomas Vachuska

Added redirect for the /onos/v1/docs Swagger UI URL. Added onos-rsdocs tool to …

…launch REST API docs UI from shell.

Change-Id: Ifb839e0205e5b176ebc7bb48644925eaa3675fd9
...@@ -30,6 +30,11 @@ export PATH="$PATH:$MAVEN/bin:$KARAF_ROOT/bin" ...@@ -30,6 +30,11 @@ export PATH="$PATH:$MAVEN/bin:$KARAF_ROOT/bin"
30 # Setup cell enviroment 30 # Setup cell enviroment
31 export ONOS_CELL=${ONOS_CELL:-local} 31 export ONOS_CELL=${ONOS_CELL:-local}
32 32
33 +# Setup default web user; for local dev execution use Karaf defaults
34 +export ONOS_WEB_USER=${ONOS_WEB_USER:-karaf}
35 +export ONOS_WEB_PASS=${ONOS_WEB_PASS:-karaf}
36 +
37 +# Setup default location of test scenarios
33 export ONOS_SCENARIOS=$ONOS_ROOT/tools/test/scenarios 38 export ONOS_SCENARIOS=$ONOS_ROOT/tools/test/scenarios
34 39
35 # Convenience utility to warp to various ONOS source projects 40 # Convenience utility to warp to various ONOS source projects
...@@ -78,8 +83,9 @@ alias ole='olo "ERROR|WARN|Exception|Error"' ...@@ -78,8 +83,9 @@ alias ole='olo "ERROR|WARN|Exception|Error"'
78 # Pretty-print JSON output 83 # Pretty-print JSON output
79 alias pp='python -m json.tool' 84 alias pp='python -m json.tool'
80 85
81 -# Short-hand to launch API docs and sample topology viewer GUI 86 +# Short-hand to launch Java API docs, REST API docs and ONOS GUI
82 alias docs='open $ONOS_ROOT/docs/target/site/apidocs/index.html' 87 alias docs='open $ONOS_ROOT/docs/target/site/apidocs/index.html'
88 +alias rsdocs='onos-rsdocs'
83 alias gui='onos-gui' 89 alias gui='onos-gui'
84 90
85 91
......
1 +#!/bin/bash
2 +# -----------------------------------------------------------------------------
3 +# Launches ONOS REST API docs GUI on the specified node.
4 +# -----------------------------------------------------------------------------
5 +
6 +host=${1:-$OCI}
7 +host=${host:-localhost}
8 +
9 +open http://$host:8181/onos/v1/docs
...@@ -23,15 +23,20 @@ import org.onosproject.rest.ApiDocService; ...@@ -23,15 +23,20 @@ import org.onosproject.rest.ApiDocService;
23 import javax.ws.rs.GET; 23 import javax.ws.rs.GET;
24 import javax.ws.rs.Path; 24 import javax.ws.rs.Path;
25 import javax.ws.rs.PathParam; 25 import javax.ws.rs.PathParam;
26 +import javax.ws.rs.core.Context;
26 import javax.ws.rs.core.Response; 27 import javax.ws.rs.core.Response;
28 +import javax.ws.rs.core.UriInfo;
27 import java.io.ByteArrayInputStream; 29 import java.io.ByteArrayInputStream;
28 import java.io.IOException; 30 import java.io.IOException;
29 import java.io.InputStream; 31 import java.io.InputStream;
30 import java.io.SequenceInputStream; 32 import java.io.SequenceInputStream;
33 +import java.net.URI;
34 +import java.net.URISyntaxException;
31 35
32 import static com.google.common.collect.ImmutableList.of; 36 import static com.google.common.collect.ImmutableList.of;
33 import static com.google.common.io.ByteStreams.toByteArray; 37 import static com.google.common.io.ByteStreams.toByteArray;
34 import static javax.ws.rs.core.MediaType.*; 38 import static javax.ws.rs.core.MediaType.*;
39 +import static javax.ws.rs.core.Response.temporaryRedirect;
35 import static org.onlab.util.Tools.nullIsNotFound; 40 import static org.onlab.util.Tools.nullIsNotFound;
36 41
37 /** 42 /**
...@@ -48,6 +53,9 @@ public class ApiDocResource extends AbstractInjectionResource { ...@@ -48,6 +53,9 @@ public class ApiDocResource extends AbstractInjectionResource {
48 private static final String INJECT_START = "<!-- {API-START} -->"; 53 private static final String INJECT_START = "<!-- {API-START} -->";
49 private static final String INJECT_END = "<!-- {API-END} -->"; 54 private static final String INJECT_END = "<!-- {API-END} -->";
50 55
56 + @Context
57 + private UriInfo uriInfo;
58 +
51 /** 59 /**
52 * Get all registered REST API docs. 60 * Get all registered REST API docs.
53 * Returns array of all registered API docs. 61 * Returns array of all registered API docs.
...@@ -102,8 +110,9 @@ public class ApiDocResource extends AbstractInjectionResource { ...@@ -102,8 +110,9 @@ public class ApiDocResource extends AbstractInjectionResource {
102 */ 110 */
103 @GET 111 @GET
104 @Path("/") 112 @Path("/")
105 - public Response getDefault() throws IOException { 113 + public Response getDefault() throws IOException, URISyntaxException {
106 - return getIndex(); 114 + return uriInfo.getPath().endsWith("/") ? getIndex() :
115 + temporaryRedirect(new URI(uriInfo.getPath() + "/")).build();
107 } 116 }
108 117
109 /** 118 /**
......