当前位置: 首页>>代码示例>>Java>>正文


Java Config类代码示例

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


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

示例1: makeFormHandler

import ninja.siden.Config; //导入依赖的package包/类
protected HttpHandler makeFormHandler(App root, OptionMap config,
		HttpHandler next) {
	FormParserFactory.Builder builder = FormParserFactory.builder(false);
	FormEncodedDataDefinition form = new FormEncodedDataDefinition();
	String cn = config.get(Config.CHARSET).name();
	form.setDefaultEncoding(cn);

	MultiPartParserDefinition mult = new MultiPartParserDefinition(
			config.get(Config.TEMP_DIR));
	mult.setDefaultEncoding(cn);
	mult.setMaxIndividualFileSize(config.get(Config.MAX_FILE_SIZE));

	builder.addParsers(form, mult);

	EagerFormParsingHandler efp = new EagerFormParsingHandler(
			builder.build());
	return efp.setNext(next);
}
 
开发者ID:taichi,项目名称:siden,代码行数:19,代码来源:DefaultAppBuilder.java

示例2: testEspeciallyPkgsAreNotRender

import ninja.siden.Config; //导入依赖的package包/类
@Test
public void testEspeciallyPkgsAreNotRender() throws Exception {
	this.exchange.putAttachment(Core.CONFIG, Config.defaults().getMap());
	this.exchange.putAttachment(Core.RESPONSE, new SidenResponse(
			this.exchange));

	RoutingHandler target = new RoutingHandler(Testing.empty());
	target.add(Predicates.truePredicate(),
			(q, s) -> s.cookie("hoge", "fuga"),
			new MockUp<Renderer<Object>>() {
				@Mock(invocations = 0)
				void render(Object model, HttpServerExchange sink)
						throws IOException {
				}
			}.getMockInstance());

	target.handleRequest(this.exchange);
}
 
开发者ID:taichi,项目名称:siden,代码行数:19,代码来源:RoutingHandlerTest.java

示例3: main

import ninja.siden.Config; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
	App app = App.configure(conf -> {
		conf.set(Config.RENDERER_REPOSITORY, new HandleBarsRepo());
		return conf;
	});

	// see. https://github.com/jknack/handlebars.java
	Handlebars engine = new Handlebars();
	Template t = engine.compileInline("Hello {{this}}!");

	// use handlebars simply
	app.get("/bars",
			(req, res) -> res.render("john", Renderer.of(t::apply)));

	// read template from templates/say/hello.html
	app.get("/hello",
			(req, res) -> res.render(new User("peter"), "say/hello"));
	
	app.listen().addShutdownHook();
}
 
开发者ID:taichi,项目名称:siden,代码行数:21,代码来源:UseHandlebars.java

示例4: identicon

import ninja.siden.Config; //导入依赖的package包/类
public Object identicon(Request req, Response res) throws Exception {
	String seed = req.params("seed").orElse("0000000");
	String type = req.params("type")
			.filter(s -> types.contains(s.toLowerCase())).orElse("png");
	int size = req.query("s").filter(s -> s.matches("\\d{1,3}"))
			.map(Integer::parseInt).filter(i -> i < 4097).orElse(48);

	MimeMappings mm = req.raw().getAttachment(Core.CONFIG)
			.get(Config.MIME_MAPPINGS);
	res.type(mm.getMimeType(type));

	return res.render(seed, Renderer.ofStream((p, os) -> {
		render(seed, size, type, os);
	}));
}
 
开发者ID:taichi,项目名称:sirusi,代码行数:16,代码来源:Sirusi.java

示例5: makeSessionHandler

import ninja.siden.Config; //导入依赖的package包/类
@Override
protected HttpHandler makeSessionHandler(App root, OptionMap config,
		HttpHandler next) {
	InMemorySessionManager sessionManager = new InMemorySessionManager(
			"SessionManagerOfSiden", config.get(Config.MAX_SESSIONS));
	sessionManager.setDefaultSessionTimeout(config
			.get(Config.DEFAULT_SESSION_TIMEOUT_SECONDS));
	SessionCookieConfig sessionConfig = new SessionCookieConfig();
	sessionConfig.setCookieName(config.get(Config.SESSION_COOKIE_NAME));

	register(root, SessionMetrics.to(sessionManager),
			Arrays.asList("type", "Session"));

	return new SessionAttachmentHandler(next, sessionManager, sessionConfig);
}
 
