Java Code Examples for com.blade.mvc.WebContext#init()
The following examples show how to use
com.blade.mvc.WebContext#init() .
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: NettyServer.java From blade with Apache License 2.0 | 5 votes |
@Override public void start(Blade blade) throws Exception { this.blade = blade; this.environment = blade.environment(); this.processors = blade.processors(); this.loaders = blade.loaders(); long startMs = System.currentTimeMillis(); int padSize = 16; log.info("{} {}{}", StringKit.padRight("app.env", padSize), getPrefixSymbol(), environment.get(ENV_KEY_APP_ENV, "default")); log.info("{} {}{}", StringKit.padRight("app.pid", padSize), getPrefixSymbol(), BladeKit.getPID()); log.info("{} {}{}", StringKit.padRight("app.devMode", padSize), getPrefixSymbol(), blade.devMode()); log.info("{} {}{}", StringKit.padRight("jdk.version", padSize), getPrefixSymbol(), System.getProperty("java.version")); log.info("{} {}{}", StringKit.padRight("user.dir", padSize), getPrefixSymbol(), System.getProperty("user.dir")); log.info("{} {}{}", StringKit.padRight("java.io.tmpdir", padSize), getPrefixSymbol(), System.getProperty("java.io.tmpdir")); log.info("{} {}{}", StringKit.padRight("user.timezone", padSize), getPrefixSymbol(), System.getProperty("user.timezone")); log.info("{} {}{}", StringKit.padRight("file.encoding", padSize), getPrefixSymbol(), System.getProperty("file.encoding")); log.info("{} {}{}", StringKit.padRight("app.classpath", padSize), getPrefixSymbol(), CLASSPATH); this.initConfig(); String contextPath = environment.get(ENV_KEY_CONTEXT_PATH, "/"); WebContext.init(blade, contextPath); this.initIoc(); this.watchEnv(); this.startServer(startMs); this.sessionCleaner(); this.startTask(); this.shutdownHook(); }
Example 2
Source File: BasicAuthMiddlewareTest.java From blade with Apache License 2.0 | 5 votes |
@Test public void testAuthSuccess() throws Exception { Request mockRequest = mockHttpRequest("GET"); WebContext.init(Blade.of(), "/"); Map<String, String> headers = new HashMap<>(); headers.put("Authorization", "Basic YWRtaW46MTIzNDU2"); when(mockRequest.parameters()).thenReturn(new HashMap<>()); when(mockRequest.headers()).thenReturn(headers); Request request = new HttpRequest(mockRequest); Response response = mockHttpResponse(200); RouteContext context = new RouteContext(request, response); context.initRoute(Route.builder() .action(AuthHandler.class.getMethod("handle", RouteContext.class)) .targetType(AuthHandler.class) .target(new AuthHandler()).build()); WebContext.set(new WebContext(request, response, null)); AuthOption authOption = AuthOption.builder().build(); authOption.addUser("admin", "123456"); BasicAuthMiddleware basicAuthMiddleware = new BasicAuthMiddleware(authOption); boolean flag = basicAuthMiddleware.before(context); assertTrue(flag); }
Example 3
Source File: BasicAuthMiddlewareTest.java From blade with Apache License 2.0 | 5 votes |
@Test public void testAuthFail() throws Exception { Request mockRequest = mockHttpRequest("GET"); WebContext.init(Blade.of(), "/"); Map<String, String> headers = new HashMap<>(); headers.put("Authorization", "Basic YmxhZGU6YmxhZGUyMg=="); when(mockRequest.parameters()).thenReturn(new HashMap<>()); when(mockRequest.headers()).thenReturn(headers); Request request = new HttpRequest(mockRequest); Response response = mockHttpResponse(200); RouteContext context = new RouteContext(request, response); context.initRoute(Route.builder() .action(AuthHandler.class.getMethod("handle", RouteContext.class)) .targetType(AuthHandler.class) .target(new AuthHandler()).build()); WebContext.set(new WebContext(request, response, null)); AuthOption authOption = AuthOption.builder().build(); authOption.addUser("admin", "123456"); BasicAuthMiddleware basicAuthMiddleware = new BasicAuthMiddleware(authOption); boolean flag = basicAuthMiddleware.before(context); assertFalse(flag); }
Example 4
Source File: ExceptionHandlerTest.java From blade with Apache License 2.0 | 5 votes |
@Before public void before() { request = mock(Request.class); when(request.header("Accept")).thenReturn("text/html"); response = mock(Response.class); WebContext.init(Blade.me(), "/"); WebContext.set(new WebContext(request, response, null)); }
Example 5
Source File: BaseTestCase.java From blade with Apache License 2.0 | 5 votes |
protected com.blade.mvc.http.HttpRequest mockHttpRequest(String methodName) { WebContext.init(Blade.of(),"/"); com.blade.mvc.http.HttpRequest request = mock(com.blade.mvc.http.HttpRequest.class); when(request.method()).thenReturn(methodName); when(request.url()).thenReturn("/"); when(request.uri()).thenReturn("/"); when(request.httpMethod()).thenReturn(HttpMethod.valueOf(methodName)); return request; }