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


Java Request类代码示例

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


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

示例1: imgs

import ninja.siden.Request; //导入依赖的package包/类
@Test
public void imgs() throws Exception {
	String content = "Bob->Alice : hello";
	String encoded = Uml.transcoder().encode(content);
	Request request = new MockUp<Request>() {
		@Mock
		Optional<String> params(String key) {
			return Optional.of(encoded);
		}
	}.getMockInstance();
	Response response = new MockUp<Response>() {

		@Mock
		Response type(String contentType) {
			return this.getMockInstance();
		}

		@Mock(invocations = 1)
		Object render(Object model, Renderer<Object> renderer) {
			return this.getMockInstance();
		}
	}.getMockInstance();
	Object result = this.target.imgs(request, response);
	assertNotNull(result);
}
 
开发者ID:taichi,项目名称:umlbot,代码行数:26,代码来源:UmlTest.java

示例2: testSimpleCall

import ninja.siden.Request; //导入依赖的package包/类
@Test
public void testSimpleCall() throws Exception {
	Filter filter = new MockUp<Filter>() {
		@Mock(invocations = 2)
		public void filter(Request req, Response res, FilterChain chain)
				throws Exception {
			chain.next();
		}
	}.getMockInstance();

	FiltersHandler target = new FiltersHandler(Testing.mustCall());
	target.add(new FilterDef(Predicates.truePredicate(), filter));
	target.add(new FilterDef(Predicates.falsePredicate(),
			(req, res, ch) -> {
				throw new AssertionError();
			}));
	target.add(new FilterDef(Predicates.truePredicate(), filter));

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

示例3: identicon

import ninja.siden.Request; //导入依赖的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

示例4: imgs

import ninja.siden.Request; //导入依赖的package包/类
Object imgs(Request request, Response response) throws Exception {
	return request.params("encoded").map(Trial.of(transcoder()::decode))
			.map(t -> t.either(SourceStringReader::new, ex -> {
				LOG.fatal(ex.getMessage(), ex);
				return null;
			}))
			.map(v -> response.type("image/png").render(v,
					Renderer.ofStream((m, os) -> m.generateImage(os, new FileFormatOption(FileFormat.PNG, false)))))
			.orElse(404);
}
 
开发者ID:taichi,项目名称:umlbot,代码行数:11,代码来源:Uml.java

示例5: outgoing

import ninja.siden.Request; //导入依赖的package包/类
@Test
public void outgoing() throws Exception {
	Map<String, String> map = new HashMap<>();
	map.put("token", TOKEN);
	map.put("trigger_word", "@startuml");
	String content = "hogehoge";
	map.put("text", "@startuml\n" + content + "\[email protected]");

	Request request = new MockUp<Request>() {
		@Mock
		Optional<String> form(String key) {
			return Optional.ofNullable(map.get(key));
		}
	}.getMockInstance();
	Response response = new MockUp<Response>() {
	}.getMockInstance();
	Object obj = this.target.outgoing(request, response);
	assertNotNull(obj);
	System.out.println(obj);
	Msg msg = JsonFactory.fromJson(obj.toString(), Msg.class);
	assertNotNull(msg.text);
	assertTrue(msg.text.startsWith(HOST));

	Transcoder t = Uml.transcoder();
	String enc = t.encode(content);
	assertTrue(msg.text.endsWith(enc));
}
 
开发者ID:taichi,项目名称:umlbot,代码行数:28,代码来源:UmlTest.java

示例6: handle

import ninja.siden.Request; //导入依赖的package包/类
boolean handle(HttpServerExchange exchange, Route fn, Renderer<?> renderer)
		throws Exception {
	try {
		Request request = exchange.getAttachment(Core.REQUEST);
		Response response = exchange.getAttachment(Core.RESPONSE);
		Object model = fn.handle(request, response);
		if (model != null) {
			if (model instanceof Optional) {
				@SuppressWarnings("unchecked")
				Optional<Object> opt = (Optional<Object>) model;
				model = opt.map(v -> v).orElse(null);
			}
			if (model instanceof Integer) {
				return handle((Integer) model, exchange);
			}
			if (model instanceof ExchangeState) {
				return true;
			}
			if (model != null && contains(model.getClass()) == false) {
				resolve(renderer, exchange).render(model, exchange);
				return true;
			}
		}
		return handle(exchange.getResponseCode(), exchange);
	} catch (Exception ex) {
		if (exchange.isRequestChannelAvailable()) {
			if (handle(ex, exchange)) {
				return true;
			}
		}
		throw ex;
	}
}
 
开发者ID:taichi,项目名称:siden,代码行数:34,代码来源:RoutingHandler.java

示例7: handle

import ninja.siden.Request; //导入依赖的package包/类
@Override
public Object handle(Request request, Response response) throws Exception {
	return totalResult.apply(m -> original.handle(request, response));
}
 
开发者ID:taichi,项目名称:siden,代码行数:5,代码来源:RouteTracker.java

示例8: adapt

import ninja.siden.Request; //导入依赖的package包/类
public static io.undertow.predicate.Predicate adapt(Predicate<Request> fn) {
	return exchange -> {
		Request request = exchange.getAttachment(Core.REQUEST);
		return fn.test(request);
	};
}
 
开发者ID:taichi,项目名称:siden,代码行数:7,代码来源:Core.java

示例9: filter

import ninja.siden.Request; //导入依赖的package包/类
@Override
public void filter(Request req, Response res, FilterChain chain)
		throws Exception {
	this.filter.filter(req, res, chain);
}
 
开发者ID:taichi,项目名称:siden,代码行数:6,代码来源:FilterDef.java

示例10: match

import ninja.siden.Request; //导入依赖的package包/类
@Override
public RoutingCustomizer match(java.util.function.Predicate<Request> fn) {
	this.matches = Predicates.and(this.matches, Core.adapt(fn));
	return this;
}
 
开发者ID:taichi,项目名称:siden,代码行数:6,代码来源:RoutingDef.java

示例11: main

import ninja.siden.Request; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
	App app = new App();

	// simple get
	app.get("/hello", (req, res) -> "Hello world !!");

	// receive Ajax request only
	app.get("/ajax", (req, res) -> "{ 'name' : 'ajax' }").match(
			Request::xhr);

	// simple logging filter
	app.use((req, res, chain) -> {
		System.out.printf("%s %s %n", req.method(), req.path());
		chain.next();
	});

	// exception handling
	class MyException extends Exception {
		private static final long serialVersionUID = -2530468497731983302L;

		public String extramessage() {
			return "MyException has come!!";
		}
	}
	app.error(MyException.class, (ex, req, res) -> {
		return ex.extramessage();
	});

	app.get("/err", (req, res) -> {
		throw new MyException();
	});

	// response code handling
	app.error(402, (req, res) -> "Payment Required. Payment Required!!");
	app.get("/402", (req, res) -> 402);
	app.get("/payment", (req, res) -> res.status(402));

	// json api on top of Boon JSON
	// see. https://github.com/boonproject/boon
	app.get("/users/:name", (req, res) -> req.params("name").map(User::new))
			.render(Renderer.of(JsonFactory::toJson))
			.type("application/json");

	// use static resources
	// GET /javascripts/jquery.js
	// GET /style.css
	// GET /favicon.ico
	app.assets("/", "assets/");

	// GET /static/javascripts/jquery.js
	// GET /static/style.css
	// GET /static/favicon.ico
	app.assets("/static", "assets/");
	
	app.get("/", (req, res) -> "Siden Example Application is running.");

	// sub application
	App sub = new App();
	// GET /secret/admin
	sub.get("/admin", (req, res) -> "I'm in secret area");
	app.use("/secret", sub);

	app.listen().addShutdownHook();
}
 
开发者ID:taichi,项目名称:siden,代码行数:65,代码来源:Main.java


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