001/** 002 * Copyright 2015 DuraSpace, Inc. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.fcrepo.http.commons; 017 018import org.fcrepo.http.commons.session.SessionProvider; 019import org.glassfish.hk2.utilities.binding.AbstractBinder; 020import org.glassfish.jersey.filter.LoggingFilter; 021import org.glassfish.jersey.jackson.JacksonFeature; 022import org.glassfish.jersey.media.multipart.MultiPartFeature; 023import org.glassfish.jersey.server.ResourceConfig; 024import org.glassfish.jersey.process.internal.RequestScoped; 025 026import com.codahale.metrics.jersey2.InstrumentedResourceMethodApplicationListener; 027import com.codahale.metrics.MetricRegistry; 028import javax.jcr.Session; 029 030import java.util.logging.Logger; 031 032import static org.slf4j.LoggerFactory.getLogger; 033 034/** 035 * @author cabeer 036 * @since 9/22/14 037 */ 038public class FedoraApplication extends ResourceConfig { 039 040 private static final org.slf4j.Logger LOGGER = getLogger(FedoraApplication.class); 041 042 /** 043 * THIS IS OUR RESOURCE CONFIG! 044 */ 045 public FedoraApplication() { 046 super(); 047 packages("org.fcrepo"); 048 register(new FactoryBinder()); 049 register(MultiPartFeature.class); 050 register(JacksonFeature.class); 051 052 if (LOGGER.isDebugEnabled()) { 053 register(new LoggingFilter(Logger.getLogger(LoggingFilter.class.getName()), LOGGER.isTraceEnabled())); 054 } 055 056 register(new InstrumentedResourceMethodApplicationListener(new MetricRegistry())); 057 } 058 059 static class FactoryBinder extends AbstractBinder { 060 061 @Override 062 protected void configure() { 063 bindFactory(SessionProvider.class) 064 .to(Session.class) 065 .in(RequestScoped.class); 066 } 067 } 068}