开发者ID:taichi,项目名称:siden,代码行数:16,代码来源:MetricsAppBuilder.java

示例6: render

import ninja.siden.Config; //导入依赖的package包/类
@Override
public void render(Object model, HttpServerExchange sink)
		throws IOException {
	Reader reader = (Reader) model;
	SecurityHandler.addContentType(sink);
	OptionMap config = sink.getAttachment(Core.CONFIG);
	delegate.render(
			new ReaderInputStream(reader, config.get(Config.CHARSET)),
			sink);
}
 
开发者ID:taichi,项目名称:siden,代码行数:11,代码来源:RendererSelector.java

示例7: handleRequest

import ninja.siden.Config; //导入依赖的package包/类
@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
	OptionMap config = exchange.getAttachment(Core.CONFIG);
	HeaderMap rh = exchange.getResponseHeaders();

	rh.add(SecurityHeaders.FRAME_OPTIONS, config.get(Config.FRAME_OPTIONS));

	if (config.get(Config.USE_XSS_PROTECTION)) {
		rh.add(SecurityHeaders.XSS_PROTECTION, "1; mode=block");
	}

	if (config.get(Config.USE_CONTENT_TYPE_OPTIONS)) {
		rh.add(SecurityHeaders.CONTENT_TYPE_OPTIONS, "nosniff");
	}

	exchange.addExchangeCompleteListener((ex, next) -> {
		try {
			if (rh.contains(Headers.CONTENT_TYPE) == false
					&& rh.contains(Headers.SEC_WEB_SOCKET_ACCEPT) == false) {

				LOG.warn(ex.getRequestURI()
						+ " Content-Type header doesn't exist.");
			}
		} finally {
			next.proceed();
		}
	});

	next.handleRequest(exchange);
}
 
开发者ID:taichi,项目名称:siden,代码行数:31,代码来源:SecurityHandler.java

示例8: parseCharset

import ninja.siden.Config; //导入依赖的package包/类
static Charset parseCharset(HttpServerExchange exchange) {
	// TODO support force charset
	OptionMap config = exchange.getAttachment(Core.CONFIG);
	Charset defaultCs = config.get(Config.CHARSET);
	String cs = exchange.getRequestCharset();
	if (defaultCs.displayName().equalsIgnoreCase(cs) == false && cs != null
			&& Charset.isSupported(cs)) {
		return Charset.forName(cs);
	}
	return defaultCs;
}
 
开发者ID:taichi,项目名称:siden,代码行数:12,代码来源:SidenRequest.java

示例9: resolve

import ninja.siden.Config; //导入依赖的package包/类
@SuppressWarnings("unchecked")
Renderer<Object> resolve(Renderer<?> renderer, HttpServerExchange exchange) {
	if (renderer == null) {
		OptionMap config = exchange.getAttachment(Core.CONFIG);
		return config.get(Config.DEFAULT_RENDERER);
	}
	return (Renderer<Object>) renderer;
}
 
开发者ID:taichi,项目名称:siden,代码行数:9,代码来源:RoutingHandler.java

示例10: addTo

import ninja.siden.Config; //导入依赖的package包/类
public void addTo(PathHandler ph, OptionMap config) {
	ResourceHandler rh = new ResourceHandler(newResourceManager(config));
	rh.setMimeMappings(config.get(Config.MIME_MAPPINGS));
	if (this.cacheTime != null) {
		rh.setCacheTime(this.cacheTime);
	}
	rh.setDirectoryListingEnabled(this.directoryListing);
	rh.setCanonicalizePaths(this.canonicalizePaths);
	if (this.welcomeFiles != null) {
		rh.setWelcomeFiles(this.welcomeFiles);
	}

	ph.addPrefixPath(this.path, rh);
}
 
开发者ID:taichi,项目名称:siden,代码行数:15,代码来源:AssetDef.java

