Java Code Examples for org.osgl.http.H#Method

The following examples show how to use org.osgl.http.H#Method . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Router.java    From actframework with Apache License 2.0 6 votes vote down vote up
private Node root(H.Method method, boolean reportError) {
    switch (method) {
        case GET:
            return _GET;
        case POST:
            return _POST;
        case PUT:
            return _PUT;
        case DELETE:
            return _DEL;
        case PATCH:
            return _PATCH;
        default:
            if (reportError) {
                throw E.unexpected("HTTP Method not supported: %s", method);
            }
            return null;
    }
}
 
Example 2
Source File: Router.java    From actframework with Apache License 2.0 6 votes vote down vote up
private Node _search(H.Method method, String path) {
    Node node = root(method);
    assert node != null;
    E.unsupportedIf(null == node, "Method %s is not supported", method);
    if (path.length() == 1 && path.charAt(0) == '/') {
        return node;
    }
    String sUrl = path;
    List<String> paths = Path.tokenize(Unsafe.bufOf(sUrl));
    int len = paths.size();
    for (int i = 0; i < len - 1; ++i) {
        node = node.findChild(paths.get(i));
        if (null == node) return null;
    }
    return node.findChild(paths.get(len - 1));
}
 
Example 3
Source File: CSRF.java    From actframework with Apache License 2.0 5 votes vote down vote up
/**
 * Do sanity check to see if CSRF token is present. This method
 * is called before session resolved
 *
 * @param context the current context
 */
public void preCheck(ActionContext context) {
    if (!enabled) {
        return;
    }
    H.Method method = context.req().method();
    if (method.safe()) {
        return;
    }
    String token = retrieveCsrfToken(context);
    if (S.blank(token)) {
        raiseCsrfNotVerified(context);
    }
}
 
Example 4
Source File: Router.java    From actframework with Apache License 2.0 5 votes vote down vote up
public String reverseRoute(String action, Map<String, Object> args) {
    String fullAction = inferFullActionPath(action);
    for (H.Method m : supportedHttpMethods()) {
        String url = reverseRoute(fullAction, m, args);
        if (null != url) {
            return ensureUrlContext(url);
        }
    }
    return null;
}
 
Example 5
Source File: ControllerByteCodeScanner.java    From actframework with Apache License 2.0 5 votes vote down vote up
public ActionAnnotationVisitor(AnnotationVisitor av, H.Method method, boolean isUtil, boolean staticMethod, boolean noDefPath) {
    super(ASM5, av);
    if (null != method) {
        httpMethods.add(method);
    }
    this.isUtil = isUtil;
    this.isStatic = staticMethod;
    this.noDefPath = noDefPath;
}
 
Example 6
Source File: ControllerByteCodeScanner.java    From actframework with Apache License 2.0 5 votes vote down vote up
RouteRegister(
        $.Var<Boolean> envMatched, List<H.Method> methods, List<String> paths, String methodName,
        List<Router> routers, ControllerClassMetaInfo classInfo, boolean noRegister, $.Var<Boolean> isVirtual
) {
    this.routers = routers;
    this.paths = paths;
    this.methodName = methodName;
    this.classInfo = classInfo;
    this.httpMethods = methods;
    this.noRegister = noRegister;
    this.isVirtual = isVirtual;
    this.envMatched = envMatched;
    this.probeSourceInfo();
}
 
Example 7
Source File: Endpoint.java    From actframework with Apache License 2.0 5 votes vote down vote up
private ParamInfo(H.Method httpMethod, String bindName, BeanSpec beanSpec, String description, String fieldKey, boolean pathVar, boolean body) {
    this.bindName = bindName;
    this.beanSpec = beanSpec;
    this.httpMethod = httpMethod;
    this.description = description;
    this.defaultValue = checkDefaultValue(beanSpec);
    this.required = checkRequired(beanSpec);
    this.sessionVariable = checkSessionVariable(beanSpec);
    this.headerVariable = checkHeaderVariable(beanSpec);
    this.options = checkOptions(beanSpec);
    this.fieldKey = fieldKey;
    this.pathVar = pathVar;
    this.body = body;
}
 
Example 8
Source File: RouteInfo.java    From actframework with Apache License 2.0 5 votes vote down vote up
public static RouteInfo of(ActionContext context) {
    H.Method m = context.req().method();
    String path = context.req().url();
    RequestHandler handler = context.handler();
    if (null == handler) {
        handler = UNKNOWN_HANDLER;
    }
    return new RouteInfo(m, path, handler);
}
 
Example 9
Source File: Router.java    From actframework with Apache License 2.0 4 votes vote down vote up
public void addMapping(H.Method method, String path, String action) {
    addMapping(method, withUrlContext(path, action), resolveActionHandler(action), RouteSource.ROUTE_TABLE);
}
 
Example 10
Source File: ControllerByteCodeScannerTest.java    From actframework with Apache License 2.0 4 votes vote down vote up
private void verifyRouting(String url, String controller, String action, H.Method... methods) {
    for (H.Method method : methods) {
        verify(mockRouter).addMapping(method, url, "testapp.controller." + controller + "." + action, ACTION_ANNOTATION);
    }
}
 
Example 11
Source File: RequestImplBase.java    From actframework with Apache License 2.0 4 votes vote down vote up
private H.Method _method() {
    return H.Method.valueOfIgnoreCase(methodName());
}
 
Example 12
Source File: Endpoint.java    From actframework with Apache License 2.0 4 votes vote down vote up
public H.Method getHttpMethod() {
    return httpMethod;
}
 
Example 13
Source File: Router.java    From actframework with Apache License 2.0 4 votes vote down vote up
boolean isMapped(H.Method method, String path) {
    return null != _search(method, path);
}
 
Example 14
Source File: UnknownHttpMethodProcessor.java    From actframework with Apache License 2.0 4 votes vote down vote up
@Override
public Result handle(H.Method method) {
    return org.osgl.mvc.result.NotImplemented.INSTANCE;
}
 
Example 15
Source File: RouteInfo.java    From actframework with Apache License 2.0 4 votes vote down vote up
public RouteInfo(H.Method method, String path, RequestHandler handler, RouteSource routeSource) {
    this(method, path, handler);
    this.routeSource = $.requireNotNull(routeSource);
}
 
Example 16
Source File: EndpointTester.java    From actframework with Apache License 2.0 4 votes vote down vote up
public H.Method method() {
    return this.method;
}
 
Example 17
Source File: MockRequest.java    From actframework with Apache License 2.0 4 votes vote down vote up
public MockRequest(AppConfig config, H.Method method, String url) {
    super(config);
    this.method = method;
    this.url = url;
}
 
Example 18
Source File: MockRequest.java    From actframework with Apache License 2.0 4 votes vote down vote up
@Override
public H.Method method() {
    return null;
}
 
Example 19
Source File: Router.java    From actframework with Apache License 2.0 2 votes vote down vote up
/**
 * Visit a route mapping in the router
 *
 * @param method
 *         the HTTP method
 * @param path
 *         the URL path
 * @param source
 *         the route source
 * @param varNames
 *         the URL path variable name list
 * @param handler
 *         the handler
 */
void visit(H.Method method, String path, RouteSource source, Set<String> varNames, RequestHandler handler);
 
Example 20
Source File: ControllerPlugin.java    From actframework with Apache License 2.0 votes vote down vote up
protected abstract Map<Class<? extends Annotation>, H.Method> annotationMethodLookup();