blob: 5d6b06dc98159e8c9fac3b12238e8c14263a5bf6 [file] [log] [blame]
Thomas Vachuskaa026be72015-12-07 16:00:37 -08001/*
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
17package org.onlab.rest;
18
19import com.google.common.collect.ImmutableSet;
20import org.onlab.rest.exceptions.BadRequestMapper;
21import org.onlab.rest.exceptions.EntityNotFoundMapper;
22import org.onlab.rest.exceptions.IllegalArgumentExceptionMapper;
23import org.onlab.rest.exceptions.IllegalStateExceptionMapper;
24import org.onlab.rest.exceptions.NotFoundMapper;
25import org.onlab.rest.exceptions.ServerErrorMapper;
26import org.onlab.rest.exceptions.ServiceNotFoundMapper;
27import org.onlab.rest.exceptions.WebApplicationExceptionMapper;
28
29import javax.ws.rs.core.Application;
30import java.util.Set;
31
32/**
33 * Base web application.
34 */
35public 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}