All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.formkiq.server.api.AbstractRestController Maven / Gradle / Ivy

/*
 * Copyright (C) 2016 FormKiQ 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.formkiq.server.api;

import java.util.logging.Logger;

import javax.servlet.http.HttpServletRequest;

import org.springframework.http.MediaType;

import javassist.bytecode.stackmap.TypeData.ClassName;

/**
 * Abstract Rest Services controller.
 *
 */
public abstract class AbstractRestController {

    /** Valid Accept Header. */
    public static final MediaType ACCEPT_HEADER_V1
        = MediaType.valueOf("application/vnd.formkiq.v1+json");
    /** Admin Accept Header, skpis OAuth. */
    public static final MediaType ACCEPT_HEADER_ADMIN
        = MediaType.valueOf("application/vnd.formkiq.admin");

    /** Logger. */
    protected static final Logger LOG = Logger.getLogger(ClassName.class
            .getName());

    /**
	 * @param request HttpServletRequest
     * @return int
     */
    protected int getApiVersion(final HttpServletRequest request) {
        String accept = request.getHeader("Accept");

        if (accept.contains(ACCEPT_HEADER_V1.toString())) {
            return 1;
        }

        throw new InvalidMediaTypeException(
                "invalid accept header, must be " + ACCEPT_HEADER_V1);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy