Committed by
Gerrit Code Review
CORD Subscriber Demo - Support for loading local data files.
Change-Id: I902197c26060eb791d8ac872890be4268f0dd64c
Showing
4 changed files
with
73 additions
and
0 deletions
... | @@ -48,6 +48,12 @@ | ... | @@ -48,6 +48,12 @@ |
48 | <artifactId>jersey-servlet</artifactId> | 48 | <artifactId>jersey-servlet</artifactId> |
49 | <version>1.19</version> | 49 | <version>1.19</version> |
50 | </dependency> | 50 | </dependency> |
51 | + | ||
52 | + <dependency> | ||
53 | + <groupId>commons-io</groupId> | ||
54 | + <artifactId>commons-io</artifactId> | ||
55 | + <version>2.4</version> | ||
56 | + </dependency> | ||
51 | </dependencies> | 57 | </dependencies> |
52 | 58 | ||
53 | </project> | 59 | </project> | ... | ... |
... | @@ -32,4 +32,9 @@ public class CordWebResource { | ... | @@ -32,4 +32,9 @@ public class CordWebResource { |
32 | return Response.ok("Hello World").build(); | 32 | return Response.ok("Hello World").build(); |
33 | } | 33 | } |
34 | 34 | ||
35 | + @GET | ||
36 | + @Path("fake") | ||
37 | + public Response fake() { | ||
38 | + return Response.ok(FakeUtils.slurp("sample.json")).build(); | ||
39 | + } | ||
35 | } | 40 | } | ... | ... |
1 | +/* | ||
2 | + * Copyright 2015 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + * | ||
16 | + */ | ||
17 | + | ||
18 | +package org.onosproject.cord.gui; | ||
19 | + | ||
20 | +import org.apache.commons.io.IOUtils; | ||
21 | + | ||
22 | +import java.io.IOException; | ||
23 | +import java.io.InputStream; | ||
24 | + | ||
25 | +/** | ||
26 | + * Provides support for fake data. | ||
27 | + */ | ||
28 | +public class FakeUtils { | ||
29 | + private static final ClassLoader CL = FakeUtils.class.getClassLoader(); | ||
30 | + private static final String ROOT_PATH = "/org/onosproject/cord/gui/"; | ||
31 | + private static final String UTF_8 = "UTF-8"; | ||
32 | + | ||
33 | + /** | ||
34 | + * Returns the contents of a local file as a string. | ||
35 | + * | ||
36 | + * @param path file path name | ||
37 | + * @return contents of file as a string | ||
38 | + */ | ||
39 | + public static String slurp(String path) { | ||
40 | + String result = ""; | ||
41 | + InputStream is = CL.getResourceAsStream(ROOT_PATH + path); | ||
42 | + try { | ||
43 | + result = IOUtils.toString(is, UTF_8); | ||
44 | + } catch (IOException e) { | ||
45 | + e.printStackTrace(); | ||
46 | + } | ||
47 | + return result; | ||
48 | + } | ||
49 | +} |
-
Please register or login to post a comment