本文整理汇总了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);
}
示例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);
}
示例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();
}
示例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);
}));
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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());
}
示例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);
}