001/*
002 * Copyright (c) 2015 Maxim Yunusov
003 *    Licensed under the Apache License, Version 2.0 (the "License");
004 *    you may not use this file except in compliance with the License.
005 *    You may obtain a copy of the License at
006 *
007 *        http://www.apache.org/licenses/LICENSE-2.0
008 *
009 *    Unless required by applicable law or agreed to in writing, software
010 *    distributed under the License is distributed on an "AS IS" BASIS,
011 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012 *    See the License for the specific language governing permissions and
013 *    limitations under the License.
014 */
015
016package org.maxur.perfmodel.backend.rest;
017
018import org.glassfish.jersey.ServiceLocatorProvider;
019import org.glassfish.jersey.jackson.JacksonFeature;
020import org.glassfish.jersey.server.ResourceConfig;
021
022import javax.ws.rs.core.Feature;
023import javax.ws.rs.core.FeatureContext;
024
025/**
026 * Rest Service Configuration
027 *
028 * @author myunusov
029 * @version 1.0
030 * @since <pre>30.08.2015</pre>
031 */
032public class RestServiceConfig extends ResourceConfig {
033
034    public RestServiceConfig() {
035        packages("org.maxur.perfmodel.backend.rest.resources");
036        register(JacksonFeature.class);
037        register(PmcObjectMapperProvider.class);
038        register(RuntimeExceptionHandler.class);
039        register(new ServiceLocatorFeature());
040    }
041
042    static class ServiceLocatorFeature implements Feature {
043
044        @Override
045        public boolean configure(FeatureContext context) {
046            ServiceLocatorProvider.getServiceLocator(context);
047            return true;
048        }
049    }
050
051}