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.HttpSession;
021import org.fcrepo.http.commons.session.SessionProvider;
022import org.glassfish.hk2.utilities.binding.AbstractBinder;
023import org.glassfish.jersey.jackson.JacksonFeature;
024import org.glassfish.jersey.logging.LoggingFeature;
025import org.glassfish.jersey.media.multipart.MultiPartFeature;
026import org.glassfish.jersey.server.ResourceConfig;
027import org.glassfish.jersey.process.internal.RequestScoped;
028
029import java.util.logging.Logger;
030
031import static org.slf4j.LoggerFactory.getLogger;
032
033/**
034 * @author cabeer
035 * @since 9/22/14
036 */
037public class FedoraApplication extends ResourceConfig {
038
039    private static final org.slf4j.Logger LOGGER = getLogger(FedoraApplication.class);
040
041    /**
042     * THIS IS OUR RESOURCE CONFIG!
043     */
044    public FedoraApplication() {
045        super();
046        packages("org.fcrepo");
047        register(new FactoryBinder());
048        register(MultiPartFeature.class);
049        register(JacksonFeature.class);
050
051        if (LOGGER.isDebugEnabled()) {
052            register(new LoggingFeature(Logger.getLogger(LoggingFeature.class.getName())));
053        }
054    }
055
056    static class FactoryBinder extends AbstractBinder {
057
058        @Override
059        protected void configure() {
060            bindFactory(SessionProvider.class)
061                    .to(HttpSession.class)
062                    .in(RequestScoped.class);
063        }
064    }
065}