示例11: newResourceManager

import ninja.siden.Config; //导入依赖的package包/类
protected ResourceManager newResourceManager(OptionMap config) {
	if (this.loadFrom == null) {
		return new FileResourceManager(new File(this.root),
				config.get(Config.TRANSFER_MIN_SIZE));
	}
	return new ClassPathResourceManager(this.loadFrom, this.root);
}
 
开发者ID:taichi,项目名称:siden,代码行数:8,代码来源:AssetDef.java

示例12: makeSharedHandlers

import ninja.siden.Config; //导入依赖的package包/类
protected HttpHandler makeSharedHandlers(App root, OptionMap config,
		HttpHandler next) {
	HttpHandler hh = next;
	if (config.get(Config.METHOD_OVERRIDE)) {
		hh = new MethodOverrideHandler(hh);
	}
	hh = makeSessionHandler(root, config, hh);
	hh = makeFormHandler(root, config, hh);

	if (Config.isInDev(config)) {
		hh = Handlers.disableCache(hh);
	} else {
		GracefulShutdownHandler gsh = Handlers.gracefulShutdown(hh);
		root.stopOn(app -> {
			gsh.shutdown();
			try {
				gsh.awaitShutdown(config.get(
						Config.WAIT_FOR_GRACEFUL_SHUTDOWN, 500));
			} catch (InterruptedException e) {
				// ignore
			}
		});
		hh = gsh;
	}

	hh = new SecurityHandler(hh);
	return new Core(config, hh);
}
 
开发者ID:taichi,项目名称:siden,代码行数:29,代码来源:DefaultAppBuilder.java

示例13: makeSessionHandler

import ninja.siden.Config; //导入依赖的package包/类
protected HttpHandler makeSessionHandler(App root, OptionMap config,
		HttpHandler next) {
	InMemorySessionManager sessionManager = new InMemorySessionManager(
			"SessionManagerOfSiden", config.get(Config.MAX_SESSIONS));
	sessionManager.setDefaultSessionTimeout(config
			.get(Config.DEFAULT_SESSION_TIMEOUT_SECONDS));
	SessionCookieConfig sessionConfig = new SessionCookieConfig();
	sessionConfig.setCookieName(config.get(Config.SESSION_COOKIE_NAME));
	return new SessionAttachmentHandler(next, sessionManager, sessionConfig);
}
 
开发者ID:taichi,项目名称:siden,代码行数:11,代码来源:DefaultAppBuilder.java

示例14: setUp

import ninja.siden.Config; //导入依赖的package包/类
@Before
public void setUp() {
	this.exchange = new HttpServerExchange(null);
	this.exchange.putAttachment(Core.CONFIG, Config.defaults().getMap());

	this.target = new SecurityHandler(Testing.mustCall());
}
 
开发者ID:taichi,项目名称:siden,代码行数:8,代码来源:SecurityHandlerTest.java

示例15: testResponseCodeSettigIsOnce

import ninja.siden.Config; //导入依赖的package包/类
@Test
public void testResponseCodeSettigIsOnce() throws Exception {
	this.exchange = new MockUp<HttpServerExchange>() {
		@Mock
		public boolean isInIoThread() {
			return false;
		}

		@Mock
		public HeaderMap getResponseHeaders() {
			return new HeaderMap();
		}

		@Mock(invocations = 1)
		public HttpServerExchange setResponseCode(final int responseCode) {
			return getMockInstance();
		}

		@Mock(invocations = 1)
		public HttpServerExchange endExchange() {
			return getMockInstance();
		}
	}.getMockInstance();

	this.exchange.putAttachment(Core.CONFIG, Config.defaults().getMap());
	this.exchange.putAttachment(Core.RESPONSE, new SidenResponse(
			this.exchange));

	RoutingHandler target = new RoutingHandler(Testing.empty());
	target.add(Predicates.truePredicate(),
			(q, s) -> s.redirect("/hoge/fuga/moge"), null);

	target.handleRequest(this.exchange);
}
 
开发者ID:taichi,项目名称:siden,代码行数:35,代码来源:RoutingHandlerTest.java


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