本文整理汇总了Java中org.takes.rs.RsWithStatus类的典型用法代码示例。如果您正苦于以下问题:Java RsWithStatus类的具体用法?Java RsWithStatus怎么用?Java RsWithStatus使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RsWithStatus类属于org.takes.rs包,在下文中一共展示了RsWithStatus类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
)
);
}
示例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))
)
);
}
示例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
);
}
示例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
);
}
示例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
);
}
示例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"
)
);
}
});
}
示例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);
}
}
);
}
示例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)
);
}
示例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()
)
);
}
}
);
}
示例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
);
}
示例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)
)
);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}