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

net.craftforge.essential.controller.resolvers.DefaultMethodResolver Maven / Gradle / Ivy

The newest version!
/*
 * This file is part of essential.
 *
 *     essential is free software: you can redistribute it and/or modify
 *     it under the terms of the GNU General Public License as published by
 *     the Free Software Foundation, either version 3 of the License, or
 *     (at your option) any later version.
 *
 *     essential is distributed in the hope that it will be useful,
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *     GNU General Public License for more details.
 *
 *     You should have received a copy of the GNU General Public License
 *     along with essential.  If not, see .
 */

package net.craftforge.essential.controller.resolvers;

import net.craftforge.essential.context.Request;
import net.craftforge.essential.core.constants.HttpMethods;

import javax.inject.Inject;

/**
 * {@inheritDoc}
 *
 * @author Christian Bick
 * @since 28.11.11
 */
public class DefaultMethodResolver implements MethodResolver {

    private Request request;

    @Inject
    public DefaultMethodResolver(Request request) {
        this.request = request;
    }

    /**
     * {@inheritDoc}
     *
     * Uses the HTTP method of the request if not overridden
     * in the URL info part. (e.g. my/path.put)
     *
     * @return The HTTP method
     */
    public String getHttpMethod() {
        String urlInfoPart = request.getUrlResourcePart();
        if (urlInfoPart.contains(".get")) {
            return HttpMethods.GET;
        } else if (urlInfoPart.contains(".post")) {
            return HttpMethods.POST;
        } else if (urlInfoPart.contains(".put")) {
            return HttpMethods.PUT;
        } else if (urlInfoPart.contains(".delete")) {
            return HttpMethods.DELETE;
        } else if (urlInfoPart.contains(".head")) {
            return HttpMethods.HEAD;
        } else if (urlInfoPart.contains(".options")) {
            return HttpMethods.OPTIONS;
        } else if (urlInfoPart.contains(".trace")) {
            return HttpMethods.TRACE;
        }
        return request.getHttpMethod().toUpperCase();
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy