• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Jooby类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.jooby.Jooby的典型用法代码示例。如果您正苦于以下问题:Java Jooby类的具体用法?Java Jooby怎么用?Java Jooby使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Jooby类属于org.jooby包,在下文中一共展示了Jooby类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: process

import org.jooby.Jooby; //导入依赖的package包/类
private void process(final Jooby app, final Path srcdir, final Path bindir) {
  getLogger().info("Source: {}", srcdir);
  getLogger().info("Output: {}", bindir);
  RouteProcessor processor = new RouteProcessor();
  String[] name = app.getClass().getPackage().getName().split("\\.");
  Path outdir = bindir;
  for (String n : name) {
    outdir = outdir.resolve(n);
  }
  String routes = processor.compile(app, srcdir, outdir).stream()
      .map(RouteSpec::toString)
      .collect(Collectors.joining("\n"));
  getLogger().debug(app.getClass().getSimpleName() + ".spec :\n" + routes);
  // update task output
  throw new Done();
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:17,代码来源:SpecTask.java


示例2: contextInitialized

import org.jooby.Jooby; //导入依赖的package包/类
@Override
public void contextInitialized(final ServletContextEvent sce) {
  ServletContext ctx = sce.getServletContext();
  String appClass = ctx.getInitParameter("application.class");
  requireNonNull(appClass, "Context param NOT found: application.class");
  try {

    Jooby app = (Jooby) ctx.getClassLoader().loadClass(appClass).newInstance();

    app.use(ConfigFactory.empty()
        .withValue("application.path", ConfigValueFactory.fromAnyRef(ctx.getContextPath()))
        .withValue("server.module", ConfigValueFactory.fromAnyRef(ServletModule.class.getName())));

    app.start();

    ctx.setAttribute(Jooby.class.getName(), app);

  } catch (Throwable ex) {
    throw new IllegalStateException("App didn't to start: " + appClass, ex);
  }

}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:23,代码来源:ServerInitializer.java


示例3: contextDestroyed

import org.jooby.Jooby; //导入依赖的package包/类
@SuppressWarnings({"rawtypes" })
@Test
public void contextDestroyed() throws Exception {
  new MockUnit(ServletContextEvent.class)
      .expect(unit -> {
        Class appClass = Jooby.class;
        String appClassname = appClass.getName();

        Jooby app = unit.mock(Jooby.class);
        app.stop();

        ServletContext ctx = unit.mock(ServletContext.class);
        expect(ctx.getAttribute(appClassname)).andReturn(app);

        ServletContextEvent sce = unit.get(ServletContextEvent.class);
        expect(sce.getServletContext()).andReturn(ctx);
      })
      .run(unit -> {
        new ServerInitializer().contextDestroyed(unit.get(ServletContextEvent.class));
      });
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:22,代码来源:ServerInitializerTest.java


示例4: contextDestroyedShouldIgnoreMissingAttr

import org.jooby.Jooby; //导入依赖的package包/类
@SuppressWarnings({"rawtypes" })
@Test
public void contextDestroyedShouldIgnoreMissingAttr() throws Exception {
  new MockUnit(ServletContextEvent.class)
      .expect(unit -> {
        Class appClass = Jooby.class;
        String appClassname = appClass.getName();

        ServletContext ctx = unit.mock(ServletContext.class);
        expect(ctx.getAttribute(appClassname)).andReturn(null);

        ServletContextEvent sce = unit.get(ServletContextEvent.class);
        expect(sce.getServletContext()).andReturn(ctx);
      })
      .run(unit -> {
        new ServerInitializer().contextDestroyed(unit.get(ServletContextEvent.class));
      });
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:19,代码来源:ServerInitializerTest.java


示例5: bodyParam

import org.jooby.Jooby; //导入依赖的package包/类
@Test
public void bodyParam() throws Exception {

  Jooby app = new BodyParam();

  RouteProcessor processor = new RouteProcessor();
  List<RouteSpec> routes = processor.process(app, basedir);
  assertEquals(1, routes.size());
  RouteSpec route = routes.get(0);
  assertEquals("POST", route.method());
  assertEquals("/create", route.pattern());
  assertEquals(1, route.params().size());
  assertEquals("<body>", route.params().get(0).name());
  assertEquals(RouteParamType.BODY, route.params().get(0).paramType());
  assertEquals("apps.LocalType", route.params().get(0).type().getTypeName());
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:17,代码来源:RouteProcessorTest.java


示例6: defInt

import org.jooby.Jooby; //导入依赖的package包/类
@Test
public void defInt() throws Exception {
  RouteProcessor processor = new RouteProcessor();

  Jooby app = new DefInt();

  List<RouteSpec> routes = processor.process(app, basedir);
  assertEquals(1, routes.size());
  RouteSpec route = routes.get(0);
  assertEquals("GET", route.method());
  assertEquals("/", route.pattern());
  assertEquals("int", route.response().type().getTypeName());

  assertEquals(2, route.params().size());
  assertEquals("start", route.params().get(0).name());
  assertEquals(RouteParamType.QUERY, route.params().get(0).paramType());
  assertEquals("int", route.params().get(0).type().getTypeName());
  assertEquals(0, route.params().get(0).value());
  assertTrue(route.params().get(0).optional());

  assertEquals("max", route.params().get(1).name());
  assertEquals(RouteParamType.QUERY, route.params().get(1).paramType());
  assertEquals("int", route.params().get(1).type().getTypeName());
  assertEquals(200, route.params().get(1).value());
  assertTrue(route.params().get(1).optional());
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:27,代码来源:RouteProcessorTest.java


示例7: defStr

import org.jooby.Jooby; //导入依赖的package包/类
@Test
public void defStr() throws Exception {
  RouteProcessor processor = new RouteProcessor();

  Jooby app = new DefStr();

  List<RouteSpec> routes = processor.process(app, basedir);
  assertEquals(1, routes.size());
  RouteSpec route = routes.get(0);
  assertEquals("GET", route.method());
  assertEquals("/", route.pattern());
  assertEquals("java.lang.String", route.response().type().getTypeName());

  assertEquals(1, route.params().size());
  assertEquals("value", route.params().get(0).name());
  assertEquals(RouteParamType.QUERY, route.params().get(0).paramType());
  assertEquals("java.lang.String", route.params().get(0).type().getTypeName());
  assertEquals("value", route.params().get(0).value());
  assertTrue(route.params().get(0).optional());
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:21,代码来源:RouteProcessorTest.java


示例8: defBool

import org.jooby.Jooby; //导入依赖的package包/类
@Test
public void defBool() throws Exception {
  RouteProcessor processor = new RouteProcessor();

  Jooby app = new DefBool();

  List<RouteSpec> routes = processor.process(app, basedir);
  assertEquals(1, routes.size());
  RouteSpec route = routes.get(0);
  assertEquals("GET", route.method());
  assertEquals("/", route.pattern());
  assertEquals("boolean", route.response().type().getTypeName());

  assertEquals(2, route.params().size());
  assertEquals("t", route.params().get(0).name());
  assertEquals(RouteParamType.QUERY, route.params().get(0).paramType());
  assertEquals("boolean", route.params().get(0).type().getTypeName());
  assertEquals(true, route.params().get(0).value());
  assertTrue(route.params().get(0).optional());

  assertEquals("f", route.params().get(1).name());
  assertEquals(RouteParamType.QUERY, route.params().get(1).paramType());
  assertEquals("boolean", route.params().get(1).type().getTypeName());
  assertEquals(false, route.params().get(1).value());
  assertTrue(route.params().get(1).optional());
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:27,代码来源:RouteProcessorTest.java


示例9: defDouble

import org.jooby.Jooby; //导入依赖的package包/类
@Test
public void defDouble() throws Exception {
  RouteProcessor processor = new RouteProcessor();

  Jooby app = new DefDouble();

  List<RouteSpec> routes = processor.process(app, basedir);
  assertEquals(1, routes.size());
  RouteSpec route = routes.get(0);
  assertEquals("GET", route.method());
  assertEquals("/", route.pattern());
  assertEquals("double", route.response().type().getTypeName());

  assertEquals(1, route.params().size());
  assertEquals("d", route.params().get(0).name());
  assertEquals(RouteParamType.QUERY, route.params().get(0).paramType());
  assertEquals("double", route.params().get(0).type().getTypeName());
  assertEquals(3.7, route.params().get(0).value());
  assertTrue(route.params().get(0).optional());
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:21,代码来源:RouteProcessorTest.java


示例10: appOverride

import org.jooby.Jooby; //导入依赖的package包/类
@Test
public void appOverride() throws Exception {

  RouteProcessor processor = new RouteProcessor();

  Jooby app = new AppOverride();

  List<RouteSpec> specs = processor.process(app, basedir);

  assertEquals(2, specs.size());

  RouteSpec route = specs.get(0);
  assertEquals("DELETE", route.method());
  assertEquals("/:id", route.pattern());
  assertEquals("void", route.response().type().getTypeName());
  assertEquals(204, route.response().statusCode());

  route = specs.get(1);
  assertEquals("POST", route.method());
  assertEquals("/", route.pattern());
  assertEquals("apps.model.Pet", route.response().type().getTypeName());
  assertEquals(201, route.response().statusCode());

}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:25,代码来源:AppOverrideTest.java


示例11: scanGuiceModule

import org.jooby.Jooby; //导入依赖的package包/类
@Test
public void scanGuiceModule() throws Exception {
  new MockUnit(Env.class, Config.class, Binder.class, Router.class)
      .expect(ns("app.ns"))
      .expect(runtimeProcessors)
      .expect(scanResult("app.ns", "com.google.inject"))
      .expect(routes)
      .expect(annotations(Path.class))
      .expect(subClassesOf(Jooby.class))
      .expect(appclass(ScannerTest.class.getName()))
      .expect(implementing(Module.class, GuiceModule.class.getName()))
      .expect(unit -> {
        Binder binder = unit.get(Binder.class);
        expect(binder.bind(GuiceModule.class)).andReturn(null);
      })
      .run(unit -> {
        new Scanner()
            .scan(Module.class)
            .configure(unit.get(Env.class), unit.get(Config.class), unit.get(Binder.class));
      });
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:22,代码来源:ScannerTest.java


示例12: scanEmptyGuavaService

import org.jooby.Jooby; //导入依赖的package包/类
@Test
public void scanEmptyGuavaService() throws Exception {
  new MockUnit(Env.class, Config.class, Binder.class, Router.class, Registry.class)
      .expect(ns("app.ns"))
      .expect(runtimeProcessors)
      .expect(scanResult("app.ns", "com.google.common.util.concurrent"))
      .expect(routes)
      .expect(annotations(Path.class))
      .expect(subClassesOf(Jooby.class))
      .expect(appclass(ScannerTest.class.getName()))
      .expect(implementing(Service.class))
      .run(unit -> {
        new Scanner()
            .scan(Service.class)
            .configure(unit.get(Env.class), unit.get(Config.class), unit.get(Binder.class));
      });
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:18,代码来源:ScannerTest.java


示例13: scanShouldIgnoreAbsClasses

import org.jooby.Jooby; //导入依赖的package包/类
@Test
public void scanShouldIgnoreAbsClasses() throws Exception {
  new MockUnit(Env.class, Config.class, Binder.class, Router.class)
      .expect(ns("app.ns"))
      .expect(runtimeProcessors)
      .expect(scanResult("app.ns"))
      .expect(routes)
      .expect(
          annotations(Path.class, AbsController.class.getName()))
      .expect(subClassesOf(Jooby.class))
      .expect(appclass(ScannerTest.class.getName()))
      .run(unit -> {
        new Scanner()
            .configure(unit.get(Env.class), unit.get(Config.class), unit.get(Binder.class));
      });
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:17,代码来源:ScannerTest.java


示例14: shouldThrowBootstrapException

import org.jooby.Jooby; //导入依赖的package包/类
@Test
public void shouldThrowBootstrapException() {
  IllegalStateException ies = new IllegalStateException("boot err");
  try {
    new Jooby() {
      {
        throwBootstrapException();

        onStart(() -> {
          throw ies;
        });
      }
    }.start();
    fail();
  } catch (Err err) {
    assertEquals(Status.SERVICE_UNAVAILABLE.value(), err.statusCode());
    assertEquals(ies, err.getCause());
  }
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:20,代码来源:Issue576.java


示例15: run

import org.jooby.Jooby; //导入依赖的package包/类
public void run(final String mainClass, final BiConsumer<Jooby, Config> callback, final String... args)
    throws Throwable {
  ClassLoader global = Thread.currentThread().getContextClassLoader();
  try (URLClassLoader local = project.newClassLoader()) {
    Thread.currentThread().setContextClassLoader(local);
    if (mainClass == null) {
      throw new IllegalArgumentException("Main class missing. Please set, like: mainClassName = \"my.App\"");
    }
    Jooby app = (Jooby) local.loadClass(mainClass).newInstance();
    Config conf = Jooby.exportConf(app);
    callback.accept(app, conf);
  } finally {
    Thread.currentThread().setContextClassLoader(global);
  }
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:16,代码来源:JoobyContainer.java


示例16: contextDestroyed

import org.jooby.Jooby; //导入依赖的package包/类
@Override
public void contextDestroyed(final ServletContextEvent sce) {
  ServletContext ctx = sce.getServletContext();
  Jooby app = (Jooby) ctx.getAttribute(Jooby.class.getName());
  if (app != null) {
    app.stop();
  }
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:9,代码来源:ServerInitializer.java


示例17: init

import org.jooby.Jooby; //导入依赖的package包/类
@Override
public void init(final ServletConfig config) throws ServletException {
  super.init(config);

  ServletContext ctx = config.getServletContext();

  Jooby app = (Jooby) ctx.getAttribute(Jooby.class.getName());

  dispatcher = app.require(HttpHandler.class);
  tmpdir = app.require(Config.class).getString("application.tmpdir");
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:12,代码来源:ServletHandler.java


示例18: contextInitialized

import org.jooby.Jooby; //导入依赖的package包/类
@SuppressWarnings({"rawtypes", "unchecked" })
@Test
public void contextInitialized() throws Exception {
  new MockUnit(ServletContextEvent.class)
      .expect(unit -> {
        Class appClass = Jooby.class;
        String appClassname = appClass.getName();

        ClassLoader loader = unit.mock(ClassLoader.class);
        expect(loader.loadClass(appClassname)).andReturn(appClass);

        ServletContext ctx = unit.mock(ServletContext.class);
        expect(ctx.getInitParameter("application.class")).andReturn(appClassname);
        expect(ctx.getClassLoader()).andReturn(loader);
        expect(ctx.getContextPath()).andReturn("/");
        ctx.setAttribute(eq(Jooby.class.getName()), isA(Jooby.class));

        ServletContextEvent sce = unit.get(ServletContextEvent.class);
        expect(sce.getServletContext()).andReturn(ctx);
      })
      .run(unit -> {
        try {
        ServerInitializer initializer = new ServerInitializer();
        initializer.contextInitialized(unit.get(ServletContextEvent.class));
        } catch (Throwable ex) {
          ex.printStackTrace();
        }
      });
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:30,代码来源:ServerInitializerTest.java


示例19: contextInitializedShouldReThrowException

import org.jooby.Jooby; //导入依赖的package包/类
@SuppressWarnings({"rawtypes" })
@Test(expected = IllegalStateException.class)
public void contextInitializedShouldReThrowException() throws Exception {
  new MockUnit(ServletContextEvent.class)
      .expect(
          unit -> {
            Class appClass = Jooby.class;
            String appClassname = appClass.getName();

            ClassLoader loader = unit.mock(ClassLoader.class);
            expect(loader.loadClass(appClassname)).andThrow(
                new ClassNotFoundException("intentional err"));

            ServletContext ctx = unit.mock(ServletContext.class);
            expect(ctx.getInitParameter("application.class")).andReturn(appClassname);
            expect(ctx.getClassLoader()).andReturn(loader);
            expect(ctx.getContextPath()).andReturn("/");
            ctx.setAttribute(eq(Jooby.class.getName()), isA(Jooby.class));

            ServletContextEvent sce = unit.get(ServletContextEvent.class);
            expect(sce.getServletContext()).andReturn(ctx);
          })
      .run(unit -> {
        ServerInitializer initializer = new ServerInitializer();
        initializer.contextInitialized(unit.get(ServletContextEvent.class));
      });
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:28,代码来源:ServerInitializerTest.java


示例20: SwaggerBuilder

import org.jooby.Jooby; //导入依赖的package包/类
@Inject
public SwaggerBuilder(@Named("application.class") final Class<? extends Jooby> appClass,
    final Set<Route.Definition> routes,
    @Named("swagger") final Config config,
    @Named("swagger") final ObjectMapper mapper) {
  requireNonNull(appClass, "App class is required.");
  requireNonNull(routes, "Routes are required.");
  this.routes = ImmutableList.copyOf(routes);
  this.appClass = appClass;
  this.config = requireNonNull(config, "Swagger config is required.");
  this.mapper = requireNonNull(mapper, "Mapper is required.");
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:13,代码来源:SwaggerBuilder.java



注:本文中的org.jooby.Jooby类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Contract类代码示例发布时间:2022-05-22
下一篇:
Java Event类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap