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