本文整理汇总了Java中org.takes.rs.RsWithStatus类的典型用法代码示例。如果您正苦于以下问题:Java RsWithStatus类的具体用法?Java RsWithStatus怎么用?Java RsWithStatus使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RsWithStatus类属于org.takes.rs包,在下文中一共展示了RsWithStatus类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: route
import org.takes.rs.RsWithStatus; //导入依赖的package包/类
@Override
public final Opt<Response> route(final RqFallback req) throws IOException {
return new Opt.Single<>(
new RsWithStatus(
new RsHtml(
new RsVelocity(
TkApp.class.getResource("error.html.vm"),
new RsVelocity.Pair(
"err",
new TextOf(req.throwable()).asString()
),
new RsVelocity.Pair(
"rev",
Manifests.read("Rehttp-Revision")
)
)
),
HttpURLConnection.HTTP_INTERNAL_ERROR
)
);
}
开发者ID:yegor256,项目名称:rehttp,代码行数:22,代码来源:TkFatal.java
示例2: make
import org.takes.rs.RsWithStatus; //导入依赖的package包/类
private static Take make(final Take take) {
return new TkFallback(
take,
new FbChain(
new FbStatus(
HttpURLConnection.HTTP_NOT_FOUND,
new RsWithStatus(
new RsText("endpoint with this path not found"),
HttpURLConnection.HTTP_NOT_FOUND
)
),
new FbStatus(
HttpURLConnection.HTTP_BAD_REQUEST,
new RsWithStatus(
new RsText("bad request"),
HttpURLConnection.HTTP_BAD_REQUEST
)
),
req -> new Opt.Empty<>(),
req -> new Opt.Single<>(fatal(req))
)
);
}
开发者ID:yaroska,项目名称:true_oop,代码行数:24,代码来源:TkAppFallback.java
示例3: fatal
import org.takes.rs.RsWithStatus; //导入依赖的package包/类
/**
* Make fatal error page.
* @param req Request
* @return Response
* @throws IOException If fails
*/
private static Response fatal(final RqFallback req) throws IOException {
return new RsWithStatus(
new RsHtml(
new RsVelocity(
TkApp.class.getResource("error.html.vm"),
new RsVelocity.Pair(
"err",
new TextOf(req.throwable()).asString()
),
new RsVelocity.Pair("rev", TkApp.REV)
)
),
HttpURLConnection.HTTP_INTERNAL_ERROR
);
}
开发者ID:yegor256,项目名称:threecopies,代码行数:22,代码来源:TkApp.java
示例4: fatal
import org.takes.rs.RsWithStatus; //导入依赖的package包/类
/**
* Make fatal error page.
* @param req Request
* @return Response
* @throws IOException If fails
*/
private static Response fatal(final RqFallback req) throws IOException {
return new RsWithStatus(
new RsWithType(
new RsVelocity(
TkAppFallback.class.getResource("error.html.vm"),
new RsVelocity.Pair(
"err",
ExceptionUtils.getStackTrace(req.throwable())
),
new RsVelocity.Pair("rev", TkAppFallback.REV)
),
"text/html"
),
HttpURLConnection.HTTP_INTERNAL_ERROR
);
}
开发者ID:yegor256,项目名称:jare,代码行数:23,代码来源:TkAppFallback.java
示例5: fatal
import org.takes.rs.RsWithStatus; //导入依赖的package包/类
/**
* Make fatal error page.
* @param req Request
* @return Response
* @throws IOException If fails
*/
private static Response fatal(final RqFallback req) throws IOException {
return new RsWithStatus(
new RsWithType(
new RsVelocity(
TkAppFallback.class.getResource("error.html.vm"),
new RsVelocity.Pair(
"err",
ExceptionUtils.getStackTrace(req.throwable())
),
new RsVelocity.Pair("rev", TkAppFallback.REV),
new RsVelocity.Pair("version", TkAppFallback.VERSION)
),
"text/html"
),
HttpURLConnection.HTTP_INTERNAL_ERROR
);
}
开发者ID:yegor256,项目名称:wring,代码行数:24,代码来源:TkAppFallback.java
示例6: FbStatus
import org.takes.rs.RsWithStatus; //导入依赖的package包/类
/**
* Ctor.
* @param check HTTP status code predicate
* @since 0.16.10
*/
public FbStatus(final Condition<Integer> check) {
this(check, new Fallback() {
@Override
public Opt<Response> route(final RqFallback req)
throws IOException {
final Response res = new RsWithStatus(req.code());
return new Opt.Single<Response>(
new RsWithType(
new RsWithBody(
res,
String.format(
"%s: %s", WHITESPACE.split(
res.head().iterator().next(),
2
)[1], req.throwable().getLocalizedMessage()
)
), "text/plain"
)
);
}
});
}
开发者ID:yegor256,项目名称:takes,代码行数:28,代码来源:FbStatus.java
示例7: RsXembly
import org.takes.rs.RsWithStatus; //导入依赖的package包/类
/**
* Ctor.
* @param dom DOM node to build upon
* @param src Source
*/
public RsXembly(final Node dom, final XeSource src) {
super(
new Response() {
@Override
public Iterable<String> head() throws IOException {
return new RsWithType(
new RsWithStatus(
new RsEmpty(),
HttpURLConnection.HTTP_OK
),
"text/xml"
).head();
}
@Override
public InputStream body() throws IOException {
return RsXembly.render(dom, src);
}
}
);
}
开发者ID:yegor256,项目名称:takes,代码行数:26,代码来源:RsXembly.java
示例8: exitTest
import org.takes.rs.RsWithStatus; //导入依赖的package包/类
/**
* PsByFlag wraps response with authenticated user.
* @throws IOException If some problem inside
*/
@Test
public void exitTest() throws IOException {
final Response response = new RsWithStatus(
new RsWithType(
new RsWithBody("<html>This is test response</html>"),
"text/html"
),
HttpURLConnection.HTTP_OK
);
MatcherAssert.assertThat(
new PsByFlag(
ImmutableMap.<Pattern, Pass>of(
Pattern.compile("key"), new PsFake(true)
)
).exit(response, Mockito.mock(Identity.class)),
Matchers.is(response)
);
}
开发者ID:yegor256,项目名称:takes,代码行数:23,代码来源:PsByFlagTest.java
示例9: FbError
import org.takes.rs.RsWithStatus; //导入依赖的package包/类
/**
* Ctor.
*/
public FbError() {
super(
new Fallback() {
@Override
public Opt<Response> route(final RqFallback req) {
final String exc = ExceptionUtils.getStackTrace(
req.throwable()
);
return new Opt.Single<Response>(
new RsWithStatus(
new RsText(
String.format(
"oops, something went wrong!\n%s",
exc
)
),
req.code()
)
);
}
}
);
}
开发者ID:libreio,项目名称:libre,代码行数:27,代码来源:FbError.java
示例10: fatal
import org.takes.rs.RsWithStatus; //导入依赖的package包/类
/**
* Make a fatal response.
* @param req Request
* @return Response
* @throws IOException If fails
*/
private static Response fatal(final RqFallback req) throws IOException {
final String err = ExceptionUtils.getStackTrace(
req.throwable()
);
Logger.error(TkAppFallback.class, "%[exception]s", req.throwable());
return new RsWithStatus(
new RsWithType(
new RsVelocity(
TkAppFallback.class.getResource("error.html.vm"),
new RsVelocity.Pair("error", err),
new RsVelocity.Pair("version", TkAppFallback.VERSION)
),
"text/html"
),
HttpURLConnection.HTTP_INTERNAL_ERROR
);
}
开发者ID:yegor256,项目名称:thindeck,代码行数:24,代码来源:TkAppFallback.java
示例11: TkSafe
import org.takes.rs.RsWithStatus; //导入依赖的package包/类
/**
* Ctor.
* @param take Original take
*/
public TkSafe(final Take take) {
this.take = new TkFallback(
take,
new FbChain(
new FbStatus(
HttpURLConnection.HTTP_NOT_FOUND,
new RsWithStatus(
new RsText("Page not found"),
HttpURLConnection.HTTP_NOT_FOUND
)
),
new FbStatus(
HttpURLConnection.HTTP_BAD_REQUEST,
new RsWithStatus(
new RsText("Bad request"),
HttpURLConnection.HTTP_BAD_REQUEST
)
),
req -> {
Sentry.capture(req.throwable());
return new Opt.Empty<>();
},
req -> new TkFatal().route(req)
)
);
}
开发者ID:yegor256,项目名称:rehttp,代码行数:31,代码来源:TkSafe.java
示例12: act
import org.takes.rs.RsWithStatus; //导入依赖的package包/类
@Override
public Response act(Request req) throws IOException {
long categoryId = Long.parseLong(((RqRegex) req).matcher().group("ctgId"));
long productId = Long.parseLong(((RqRegex) req).matcher().group("prdId"));
Category category = base.categories().category(categoryId);
Product product = base.products().product(productId);
base.categoryProducts(category).remove(product);
return new RsWithStatus(HttpURLConnection.HTTP_NO_CONTENT);
}
开发者ID:yaroska,项目名称:true_oop,代码行数:12,代码来源:TkCategoryProductDelete.java
示例13: act
import org.takes.rs.RsWithStatus; //导入依赖的package包/类
@Override
public Response act(Request req) throws IOException {
long categoryId = Long.parseLong(((RqRegex) req).matcher().group("number"));
Category category = base.categories().category(categoryId);
JsonReader reader = Json.createReader(req.body());
Product[] products = reader.readArray().stream()
.map(JsonValue::asJsonObject)
.map(product -> product.getInt("id"))
.map(id -> base.products().product(id))
.toArray(Product[]::new);
base.categoryProducts(category).add(products);
return new RsWithStatus(HttpURLConnection.HTTP_NO_CONTENT);
}
开发者ID:yaroska,项目名称:true_oop,代码行数:14,代码来源:TkCategoryProductsAdd.java
示例14: act
import org.takes.rs.RsWithStatus; //导入依赖的package包/类
@Override
public Response act(Request req) throws IOException {
long categoryId = Long.parseLong(((RqRegex) req).matcher().group("ctgId"));
long productId = Long.parseLong(((RqRegex) req).matcher().group("prdId"));
Category category = base.categories().category(categoryId);
Product product = base.products().product(productId);
base.categoryProducts(category).add(product);
return new RsWithStatus(HttpURLConnection.HTTP_NO_CONTENT);
}
开发者ID:yaroska,项目名称:true_oop,代码行数:12,代码来源:TkCategoryProductAdd.java
示例15: act
import org.takes.rs.RsWithStatus; //导入依赖的package包/类
@Override
public Response act(Request req) throws IOException {
long number = Long.parseLong(((RqRegex) req).matcher().group("number"));
Product product = base.products().product(number);
base.products().delete(product);
return new RsWithStatus(HttpURLConnection.HTTP_NO_CONTENT);
}
开发者ID:yaroska,项目名称:true_oop,代码行数:9,代码来源:TkProductDelete.java
示例16: act
import org.takes.rs.RsWithStatus; //导入依赖的package包/类
@Override
public Response act(Request req) throws IOException {
long number = Long.parseLong(((RqRegex) req).matcher().group("number"));
Category category = base.categories().category(number);
base.categories().delete(category);
return new RsWithStatus(HttpURLConnection.HTTP_NO_CONTENT);
}
开发者ID:yaroska,项目名称:true_oop,代码行数:9,代码来源:TkCategoryDelete.java
示例17: safe
import org.takes.rs.RsWithStatus; //导入依赖的package包/类
/**
* With fallback.
* @param take Takes
* @return Safe takes
*/
private static Take safe(final Take take) {
return new TkFallback(
take,
new FbChain(
new FbStatus(
HttpURLConnection.HTTP_NOT_FOUND,
(Fallback) req -> new Opt.Single<>(
new RsWithStatus(
new RsText(req.throwable().getLocalizedMessage()),
HttpURLConnection.HTTP_NOT_FOUND
)
)
),
new FbStatus(
HttpURLConnection.HTTP_BAD_REQUEST,
(Fallback) req -> new Opt.Single<>(
new RsWithStatus(
new RsText(req.throwable().getLocalizedMessage()),
HttpURLConnection.HTTP_BAD_REQUEST
)
)
),
req -> {
Sentry.capture(req.throwable());
return new Opt.Empty<>();
},
req -> new Opt.Single<>(TkApp.fatal(req))
)
);
}
开发者ID:yegor256,项目名称:threecopies,代码行数:36,代码来源:TkApp.java
示例18: make
import org.takes.rs.RsWithStatus; //导入依赖的package包/类
/**
* Authenticated.
* @param take Takes
* @return Authenticated takes
*/
private static Take make(final Take take) {
return new TkFallback(
take,
new FbChain(
new FbStatus(
HttpURLConnection.HTTP_NOT_FOUND,
new RsWithStatus(
new RsText("Page not found"),
HttpURLConnection.HTTP_NOT_FOUND
)
),
new FbStatus(
HttpURLConnection.HTTP_BAD_REQUEST,
new RsWithStatus(
new RsText("Bad request"),
HttpURLConnection.HTTP_BAD_REQUEST
)
),
req -> {
Sentry.capture(req.throwable());
return new Opt.Empty<>();
},
req -> new Opt.Single<>(TkAppFallback.fatal(req))
)
);
}
开发者ID:yegor256,项目名称:jare,代码行数:32,代码来源:TkAppFallback.java
示例19: make
import org.takes.rs.RsWithStatus; //导入依赖的package包/类
/**
* Authenticated.
* @param take Takes
* @return Authenticated takes
*/
private static Take make(final Take take) {
return new TkFallback(
take,
new FbChain(
new FbStatus(
HttpURLConnection.HTTP_NOT_FOUND,
new RsWithStatus(
new RsText("page not found"),
HttpURLConnection.HTTP_NOT_FOUND
)
),
new FbStatus(
HttpURLConnection.HTTP_BAD_REQUEST,
new RsWithStatus(
new RsText("bad request"),
HttpURLConnection.HTTP_BAD_REQUEST
)
),
req -> {
Sentry.capture(req.throwable());
return new Opt.Empty<>();
},
req -> new Opt.Single<>(TkAppFallback.fatal(req))
)
);
}
开发者ID:yegor256,项目名称:wring,代码行数:32,代码来源:TkAppFallback.java
示例20: TkRoot
import org.takes.rs.RsWithStatus; //导入依赖的package包/类
public TkRoot(final Services services) {
super(
new TkSlf4j(
new TkFallback(
new TkFork(
new FkRegex("/health", new TkHealth()),
new FkRegex("/service(/.*)?", new TkServices(services))
),
new FbFixed(new RsWithStatus(new RsText("404 Not Found"), HttpURLConnection.HTTP_NOT_FOUND))
)
)
);
}
开发者ID:aliceice,项目名称:roster,代码行数:14,代码来源:TkRoot.java
注:本文中的org.takes.rs.RsWithStatus类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论