開発メモ

開発用のメモです。

HTTPメソッドをPOSTのみに制限するInterceptor

import org.apache.commons.lang3.StringUtils;
import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

public class PostInterceptor extends AbstractInterceptor {

    @Override
    public String intercept(ActionInvocation invocation) throws Exception {
        if (StringUtils.endsWithIgnoreCase("post", ServletActionContext.getRequest().getMethod())) {
            return invocation.invoke();
        }
        return ActionSupport.INPUT;
    }

}
Twitter: @asahina_alice