Thomas Vachuska | a026be7 | 2015-12-07 16:00:37 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
Thomas Vachuska | a026be7 | 2015-12-07 16:00:37 -0800 | [diff] [blame] | 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 | } |