com.blade.mvc.annotation.Path Java Examples
The following examples show how to use
com.blade.mvc.annotation.Path.
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: ClassPathClassReaderTest.java From blade with Apache License 2.0 | 6 votes |
@Test public void testClassPathReader() { String packageName = "com.blade.types.controller"; ClassReader classReader = DynamicContext.getClassReader(packageName); assertEquals(ClassPathClassReader.class, classReader.getClass()); Set<ClassInfo> classInfos = classReader.readClasses(Scanner.builder().packageName(packageName).build()); assertEquals(2, classInfos.size()); classInfos = classReader.readClasses(Scanner.builder().packageName(packageName).parent(Runnable.class).build()); assertEquals(1, classInfos.size()); assertEquals(UserService.class, classInfos.stream().findFirst().get().getClazz()); classInfos = classReader.readClasses(Scanner.builder().packageName(packageName).annotation(Path.class).build()); assertEquals(1, classInfos.size()); assertEquals(IndexController.class, classInfos.stream().findFirst().get().getClazz()); classInfos = classReader.readClasses(Scanner.builder().packageName(packageName).parent(Object.class).annotation(Path.class).build()); assertEquals(1, classInfos.size()); assertEquals(IndexController.class, classInfos.stream().findFirst().get().getClazz()); }
Example #2
Source File: ParameterInjectionExampleController.java From tutorials with MIT License | 6 votes |
@PostRoute("/params-file") // DO NOT USE A SLASH WITHIN THE ROUTE OR IT WILL BREAK (?) @JSON public RestResponse<?> fileParam(@MultipartParam FileItem fileItem) throws Exception { try { byte[] fileContent = fileItem.getData(); log.debug("Saving the uploaded file"); java.nio.file.Path tempFile = Files.createTempFile("baeldung_tempfiles", ".tmp"); Files.write(tempFile, fileContent, StandardOpenOption.WRITE); return RestResponse.ok(); } catch (Exception e) { log.error(e.getMessage(), e); return RestResponse.fail(e.getMessage()); } }
Example #3
Source File: AttachController.java From tale with MIT License | 5 votes |
@Route(value = "delete") @JSON public RestResponse delete(@Param Integer id, Request request) { try { Attach attach = new Attach().find(id); if (null == attach) { return RestResponse.fail("不存在该附件"); } String fkey = attach.getFkey(); siteService.cleanCache(Types.C_STATISTICS); String filePath = CLASSPATH.substring(0, CLASSPATH.length() - 1) + fkey; java.nio.file.Path path = Paths.get(filePath); log.info("Delete attach: [{}]", filePath); if (Files.exists(path)) { Files.delete(path); } attach.delete(id); new Logs(LogActions.DEL_ATTACH, fkey, request.address(), this.getUid()).save(); } catch (Exception e) { String msg = "附件删除失败"; if (e instanceof TipException) { msg = e.getMessage(); } else { log.error(msg, e); } return RestResponse.fail(msg); } return RestResponse.ok(); }
Example #4
Source File: NettyServer.java From blade with Apache License 2.0 | 4 votes |
private void parseAndCreate(Class<?> clazz) { if (null != clazz.getAnnotation(Bean.class) || null != clazz.getAnnotation(Value.class)) { blade.register(clazz); } if (null != clazz.getAnnotation(Path.class)) { if (null == blade.getBean(clazz)) { blade.register(clazz); } Object controller = blade.getBean(clazz); routeBuilder.addRouter(clazz, controller); } if (null != clazz.getAnnotation(Configuration.class) && clazz.getMethods().length > 0) { Object config = ReflectKit.newInstance(clazz); Arrays.stream(clazz.getMethods()) .filter(m -> m.getAnnotation(Bean.class) != null) .forEach(n -> { try { blade.register(n.invoke(config)); } catch (Exception e) { e.printStackTrace(); } }); } if (ReflectKit.hasInterface(clazz, WebHook.class) && null != clazz.getAnnotation(Bean.class)) { URLPattern URLPattern = clazz.getAnnotation(URLPattern.class); if (null == URLPattern) { routeBuilder.addWebHook(clazz, "/.*"); } else { Stream.of(URLPattern.values()) .forEach(pattern -> routeBuilder.addWebHook(clazz, pattern)); } } if (ReflectKit.hasInterface(clazz, BladeLoader.class) && null != clazz.getAnnotation(Bean.class)) { this.loaders.add((BladeLoader) blade.getBean(clazz)); } if (ReflectKit.hasInterface(clazz, BeanProcessor.class) && null != clazz.getAnnotation(Bean.class)) { this.processors.add((BeanProcessor) blade.getBean(clazz)); } if (isExceptionHandler(clazz)) { ExceptionHandler exceptionHandler = (ExceptionHandler) blade.getBean(clazz); blade.exceptionHandler(exceptionHandler); } WebSocket webSocket; if (null != (webSocket = clazz.getAnnotation(WebSocket.class))) { if (null == blade.getBean(clazz)) { blade.register(clazz); } if (ReflectKit.hasInterface(clazz, WebSocketHandler.class)) { blade.webSocket(webSocket.value(), (WebSocketHandler) blade.getBean(clazz)); } else { WebSocketHandlerWrapper wrapper = blade.getBean(WebSocketHandlerWrapper.class); if (wrapper == null) { wrapper = WebSocketHandlerWrapper.init(blade); blade.register(wrapper); } blade.webSocket(webSocket.value(), wrapper); wrapper.wrapHandler(webSocket.value(), clazz); } } }