Committed by
Gerrit Code Review
Restructuring the form of REST API deployment to provide
for security of app's REST APIs and for consistency of exception mappers and JSON writer. Change-Id: Id318372bf62f82ed974355c05e7fe64e0fbfc0c5
Showing
25 changed files
with
400 additions
and
152 deletions
| 1 | /* | 1 | /* |
| 2 | - * Copyright 2015 Open Networking Laboratory | 2 | + * Copyright 2014-2015 Open Networking Laboratory |
| 3 | * | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. | 5 | * you may not use this file except in compliance with the License. |
| ... | @@ -13,23 +13,20 @@ | ... | @@ -13,23 +13,20 @@ |
| 13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. | 14 | * limitations under the License. |
| 15 | */ | 15 | */ |
| 16 | -package org.onosproject.rest.exceptions; | ||
| 17 | 16 | ||
| 18 | -import org.junit.Test; | 17 | +package org.onosproject.acl; |
| 19 | 18 | ||
| 20 | -import static org.junit.Assert.*; | 19 | +import org.onlab.rest.AbstractWebApplication; |
| 20 | + | ||
| 21 | +import java.util.Set; | ||
| 21 | 22 | ||
| 22 | /** | 23 | /** |
| 23 | - * Set of tests for the various exception mappers. | 24 | + * ACL REST API web application. |
| 24 | */ | 25 | */ |
| 25 | -public class ExceptionMapperTest { | 26 | +public class AclWebApplication extends AbstractWebApplication { |
| 26 | - | 27 | + @Override |
| 27 | - @Test | 28 | + public Set<Class<?>> getClasses() { |
| 28 | - public void emptyMessage() { | 29 | + return getClasses(AclWebResource.class); |
| 29 | - RuntimeException exception = new NullPointerException(); | ||
| 30 | - ServerErrorMapper mapper = new ServerErrorMapper(); | ||
| 31 | - Object response = mapper.toResponse(exception).getEntity(); | ||
| 32 | - assertTrue("incorrect response", | ||
| 33 | - response.toString().contains("ExceptionMapperTest.emptyMessage(")); | ||
| 34 | } | 30 | } |
| 35 | -} | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 31 | +} | ||
| 32 | + | ... | ... |
| ... | @@ -22,20 +22,35 @@ | ... | @@ -22,20 +22,35 @@ |
| 22 | xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" | 22 | xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" |
| 23 | xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" | 23 | xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" |
| 24 | id="ONOS" version="2.5"> | 24 | id="ONOS" version="2.5"> |
| 25 | - <display-name>ACL application</display-name> | 25 | + <display-name>ACL application REST API</display-name> |
| 26 | + | ||
| 27 | + <security-constraint> | ||
| 28 | + <web-resource-collection> | ||
| 29 | + <web-resource-name>Secured</web-resource-name> | ||
| 30 | + <url-pattern>/*</url-pattern> | ||
| 31 | + </web-resource-collection> | ||
| 32 | + <auth-constraint> | ||
| 33 | + <role-name>admin</role-name> | ||
| 34 | + </auth-constraint> | ||
| 35 | + </security-constraint> | ||
| 36 | + | ||
| 37 | + <security-role> | ||
| 38 | + <role-name>admin</role-name> | ||
| 39 | + </security-role> | ||
| 40 | + | ||
| 41 | + <login-config> | ||
| 42 | + <auth-method>BASIC</auth-method> | ||
| 43 | + <realm-name>karaf</realm-name> | ||
| 44 | + </login-config> | ||
| 26 | 45 | ||
| 27 | <servlet> | 46 | <servlet> |
| 28 | <servlet-name>JAX-RS Service</servlet-name> | 47 | <servlet-name>JAX-RS Service</servlet-name> |
| 29 | <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class> | 48 | <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class> |
| 30 | <init-param> | 49 | <init-param> |
| 31 | - <param-name>com.sun.jersey.config.property.resourceConfigClass</param-name> | 50 | + <param-name>javax.ws.rs.Application</param-name> |
| 32 | - <param-value>com.sun.jersey.api.core.ClassNamesResourceConfig</param-value> | 51 | + <param-value>org.onosproject.acl.AclWebApplication</param-value> |
| 33 | - </init-param> | ||
| 34 | - <init-param> | ||
| 35 | - <param-name>com.sun.jersey.config.property.classnames</param-name> | ||
| 36 | - <param-value>org.onosproject.acl.AclWebResource</param-value> | ||
| 37 | </init-param> | 52 | </init-param> |
| 38 | - <load-on-startup>10</load-on-startup> | 53 | + <load-on-startup>1</load-on-startup> |
| 39 | </servlet> | 54 | </servlet> |
| 40 | 55 | ||
| 41 | <servlet-mapping> | 56 | <servlet-mapping> | ... | ... |
| 1 | +/* | ||
| 2 | + * Copyright 2014-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 | +package org.onosproject.dhcp.rest; | ||
| 18 | + | ||
| 19 | +import org.onlab.rest.AbstractWebApplication; | ||
| 20 | + | ||
| 21 | +import java.util.Set; | ||
| 22 | + | ||
| 23 | +/** | ||
| 24 | + * DHCP Web application. | ||
| 25 | + */ | ||
| 26 | +public class DhcpWebApplication extends AbstractWebApplication { | ||
| 27 | + @Override | ||
| 28 | + public Set<Class<?>> getClasses() { | ||
| 29 | + return getClasses(DhcpWebResource.class); | ||
| 30 | + } | ||
| 31 | +} |
| ... | @@ -44,7 +44,7 @@ import java.util.Map; | ... | @@ -44,7 +44,7 @@ import java.util.Map; |
| 44 | @Path("dhcp") | 44 | @Path("dhcp") |
| 45 | public class DhcpWebResource extends AbstractWebResource { | 45 | public class DhcpWebResource extends AbstractWebResource { |
| 46 | 46 | ||
| 47 | - final DhcpService service = get(DhcpService.class); | 47 | + private final DhcpService service = get(DhcpService.class); |
| 48 | 48 | ||
| 49 | /** | 49 | /** |
| 50 | * Get DHCP server configuration data. | 50 | * Get DHCP server configuration data. |
| ... | @@ -56,12 +56,11 @@ public class DhcpWebResource extends AbstractWebResource { | ... | @@ -56,12 +56,11 @@ public class DhcpWebResource extends AbstractWebResource { |
| 56 | @GET | 56 | @GET |
| 57 | @Path("config") | 57 | @Path("config") |
| 58 | public Response getConfigs() { | 58 | public Response getConfigs() { |
| 59 | - DhcpService service = get(DhcpService.class); | ||
| 60 | ObjectNode node = mapper().createObjectNode() | 59 | ObjectNode node = mapper().createObjectNode() |
| 61 | .put("leaseTime", service.getLeaseTime()) | 60 | .put("leaseTime", service.getLeaseTime()) |
| 62 | .put("renewalTime", service.getRenewalTime()) | 61 | .put("renewalTime", service.getRenewalTime()) |
| 63 | .put("rebindingTime", service.getRebindingTime()); | 62 | .put("rebindingTime", service.getRebindingTime()); |
| 64 | - return ok(node.toString()).build(); | 63 | + return ok(node).build(); |
| 65 | } | 64 | } |
| 66 | 65 | ||
| 67 | /** | 66 | /** |
| ... | @@ -76,13 +75,13 @@ public class DhcpWebResource extends AbstractWebResource { | ... | @@ -76,13 +75,13 @@ public class DhcpWebResource extends AbstractWebResource { |
| 76 | public Response listMappings() { | 75 | public Response listMappings() { |
| 77 | ObjectNode root = mapper().createObjectNode(); | 76 | ObjectNode root = mapper().createObjectNode(); |
| 78 | 77 | ||
| 79 | - final Map<HostId, IpAssignment> intents = service.listMapping(); | 78 | + Map<HostId, IpAssignment> intents = service.listMapping(); |
| 80 | ArrayNode arrayNode = root.putArray("mappings"); | 79 | ArrayNode arrayNode = root.putArray("mappings"); |
| 81 | intents.entrySet().forEach(i -> arrayNode.add(mapper().createObjectNode() | 80 | intents.entrySet().forEach(i -> arrayNode.add(mapper().createObjectNode() |
| 82 | .put("host", i.getKey().toString()) | 81 | .put("host", i.getKey().toString()) |
| 83 | .put("ip", i.getValue().ipAddress().toString()))); | 82 | .put("ip", i.getValue().ipAddress().toString()))); |
| 84 | 83 | ||
| 85 | - return ok(root.toString()).build(); | 84 | + return ok(root).build(); |
| 86 | } | 85 | } |
| 87 | 86 | ||
| 88 | 87 | ||
| ... | @@ -96,12 +95,11 @@ public class DhcpWebResource extends AbstractWebResource { | ... | @@ -96,12 +95,11 @@ public class DhcpWebResource extends AbstractWebResource { |
| 96 | @GET | 95 | @GET |
| 97 | @Path("available") | 96 | @Path("available") |
| 98 | public Response listAvailableIPs() { | 97 | public Response listAvailableIPs() { |
| 99 | - final Iterable<Ip4Address> availableIPList = service.getAvailableIPs(); | 98 | + Iterable<Ip4Address> availableIPList = service.getAvailableIPs(); |
| 100 | - | 99 | + ObjectNode root = mapper().createObjectNode(); |
| 101 | - final ObjectNode root = mapper().createObjectNode(); | ||
| 102 | ArrayNode arrayNode = root.putArray("availableIP"); | 100 | ArrayNode arrayNode = root.putArray("availableIP"); |
| 103 | availableIPList.forEach(i -> arrayNode.add(i.toString())); | 101 | availableIPList.forEach(i -> arrayNode.add(i.toString())); |
| 104 | - return ok(root.toString()).build(); | 102 | + return ok(root).build(); |
| 105 | } | 103 | } |
| 106 | 104 | ||
| 107 | /** | 105 | /** |
| ... | @@ -139,7 +137,7 @@ public class DhcpWebResource extends AbstractWebResource { | ... | @@ -139,7 +137,7 @@ public class DhcpWebResource extends AbstractWebResource { |
| 139 | } catch (IOException e) { | 137 | } catch (IOException e) { |
| 140 | throw new IllegalArgumentException(e.getMessage()); | 138 | throw new IllegalArgumentException(e.getMessage()); |
| 141 | } | 139 | } |
| 142 | - return ok(root.toString()).build(); | 140 | + return ok(root).build(); |
| 143 | } | 141 | } |
| 144 | 142 | ||
| 145 | /** | 143 | /** |
| ... | @@ -152,7 +150,6 @@ public class DhcpWebResource extends AbstractWebResource { | ... | @@ -152,7 +150,6 @@ public class DhcpWebResource extends AbstractWebResource { |
| 152 | @DELETE | 150 | @DELETE |
| 153 | @Path("mappings/{macID}") | 151 | @Path("mappings/{macID}") |
| 154 | public Response deleteMapping(@PathParam("macID") String macID) { | 152 | public Response deleteMapping(@PathParam("macID") String macID) { |
| 155 | - | ||
| 156 | ObjectNode root = mapper().createObjectNode(); | 153 | ObjectNode root = mapper().createObjectNode(); |
| 157 | 154 | ||
| 158 | if (!service.removeStaticMapping(MacAddress.valueOf(macID))) { | 155 | if (!service.removeStaticMapping(MacAddress.valueOf(macID))) { |
| ... | @@ -164,6 +161,6 @@ public class DhcpWebResource extends AbstractWebResource { | ... | @@ -164,6 +161,6 @@ public class DhcpWebResource extends AbstractWebResource { |
| 164 | .put("host", i.getKey().toString()) | 161 | .put("host", i.getKey().toString()) |
| 165 | .put("ip", i.getValue().ipAddress().toString()))); | 162 | .put("ip", i.getValue().ipAddress().toString()))); |
| 166 | 163 | ||
| 167 | - return ok(root.toString()).build(); | 164 | + return ok(root).build(); |
| 168 | } | 165 | } |
| 169 | } | 166 | } | ... | ... |
| ... | @@ -14,24 +14,38 @@ | ... | @@ -14,24 +14,38 @@ |
| 14 | ~ See the License for the specific language governing permissions and | 14 | ~ See the License for the specific language governing permissions and |
| 15 | ~ limitations under the License. | 15 | ~ limitations under the License. |
| 16 | --> | 16 | --> |
| 17 | -<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" | 17 | +<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
| 18 | + xmlns="http://java.sun.com/xml/ns/javaee" | ||
| 18 | xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" | 19 | xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" |
| 19 | xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" | 20 | xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" |
| 20 | id="ONOS" version="2.5"> | 21 | id="ONOS" version="2.5"> |
| 21 | <display-name>DHCP Server REST API v1.0</display-name> | 22 | <display-name>DHCP Server REST API v1.0</display-name> |
| 22 | 23 | ||
| 24 | + <security-constraint> | ||
| 25 | + <web-resource-collection> | ||
| 26 | + <web-resource-name>Secured</web-resource-name> | ||
| 27 | + <url-pattern>/*</url-pattern> | ||
| 28 | + </web-resource-collection> | ||
| 29 | + <auth-constraint> | ||
| 30 | + <role-name>admin</role-name> | ||
| 31 | + </auth-constraint> | ||
| 32 | + </security-constraint> | ||
| 33 | + | ||
| 34 | + <security-role> | ||
| 35 | + <role-name>admin</role-name> | ||
| 36 | + </security-role> | ||
| 37 | + | ||
| 38 | + <login-config> | ||
| 39 | + <auth-method>BASIC</auth-method> | ||
| 40 | + <realm-name>karaf</realm-name> | ||
| 41 | + </login-config> | ||
| 42 | + | ||
| 23 | <servlet> | 43 | <servlet> |
| 24 | <servlet-name>JAX-RS Service</servlet-name> | 44 | <servlet-name>JAX-RS Service</servlet-name> |
| 25 | <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class> | 45 | <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class> |
| 26 | <init-param> | 46 | <init-param> |
| 27 | - <param-name>com.sun.jersey.config.property.resourceConfigClass</param-name> | 47 | + <param-name>javax.ws.rs.Application</param-name> |
| 28 | - <param-value>com.sun.jersey.api.core.ClassNamesResourceConfig</param-value> | 48 | + <param-value>org.onosproject.dhcp.rest.DhcpWebApplication</param-value> |
| 29 | - </init-param> | ||
| 30 | - <init-param> | ||
| 31 | - <param-name>com.sun.jersey.config.property.classnames</param-name> | ||
| 32 | - <param-value> | ||
| 33 | - org.onosproject.dhcp.rest.DhcpWebResource | ||
| 34 | - </param-value> | ||
| 35 | </init-param> | 49 | </init-param> |
| 36 | <load-on-startup>1</load-on-startup> | 50 | <load-on-startup>1</load-on-startup> |
| 37 | </servlet> | 51 | </servlet> | ... | ... |
| 1 | +/* | ||
| 2 | + * Copyright 2014-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 | +package org.onosproject.vtnweb.resources; | ||
| 18 | + | ||
| 19 | +import org.onlab.rest.AbstractWebApplication; | ||
| 20 | + | ||
| 21 | +import java.util.Set; | ||
| 22 | + | ||
| 23 | +/** | ||
| 24 | + * VTN REST API web application. | ||
| 25 | + */ | ||
| 26 | +public class VtnWebApplication extends AbstractWebApplication { | ||
| 27 | + @Override | ||
| 28 | + public Set<Class<?>> getClasses() { | ||
| 29 | + return getClasses(TenantNetworkWebResource.class, | ||
| 30 | + SubnetWebResource.class, | ||
| 31 | + VirtualPortWebResource.class, | ||
| 32 | + FlowClassifierWebResource.class, | ||
| 33 | + PortChainWebResource.class, | ||
| 34 | + PortPairGroupWebResource.class, | ||
| 35 | + PortPairWebResource.class, | ||
| 36 | + FloatingIpWebResource.class, | ||
| 37 | + RouterWebResource.class); | ||
| 38 | + } | ||
| 39 | +} | ||
| 40 | + |
| ... | @@ -42,41 +42,17 @@ | ... | @@ -42,41 +42,17 @@ |
| 42 | --> | 42 | --> |
| 43 | 43 | ||
| 44 | <servlet> | 44 | <servlet> |
| 45 | - <servlet-name>VTNRSC JAX-RS Service</servlet-name> | 45 | + <servlet-name>JAX-RS Service</servlet-name> |
| 46 | <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class> | 46 | <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class> |
| 47 | <init-param> | 47 | <init-param> |
| 48 | - <param-name>com.sun.jersey.config.property.resourceConfigClass</param-name> | 48 | + <param-name>javax.ws.rs.Application</param-name> |
| 49 | - <param-value>com.sun.jersey.api.core.ClassNamesResourceConfig</param-value> | 49 | + <param-value>org.onosproject.vtnweb.resources.VtnWebApplication</param-value> |
| 50 | - </init-param> | ||
| 51 | - <init-param> | ||
| 52 | - <param-name>com.sun.jersey.config.property.classnames</param-name> | ||
| 53 | - <param-value> | ||
| 54 | - org.onosproject.rest.exceptions.EntityNotFoundMapper, | ||
| 55 | - org.onosproject.rest.exceptions.ServiceNotFoundMapper, | ||
| 56 | - org.onosproject.rest.exceptions.NotFoundMapper, | ||
| 57 | - org.onosproject.rest.exceptions.ServerErrorMapper, | ||
| 58 | - org.onosproject.rest.exceptions.BadRequestMapper, | ||
| 59 | - org.onosproject.rest.exceptions.WebApplicationExceptionMapper, | ||
| 60 | - org.onosproject.rest.exceptions.IllegalArgumentExceptionMapper, | ||
| 61 | - org.onosproject.rest.exceptions.IllegalStateExceptionMapper, | ||
| 62 | - org.onosproject.rest.resources.JsonBodyWriter, | ||
| 63 | - | ||
| 64 | - org.onosproject.vtnweb.resources.TenantNetworkWebResource, | ||
| 65 | - org.onosproject.vtnweb.resources.SubnetWebResource, | ||
| 66 | - org.onosproject.vtnweb.resources.VirtualPortWebResource, | ||
| 67 | - org.onosproject.vtnweb.resources.FlowClassifierWebResource, | ||
| 68 | - org.onosproject.vtnweb.resources.PortChainWebResource, | ||
| 69 | - org.onosproject.vtnweb.resources.PortPairGroupWebResource, | ||
| 70 | - org.onosproject.vtnweb.resources.PortPairWebResource, | ||
| 71 | - org.onosproject.vtnweb.resources.FloatingIpWebResource, | ||
| 72 | - org.onosproject.vtnweb.resources.RouterWebResource | ||
| 73 | - </param-value> | ||
| 74 | </init-param> | 50 | </init-param> |
| 75 | <load-on-startup>1</load-on-startup> | 51 | <load-on-startup>1</load-on-startup> |
| 76 | </servlet> | 52 | </servlet> |
| 77 | 53 | ||
| 78 | <servlet-mapping> | 54 | <servlet-mapping> |
| 79 | - <servlet-name>VTNRSC JAX-RS Service</servlet-name> | 55 | + <servlet-name>JAX-RS Service</servlet-name> |
| 80 | <url-pattern>/*</url-pattern> | 56 | <url-pattern>/*</url-pattern> |
| 81 | </servlet-mapping> | 57 | </servlet-mapping> |
| 82 | </web-app> | 58 | </web-app> | ... | ... |
| ... | @@ -33,6 +33,25 @@ | ... | @@ -33,6 +33,25 @@ |
| 33 | 33 | ||
| 34 | <dependencies> | 34 | <dependencies> |
| 35 | <dependency> | 35 | <dependency> |
| 36 | + <groupId>org.onosproject</groupId> | ||
| 37 | + <artifactId>onlab-misc</artifactId> | ||
| 38 | + </dependency> | ||
| 39 | + | ||
| 40 | + <dependency> | ||
| 41 | + <groupId>org.onosproject</groupId> | ||
| 42 | + <artifactId>onlab-osgi</artifactId> | ||
| 43 | + </dependency> | ||
| 44 | + | ||
| 45 | + <dependency> | ||
| 46 | + <groupId>com.fasterxml.jackson.core</groupId> | ||
| 47 | + <artifactId>jackson-annotations</artifactId> | ||
| 48 | + </dependency> | ||
| 49 | + <dependency> | ||
| 50 | + <groupId>com.fasterxml.jackson.core</groupId> | ||
| 51 | + <artifactId>jackson-databind</artifactId> | ||
| 52 | + </dependency> | ||
| 53 | + | ||
| 54 | + <dependency> | ||
| 36 | <groupId>com.sun.jersey.jersey-test-framework</groupId> | 55 | <groupId>com.sun.jersey.jersey-test-framework</groupId> |
| 37 | <artifactId>jersey-test-framework-core</artifactId> | 56 | <artifactId>jersey-test-framework-core</artifactId> |
| 38 | <scope>test</scope> | 57 | <scope>test</scope> |
| ... | @@ -42,12 +61,6 @@ | ... | @@ -42,12 +61,6 @@ |
| 42 | <artifactId>jersey-test-framework-grizzly2</artifactId> | 61 | <artifactId>jersey-test-framework-grizzly2</artifactId> |
| 43 | <scope>test</scope> | 62 | <scope>test</scope> |
| 44 | </dependency> | 63 | </dependency> |
| 45 | - | ||
| 46 | - <dependency> | ||
| 47 | - <groupId>org.onosproject</groupId> | ||
| 48 | - <artifactId>onlab-osgi</artifactId> | ||
| 49 | - <version>${project.version}</version> | ||
| 50 | - </dependency> | ||
| 51 | </dependencies> | 64 | </dependencies> |
| 52 | 65 | ||
| 53 | </project> | 66 | </project> | ... | ... |
| 1 | +/* | ||
| 2 | + * Copyright 2014-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 | +package org.onlab.rest; | ||
| 18 | + | ||
| 19 | +import com.google.common.collect.ImmutableSet; | ||
| 20 | +import org.onlab.rest.exceptions.BadRequestMapper; | ||
| 21 | +import org.onlab.rest.exceptions.EntityNotFoundMapper; | ||
| 22 | +import org.onlab.rest.exceptions.IllegalArgumentExceptionMapper; | ||
| 23 | +import org.onlab.rest.exceptions.IllegalStateExceptionMapper; | ||
| 24 | +import org.onlab.rest.exceptions.NotFoundMapper; | ||
| 25 | +import org.onlab.rest.exceptions.ServerErrorMapper; | ||
| 26 | +import org.onlab.rest.exceptions.ServiceNotFoundMapper; | ||
| 27 | +import org.onlab.rest.exceptions.WebApplicationExceptionMapper; | ||
| 28 | + | ||
| 29 | +import javax.ws.rs.core.Application; | ||
| 30 | +import java.util.Set; | ||
| 31 | + | ||
| 32 | +/** | ||
| 33 | + * Base web application. | ||
| 34 | + */ | ||
| 35 | +public abstract class AbstractWebApplication extends Application { | ||
| 36 | + | ||
| 37 | + /** | ||
| 38 | + * Returns the aggregate set of resources, writers and mappers combined | ||
| 39 | + * with a default set of such web entities. | ||
| 40 | + * | ||
| 41 | + * @param classes set of resources, writers and mappers | ||
| 42 | + * @return combined set of web entities | ||
| 43 | + */ | ||
| 44 | + protected Set<Class<?>> getClasses(Class<?>... classes) { | ||
| 45 | + ImmutableSet.Builder<Class<?>> builder = ImmutableSet.builder(); | ||
| 46 | + builder.add(ServiceNotFoundMapper.class, | ||
| 47 | + EntityNotFoundMapper.class, | ||
| 48 | + NotFoundMapper.class, | ||
| 49 | + ServerErrorMapper.class, | ||
| 50 | + BadRequestMapper.class, | ||
| 51 | + WebApplicationExceptionMapper.class, | ||
| 52 | + IllegalArgumentExceptionMapper.class, | ||
| 53 | + IllegalStateExceptionMapper.class, | ||
| 54 | + JsonBodyWriter.class); | ||
| 55 | + builder.add(classes); | ||
| 56 | + return builder.build(); | ||
| 57 | + } | ||
| 58 | + | ||
| 59 | + @Override | ||
| 60 | + public abstract Set<Class<?>> getClasses(); | ||
| 61 | + | ||
| 62 | +} |
| 1 | +/* | ||
| 2 | + * Copyright 2014-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 | +package org.onlab.rest; | ||
| 18 | + | ||
| 19 | +import com.fasterxml.jackson.databind.ObjectMapper; | ||
| 20 | +import com.fasterxml.jackson.databind.node.ObjectNode; | ||
| 21 | + | ||
| 22 | +import javax.ws.rs.Produces; | ||
| 23 | +import javax.ws.rs.core.MediaType; | ||
| 24 | +import javax.ws.rs.core.MultivaluedMap; | ||
| 25 | +import javax.ws.rs.ext.MessageBodyWriter; | ||
| 26 | +import javax.ws.rs.ext.Provider; | ||
| 27 | +import java.io.IOException; | ||
| 28 | +import java.io.OutputStream; | ||
| 29 | +import java.lang.annotation.Annotation; | ||
| 30 | +import java.lang.reflect.Type; | ||
| 31 | + | ||
| 32 | +/** | ||
| 33 | + * JAX-RS Response message body writer. | ||
| 34 | + */ | ||
| 35 | +@Provider | ||
| 36 | +@Produces("application/json") | ||
| 37 | +public class JsonBodyWriter implements MessageBodyWriter<ObjectNode> { | ||
| 38 | + | ||
| 39 | + private ObjectMapper mapper = new ObjectMapper(); | ||
| 40 | + | ||
| 41 | + @Override | ||
| 42 | + public boolean isWriteable(Class<?> type, Type genericType, | ||
| 43 | + Annotation[] annotations, MediaType mediaType) { | ||
| 44 | + return type == ObjectNode.class; | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + @Override | ||
| 48 | + public long getSize(ObjectNode node, Class<?> type, Type genericType, | ||
| 49 | + Annotation[] annotations, MediaType mediaType) { | ||
| 50 | + return -1; | ||
| 51 | + } | ||
| 52 | + | ||
| 53 | + @Override | ||
| 54 | + public void writeTo(ObjectNode node, Class<?> type, Type genericType, | ||
| 55 | + Annotation[] annotations, MediaType mediaType, | ||
| 56 | + MultivaluedMap<String, Object> httpHeaders, | ||
| 57 | + OutputStream entityStream) throws IOException { | ||
| 58 | + mapper.writer().writeValue(entityStream, node); | ||
| 59 | + entityStream.flush(); | ||
| 60 | + } | ||
| 61 | +} |
| ... | @@ -13,7 +13,8 @@ | ... | @@ -13,7 +13,8 @@ |
| 13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. | 14 | * limitations under the License. |
| 15 | */ | 15 | */ |
| 16 | -package org.onosproject.rest.exceptions; | 16 | + |
| 17 | +package org.onlab.rest.exceptions; | ||
| 17 | 18 | ||
| 18 | import com.fasterxml.jackson.databind.ObjectMapper; | 19 | import com.fasterxml.jackson.databind.ObjectMapper; |
| 19 | import com.fasterxml.jackson.databind.node.ObjectNode; | 20 | import com.fasterxml.jackson.databind.node.ObjectNode; | ... | ... |
| 1 | /* | 1 | /* |
| 2 | - * Copyright 2015 Open Networking Laboratory | 2 | + * Copyright 2014-2015 Open Networking Laboratory |
| 3 | * | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. | 5 | * you may not use this file except in compliance with the License. |
| ... | @@ -13,11 +13,11 @@ | ... | @@ -13,11 +13,11 @@ |
| 13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. | 14 | * limitations under the License. |
| 15 | */ | 15 | */ |
| 16 | -package org.onosproject.rest.exceptions; | 16 | + |
| 17 | +package org.onlab.rest.exceptions; | ||
| 17 | 18 | ||
| 18 | import javax.ws.rs.core.Response; | 19 | import javax.ws.rs.core.Response; |
| 19 | import javax.ws.rs.ext.Provider; | 20 | import javax.ws.rs.ext.Provider; |
| 20 | - | ||
| 21 | import java.io.IOException; | 21 | import java.io.IOException; |
| 22 | 22 | ||
| 23 | /** | 23 | /** | ... | ... |
| ... | @@ -13,7 +13,8 @@ | ... | @@ -13,7 +13,8 @@ |
| 13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. | 14 | * limitations under the License. |
| 15 | */ | 15 | */ |
| 16 | -package org.onosproject.rest.exceptions; | 16 | + |
| 17 | +package org.onlab.rest.exceptions; | ||
| 17 | 18 | ||
| 18 | import org.onlab.util.ItemNotFoundException; | 19 | import org.onlab.util.ItemNotFoundException; |
| 19 | 20 | ... | ... |
| ... | @@ -13,7 +13,8 @@ | ... | @@ -13,7 +13,8 @@ |
| 13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. | 14 | * limitations under the License. |
| 15 | */ | 15 | */ |
| 16 | -package org.onosproject.rest.exceptions; | 16 | + |
| 17 | +package org.onlab.rest.exceptions; | ||
| 17 | 18 | ||
| 18 | import javax.ws.rs.core.Response; | 19 | import javax.ws.rs.core.Response; |
| 19 | import javax.ws.rs.ext.Provider; | 20 | import javax.ws.rs.ext.Provider; | ... | ... |
| 1 | /* | 1 | /* |
| 2 | - * Copyright 2015 Open Networking Laboratory | 2 | + * Copyright 2014-2015 Open Networking Laboratory |
| 3 | * | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. | 5 | * you may not use this file except in compliance with the License. |
| ... | @@ -13,7 +13,8 @@ | ... | @@ -13,7 +13,8 @@ |
| 13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. | 14 | * limitations under the License. |
| 15 | */ | 15 | */ |
| 16 | -package org.onosproject.rest.exceptions; | 16 | + |
| 17 | +package org.onlab.rest.exceptions; | ||
| 17 | 18 | ||
| 18 | import javax.ws.rs.core.Response; | 19 | import javax.ws.rs.core.Response; |
| 19 | import javax.ws.rs.ext.Provider; | 20 | import javax.ws.rs.ext.Provider; | ... | ... |
| 1 | /* | 1 | /* |
| 2 | - * Copyright 2015 Open Networking Laboratory | 2 | + * Copyright 2014-2015 Open Networking Laboratory |
| 3 | * | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. | 5 | * you may not use this file except in compliance with the License. |
| ... | @@ -13,13 +13,14 @@ | ... | @@ -13,13 +13,14 @@ |
| 13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. | 14 | * limitations under the License. |
| 15 | */ | 15 | */ |
| 16 | -package org.onosproject.rest.exceptions; | ||
| 17 | 16 | ||
| 18 | -import javax.ws.rs.core.Response; | 17 | +package org.onlab.rest.exceptions; |
| 19 | -import javax.ws.rs.ext.Provider; | ||
| 20 | 18 | ||
| 21 | import com.sun.jersey.api.NotFoundException; | 19 | import com.sun.jersey.api.NotFoundException; |
| 22 | 20 | ||
| 21 | +import javax.ws.rs.core.Response; | ||
| 22 | +import javax.ws.rs.ext.Provider; | ||
| 23 | + | ||
| 23 | /** | 24 | /** |
| 24 | * Mapper for api not found exceptions to the NOT_FOUND response code. | 25 | * Mapper for api not found exceptions to the NOT_FOUND response code. |
| 25 | */ | 26 | */ | ... | ... |
| ... | @@ -13,13 +13,14 @@ | ... | @@ -13,13 +13,14 @@ |
| 13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. | 14 | * limitations under the License. |
| 15 | */ | 15 | */ |
| 16 | -package org.onosproject.rest.exceptions; | ||
| 17 | 16 | ||
| 18 | -import javax.ws.rs.core.Response; | 17 | +package org.onlab.rest.exceptions; |
| 19 | -import javax.ws.rs.ext.Provider; | ||
| 20 | 18 | ||
| 21 | import org.slf4j.Logger; | 19 | import org.slf4j.Logger; |
| 22 | 20 | ||
| 21 | +import javax.ws.rs.core.Response; | ||
| 22 | +import javax.ws.rs.ext.Provider; | ||
| 23 | + | ||
| 23 | import static org.slf4j.LoggerFactory.getLogger; | 24 | import static org.slf4j.LoggerFactory.getLogger; |
| 24 | 25 | ||
| 25 | /** | 26 | /** | ... | ... |
| ... | @@ -13,7 +13,8 @@ | ... | @@ -13,7 +13,8 @@ |
| 13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. | 14 | * limitations under the License. |
| 15 | */ | 15 | */ |
| 16 | -package org.onosproject.rest.exceptions; | 16 | + |
| 17 | +package org.onlab.rest.exceptions; | ||
| 17 | 18 | ||
| 18 | import org.onlab.osgi.ServiceNotFoundException; | 19 | import org.onlab.osgi.ServiceNotFoundException; |
| 19 | 20 | ... | ... |
| 1 | /* | 1 | /* |
| 2 | - * Copyright 2015 Open Networking Laboratory | 2 | + * Copyright 2014-2015 Open Networking Laboratory |
| 3 | * | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. | 5 | * you may not use this file except in compliance with the License. |
| ... | @@ -13,7 +13,8 @@ | ... | @@ -13,7 +13,8 @@ |
| 13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. | 14 | * limitations under the License. |
| 15 | */ | 15 | */ |
| 16 | -package org.onosproject.rest.exceptions; | 16 | + |
| 17 | +package org.onlab.rest.exceptions; | ||
| 17 | 18 | ||
| 18 | import javax.ws.rs.WebApplicationException; | 19 | import javax.ws.rs.WebApplicationException; |
| 19 | import javax.ws.rs.core.Response; | 20 | import javax.ws.rs.core.Response; | ... | ... |
| 1 | /* | 1 | /* |
| 2 | - * Copyright 2014 Open Networking Laboratory | 2 | + * Copyright 2014-2015 Open Networking Laboratory |
| 3 | * | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. | 5 | * you may not use this file except in compliance with the License. |
| ... | @@ -17,4 +17,4 @@ | ... | @@ -17,4 +17,4 @@ |
| 17 | /** | 17 | /** |
| 18 | * Various exception mappers to map errors to proper response status codes. | 18 | * Various exception mappers to map errors to proper response status codes. |
| 19 | */ | 19 | */ |
| 20 | -package org.onosproject.rest.exceptions; | 20 | +package org.onlab.rest.exceptions; | ... | ... |
| 1 | +/* | ||
| 2 | + * Copyright 2014-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 | +package org.onosproject.rest.resources; | ||
| 18 | + | ||
| 19 | +import org.onlab.rest.AbstractWebApplication; | ||
| 20 | + | ||
| 21 | +import java.util.Set; | ||
| 22 | + | ||
| 23 | +/** | ||
| 24 | + * Core REST APIs web application. | ||
| 25 | + */ | ||
| 26 | +public class CoreWebApplication extends AbstractWebApplication { | ||
| 27 | + | ||
| 28 | + @Override | ||
| 29 | + public Set<Class<?>> getClasses() { | ||
| 30 | + return getClasses(ApiDocResource.class, | ||
| 31 | + ApplicationsWebResource.class, | ||
| 32 | + ComponentConfigWebResource.class, | ||
| 33 | + NetworkConfigWebResource.class, | ||
| 34 | + ClusterWebResource.class, | ||
| 35 | + DevicesWebResource.class, | ||
| 36 | + LinksWebResource.class, | ||
| 37 | + HostsWebResource.class, | ||
| 38 | + IntentsWebResource.class, | ||
| 39 | + FlowsWebResource.class, | ||
| 40 | + TopologyWebResource.class, | ||
| 41 | + ConfigWebResource.class, | ||
| 42 | + PathsWebResource.class, | ||
| 43 | + StatisticsWebResource.class | ||
| 44 | + ); | ||
| 45 | + } | ||
| 46 | +} |
| ... | @@ -45,37 +45,8 @@ | ... | @@ -45,37 +45,8 @@ |
| 45 | <servlet-name>JAX-RS Service</servlet-name> | 45 | <servlet-name>JAX-RS Service</servlet-name> |
| 46 | <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class> | 46 | <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class> |
| 47 | <init-param> | 47 | <init-param> |
| 48 | - <param-name>com.sun.jersey.config.property.resourceConfigClass</param-name> | 48 | + <param-name>javax.ws.rs.Application</param-name> |
| 49 | - <param-value>com.sun.jersey.api.core.ClassNamesResourceConfig</param-value> | 49 | + <param-value>org.onosproject.rest.resources.CoreWebApplication</param-value> |
| 50 | - </init-param> | ||
| 51 | - <init-param> | ||
| 52 | - <param-name>com.sun.jersey.config.property.classnames</param-name> | ||
| 53 | - <param-value> | ||
| 54 | - org.onosproject.rest.exceptions.EntityNotFoundMapper, | ||
| 55 | - org.onosproject.rest.exceptions.ServiceNotFoundMapper, | ||
| 56 | - org.onosproject.rest.exceptions.NotFoundMapper, | ||
| 57 | - org.onosproject.rest.exceptions.ServerErrorMapper, | ||
| 58 | - org.onosproject.rest.exceptions.BadRequestMapper, | ||
| 59 | - org.onosproject.rest.exceptions.WebApplicationExceptionMapper, | ||
| 60 | - org.onosproject.rest.exceptions.IllegalArgumentExceptionMapper, | ||
| 61 | - org.onosproject.rest.exceptions.IllegalStateExceptionMapper, | ||
| 62 | - org.onosproject.rest.resources.JsonBodyWriter, | ||
| 63 | - | ||
| 64 | - org.onosproject.rest.resources.ApiDocResource, | ||
| 65 | - org.onosproject.rest.resources.ApplicationsWebResource, | ||
| 66 | - org.onosproject.rest.resources.ComponentConfigWebResource, | ||
| 67 | - org.onosproject.rest.resources.NetworkConfigWebResource, | ||
| 68 | - org.onosproject.rest.resources.ClusterWebResource, | ||
| 69 | - org.onosproject.rest.resources.DevicesWebResource, | ||
| 70 | - org.onosproject.rest.resources.LinksWebResource, | ||
| 71 | - org.onosproject.rest.resources.HostsWebResource, | ||
| 72 | - org.onosproject.rest.resources.IntentsWebResource, | ||
| 73 | - org.onosproject.rest.resources.FlowsWebResource, | ||
| 74 | - org.onosproject.rest.resources.TopologyWebResource, | ||
| 75 | - org.onosproject.rest.resources.ConfigWebResource, | ||
| 76 | - org.onosproject.rest.resources.PathsWebResource, | ||
| 77 | - org.onosproject.rest.resources.StatisticsWebResource | ||
| 78 | - </param-value> | ||
| 79 | </init-param> | 50 | </init-param> |
| 80 | <load-on-startup>1</load-on-startup> | 51 | <load-on-startup>1</load-on-startup> |
| 81 | </servlet> | 52 | </servlet> | ... | ... |
| ... | @@ -15,13 +15,12 @@ | ... | @@ -15,13 +15,12 @@ |
| 15 | */ | 15 | */ |
| 16 | package org.onosproject.rest; | 16 | package org.onosproject.rest; |
| 17 | 17 | ||
| 18 | -import java.io.InputStream; | 18 | +import com.eclipsesource.json.JsonArray; |
| 19 | -import java.net.HttpURLConnection; | 19 | +import com.eclipsesource.json.JsonObject; |
| 20 | -import java.util.Collections; | 20 | +import com.eclipsesource.json.JsonValue; |
| 21 | -import java.util.HashSet; | 21 | +import com.sun.jersey.api.client.ClientResponse; |
| 22 | - | 22 | +import com.sun.jersey.api.client.UniformInterfaceException; |
| 23 | -import javax.ws.rs.core.MediaType; | 23 | +import com.sun.jersey.api.client.WebResource; |
| 24 | - | ||
| 25 | import org.hamcrest.Description; | 24 | import org.hamcrest.Description; |
| 26 | import org.hamcrest.Matchers; | 25 | import org.hamcrest.Matchers; |
| 27 | import org.hamcrest.TypeSafeMatcher; | 26 | import org.hamcrest.TypeSafeMatcher; |
| ... | @@ -44,24 +43,16 @@ import org.onosproject.net.intent.IntentService; | ... | @@ -44,24 +43,16 @@ import org.onosproject.net.intent.IntentService; |
| 44 | import org.onosproject.net.intent.IntentState; | 43 | import org.onosproject.net.intent.IntentState; |
| 45 | import org.onosproject.net.intent.Key; | 44 | import org.onosproject.net.intent.Key; |
| 46 | import org.onosproject.net.intent.MockIdGenerator; | 45 | import org.onosproject.net.intent.MockIdGenerator; |
| 46 | +import org.onosproject.rest.resources.CoreWebApplication; | ||
| 47 | 47 | ||
| 48 | -import com.eclipsesource.json.JsonArray; | 48 | +import javax.ws.rs.core.MediaType; |
| 49 | -import com.eclipsesource.json.JsonObject; | 49 | +import java.io.InputStream; |
| 50 | -import com.eclipsesource.json.JsonValue; | 50 | +import java.net.HttpURLConnection; |
| 51 | -import com.sun.jersey.api.client.ClientResponse; | 51 | +import java.util.Collections; |
| 52 | -import com.sun.jersey.api.client.UniformInterfaceException; | 52 | +import java.util.HashSet; |
| 53 | -import com.sun.jersey.api.client.WebResource; | ||
| 54 | 53 | ||
| 55 | -import static org.easymock.EasyMock.anyObject; | 54 | +import static org.easymock.EasyMock.*; |
| 56 | -import static org.easymock.EasyMock.createMock; | 55 | +import static org.hamcrest.Matchers.*; |
| 57 | -import static org.easymock.EasyMock.expect; | ||
| 58 | -import static org.easymock.EasyMock.expectLastCall; | ||
| 59 | -import static org.easymock.EasyMock.replay; | ||
| 60 | -import static org.easymock.EasyMock.verify; | ||
| 61 | -import static org.hamcrest.Matchers.containsString; | ||
| 62 | -import static org.hamcrest.Matchers.hasSize; | ||
| 63 | -import static org.hamcrest.Matchers.is; | ||
| 64 | -import static org.hamcrest.Matchers.notNullValue; | ||
| 65 | import static org.junit.Assert.assertThat; | 56 | import static org.junit.Assert.assertThat; |
| 66 | import static org.junit.Assert.fail; | 57 | import static org.junit.Assert.fail; |
| 67 | import static org.onosproject.net.intent.IntentTestsMocks.MockIntent; | 58 | import static org.onosproject.net.intent.IntentTestsMocks.MockIntent; |
| ... | @@ -76,6 +67,10 @@ public class IntentsResourceTest extends ResourceTest { | ... | @@ -76,6 +67,10 @@ public class IntentsResourceTest extends ResourceTest { |
| 76 | private static final ApplicationId APP_ID = new DefaultApplicationId(1, "test"); | 67 | private static final ApplicationId APP_ID = new DefaultApplicationId(1, "test"); |
| 77 | private IdGenerator mockGenerator; | 68 | private IdGenerator mockGenerator; |
| 78 | 69 | ||
| 70 | + public IntentsResourceTest() { | ||
| 71 | + super(CoreWebApplication.class); | ||
| 72 | + } | ||
| 73 | + | ||
| 79 | private class MockResource implements NetworkResource { | 74 | private class MockResource implements NetworkResource { |
| 80 | int id; | 75 | int id; |
| 81 | 76 | ... | ... |
| ... | @@ -18,6 +18,7 @@ package org.onosproject.rest; | ... | @@ -18,6 +18,7 @@ package org.onosproject.rest; |
| 18 | import java.io.IOException; | 18 | import java.io.IOException; |
| 19 | import java.net.ServerSocket; | 19 | import java.net.ServerSocket; |
| 20 | 20 | ||
| 21 | +import com.sun.jersey.spi.container.servlet.ServletContainer; | ||
| 21 | import com.sun.jersey.test.framework.AppDescriptor; | 22 | import com.sun.jersey.test.framework.AppDescriptor; |
| 22 | import com.sun.jersey.test.framework.JerseyTest; | 23 | import com.sun.jersey.test.framework.JerseyTest; |
| 23 | import com.sun.jersey.test.framework.WebAppDescriptor; | 24 | import com.sun.jersey.test.framework.WebAppDescriptor; |
| ... | @@ -28,6 +29,23 @@ import com.sun.jersey.test.framework.WebAppDescriptor; | ... | @@ -28,6 +29,23 @@ import com.sun.jersey.test.framework.WebAppDescriptor; |
| 28 | public class ResourceTest extends JerseyTest { | 29 | public class ResourceTest extends JerseyTest { |
| 29 | 30 | ||
| 30 | /** | 31 | /** |
| 32 | + * Creates a new web-resource test. | ||
| 33 | + */ | ||
| 34 | + public ResourceTest() { | ||
| 35 | + super(); | ||
| 36 | + } | ||
| 37 | + | ||
| 38 | + /** | ||
| 39 | + * Creates a new web-resource test initialized according to the specified | ||
| 40 | + * web application class. | ||
| 41 | + */ | ||
| 42 | + protected ResourceTest(Class<?> webAppClass) { | ||
| 43 | + super(new WebAppDescriptor.Builder("javax.ws.rs.Application", | ||
| 44 | + webAppClass.getCanonicalName()) | ||
| 45 | + .servletClass(ServletContainer.class).build()); | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + /** | ||
| 31 | * Assigns an available port for the test. | 49 | * Assigns an available port for the test. |
| 32 | * | 50 | * |
| 33 | * @param defaultPort If a port cannot be determined, this one is used. | 51 | * @param defaultPort If a port cannot be determined, this one is used. | ... | ... |
| ... | @@ -189,6 +189,10 @@ public class NetworkConfigWebResourceTest extends ResourceTest { | ... | @@ -189,6 +189,10 @@ public class NetworkConfigWebResourceTest extends ResourceTest { |
| 189 | } | 189 | } |
| 190 | } | 190 | } |
| 191 | 191 | ||
| 192 | + public NetworkConfigWebResourceTest() { | ||
| 193 | + super(CoreWebApplication.class); | ||
| 194 | + } | ||
| 195 | + | ||
| 192 | /** | 196 | /** |
| 193 | * Sets up mocked config service. | 197 | * Sets up mocked config service. |
| 194 | */ | 198 | */ | ... | ... |
-
Please register or login to post a comment