com.netflix.exhibitor.servlet.ExhibitorResourceConfig Maven / Gradle / Ivy
The newest version!
/*
* Copyright 2012 Netflix, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.netflix.exhibitor.servlet;
import com.netflix.exhibitor.core.Exhibitor;
import com.netflix.exhibitor.core.rest.UIContext;
import com.netflix.exhibitor.core.rest.jersey.JerseySupport;
import com.sun.jersey.api.core.DefaultResourceConfig;
import com.sun.jersey.api.core.ResourceConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.servlet.ServletContext;
import javax.ws.rs.core.Application;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import java.util.List;
import java.util.Map;
import java.util.Set;
public class ExhibitorResourceConfig extends ResourceConfig
{
@SuppressWarnings("FieldCanBeLocal")
private final Logger log = LoggerFactory.getLogger(getClass());
private final DefaultResourceConfig config;
public ExhibitorResourceConfig(@Context ServletContext context)
{
DefaultResourceConfig localConfig;
Exhibitor exhibitor = (Exhibitor)context.getAttribute(ExhibitorServletContextListener.class.getName());
if ( exhibitor != null )
{
log.info("Adding Exhibitor Jersey resources");
localConfig = JerseySupport.newApplicationConfig(new UIContext(exhibitor));
}
else
{
log.info("Using DefaultResourceConfig");
localConfig = new DefaultResourceConfig();
}
config = localConfig;
}
@Override
public Set> getClasses()
{
return config.getClasses();
}
@Override
public Set