Fixed to support networks without service dependency
Change-Id: I9412c06c34f5e62e1283f1972f0417b01b55d545
Showing
1 changed file
with
13 additions
and
0 deletions
| ... | @@ -16,20 +16,27 @@ | ... | @@ -16,20 +16,27 @@ |
| 16 | package org.onosproject.xosclient.impl; | 16 | package org.onosproject.xosclient.impl; |
| 17 | 17 | ||
| 18 | import org.onosproject.xosclient.api.XosAccess; | 18 | import org.onosproject.xosclient.api.XosAccess; |
| 19 | +import org.slf4j.Logger; | ||
| 20 | +import org.slf4j.LoggerFactory; | ||
| 19 | 21 | ||
| 20 | import javax.ws.rs.client.Client; | 22 | import javax.ws.rs.client.Client; |
| 21 | import javax.ws.rs.client.ClientBuilder; | 23 | import javax.ws.rs.client.ClientBuilder; |
| 22 | import javax.ws.rs.client.Invocation; | 24 | import javax.ws.rs.client.Invocation; |
| 23 | import javax.ws.rs.client.WebTarget; | 25 | import javax.ws.rs.client.WebTarget; |
| 26 | +import javax.ws.rs.core.Response; | ||
| 24 | 27 | ||
| 25 | import static com.google.common.net.MediaType.JSON_UTF_8; | 28 | import static com.google.common.net.MediaType.JSON_UTF_8; |
| 29 | +import static java.net.HttpURLConnection.HTTP_OK; | ||
| 26 | 30 | ||
| 27 | /** | 31 | /** |
| 28 | * XOS common REST API implementation. | 32 | * XOS common REST API implementation. |
| 29 | */ | 33 | */ |
| 30 | public class XosApi { | 34 | public class XosApi { |
| 31 | 35 | ||
| 36 | + private final Logger log = LoggerFactory.getLogger(getClass()); | ||
| 37 | + | ||
| 32 | protected static final String EMPTY_STRING = ""; | 38 | protected static final String EMPTY_STRING = ""; |
| 39 | + protected static final String EMPTY_JSON_STRING = "{}"; | ||
| 33 | 40 | ||
| 34 | protected final String baseUrl; | 41 | protected final String baseUrl; |
| 35 | protected final XosAccess access; | 42 | protected final XosAccess access; |
| ... | @@ -75,6 +82,12 @@ public class XosApi { | ... | @@ -75,6 +82,12 @@ public class XosApi { |
| 75 | WebTarget wt = client.target(access.endpoint() + baseUrl).path(path); | 82 | WebTarget wt = client.target(access.endpoint() + baseUrl).path(path); |
| 76 | Invocation.Builder builder = wt.request(JSON_UTF_8.toString()); | 83 | Invocation.Builder builder = wt.request(JSON_UTF_8.toString()); |
| 77 | 84 | ||
| 85 | + Response response = builder.get(); | ||
| 86 | + if (response.getStatus() != HTTP_OK) { | ||
| 87 | + log.warn("Failed to get resource {}", access.endpoint() + baseUrl + path); | ||
| 88 | + return EMPTY_JSON_STRING; | ||
| 89 | + } | ||
| 90 | + | ||
| 78 | return builder.get(String.class); | 91 | return builder.get(String.class); |
| 79 | } | 92 | } |
| 80 | } | 93 | } | ... | ... |
-
Please register or login to post a comment