Example usage for javax.servlet HttpConstraintElement HttpConstraintElement

List of usage examples for javax.servlet HttpConstraintElement HttpConstraintElement

Introduction

In this page you can find the example usage for javax.servlet HttpConstraintElement HttpConstraintElement.

Prototype

public HttpConstraintElement() 

Source Link

Document

Constructs a default HTTP constraint element

Usage

From source file:org.brutusin.rpc.RpcWebInitializer.java

private RpcServlet registerRpcServlet(ServletContext ctx) {
    LOGGER.info("Starting HTTP RPC runtime");
    RpcServlet servlet = new RpcServlet();
    ServletRegistration.Dynamic regInfo = ctx.addServlet(RpcServlet.class.getName(), servlet);
    ServletSecurityElement sec = new ServletSecurityElement(new HttpConstraintElement());
    regInfo.setServletSecurity(sec);//w  w  w  .ja va  2  s  .com
    regInfo.setLoadOnStartup(1);
    regInfo.addMapping(RpcConfig.getInstance().getPath() + "/http");
    return servlet;
}

From source file:com.jsmartframework.web.manager.ContextControl.java

private ServletSecurityElement getServletSecurityElement(ServletContext servletContext) {
    SecureMethod[] secureMethods = CONFIG.getContent().getSecureMethods();

    if (secureMethods != null && secureMethods.length > 0) {

        HttpConstraintElement constraint = new HttpConstraintElement();

        SecureMethod allMethods = CONFIG.getContent().getSecureMethod("*");
        Set<HttpMethodConstraintElement> methodConstraints = new HashSet<HttpMethodConstraintElement>();

        if (allMethods != null) {
            for (String method : METHODS) {
                HttpConstraintElement constraintElement = getHttpConstraintElement(allMethods);
                if (constraintElement != null) {
                    methodConstraints.add(new HttpMethodConstraintElement(method, constraintElement));
                }//from  ww  w  . j a v a  2 s . c  o m
            }

        } else {
            for (SecureMethod secureMethod : secureMethods) {
                HttpConstraintElement constraintElement = getHttpConstraintElement(secureMethod);
                if (constraintElement != null) {

                    if (secureMethod.getMethod() == null
                            || !METHODS.contains(secureMethod.getMethod().toUpperCase())) {
                        throw new RuntimeException(
                                "Method name declared in [secure-method] tag is unsupported! Supported values are HTTP methods.");
                    }
                    methodConstraints.add(new HttpMethodConstraintElement(
                            secureMethod.getMethod().toUpperCase(), constraintElement));
                }
            }
        }

        return new ServletSecurityElement(constraint, methodConstraints);
    }

    return null;
}