blob: 41839c75e9fe77aa7e0c405f187849be4ba2d269 [file] [log] [blame]
Thomas Vachuskaa026be72015-12-07 16:00:37 -08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
Thomas Vachuskaa026be72015-12-07 16:00:37 -08003 *
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
17package org.onlab.rest;
18
19import com.google.common.collect.ImmutableSet;
20import org.onlab.rest.exceptions.BadRequestMapper;
21import org.onlab.rest.exceptions.EntityNotFoundMapper;
Thomas Vachuska67484d92018-07-17 11:51:54 -070022import org.onlab.rest.exceptions.ForbiddenMapper;
Thomas Vachuskaa026be72015-12-07 16:00:37 -080023import org.onlab.rest.exceptions.IllegalArgumentExceptionMapper;
24import org.onlab.rest.exceptions.IllegalStateExceptionMapper;
25import org.onlab.rest.exceptions.NotFoundMapper;
26import org.onlab.rest.exceptions.ServerErrorMapper;
27import org.onlab.rest.exceptions.ServiceNotFoundMapper;
28import org.onlab.rest.exceptions.WebApplicationExceptionMapper;
29
30import javax.ws.rs.core.Application;
31import java.util.Set;
32
33/**
34 * Base web application.
35 */
36public abstract class AbstractWebApplication extends Application {
37
38 /**
39 * Returns the aggregate set of resources, writers and mappers combined
40 * with a default set of such web entities.
41 *
42 * @param classes set of resources, writers and mappers
43 * @return combined set of web entities
44 */
45 protected Set<Class<?>> getClasses(Class<?>... classes) {
46 ImmutableSet.Builder<Class<?>> builder = ImmutableSet.builder();
Thomas Vachuska67484d92018-07-17 11:51:54 -070047 builder.add(AuthorizationFilter.class,
48 ForbiddenMapper.class,
49 ServiceNotFoundMapper.class,
Thomas Vachuskaa026be72015-12-07 16:00:37 -080050 EntityNotFoundMapper.class,
51 NotFoundMapper.class,
52 ServerErrorMapper.class,
53 BadRequestMapper.class,
54 WebApplicationExceptionMapper.class,
55 IllegalArgumentExceptionMapper.class,
56 IllegalStateExceptionMapper.class,
Thomas Vachuskaa026be72015-12-07 16:00:37 -080057 JsonBodyWriter.class);
58 builder.add(classes);
59 return builder.build();
60 }
61
62 @Override
63 public abstract Set<Class<?>> getClasses();
64
65}