本文整理汇总了Java中ratpack.registry.Registry类的典型用法代码示例。如果您正苦于以下问题:Java Registry类的具体用法?Java Registry怎么用?Java Registry使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Registry类属于ratpack.registry包,在下文中一共展示了Registry类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: serialize
import ratpack.registry.Registry; //导入依赖的package包/类
public ByteBuf serialize(Registry registry, ByteBufAllocator bufAllocator, Object value) throws Exception {
Objects.requireNonNull(value);
KryoPool kryoPool = registry.get(KryoPool.class);
Kryo kryo = kryoPool.borrow();
try {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
Output output = new Output(stream);
kryo.writeClassAndObject(output, value);
output.close();
byte[] bytes = stream.toByteArray();
String encoded = ENCODER.encodeToString(bytes);
return ByteBufUtil.encodeString(bufAllocator, CharBuffer.wrap(encoded), CharsetUtil.UTF_8);
} catch (Exception ex) {
throw ex;
} finally {
kryoPool.release(kryo);
}
}
开发者ID:zedar,项目名称:ratpack-examples,代码行数:19,代码来源:KryoValueSerializer.java
示例2: deserialize
import ratpack.registry.Registry; //导入依赖的package包/类
public Object deserialize(Registry registry, String value) throws Exception {
if (value == null || value.isEmpty()) {
return null;
}
KryoPool kryoPool = registry.get(KryoPool.class);
Kryo kryo = kryoPool.borrow();
try {
byte[] bytes = DECODER.decode(value);
ByteArrayInputStream stream = new ByteArrayInputStream(bytes);
Input input = new Input(stream);
Object obj = kryo.readClassAndObject(input);
input.close();
return obj;
} catch (Exception ex) {
throw ex;
} finally {
kryoPool.release(kryo);
}
}
开发者ID:zedar,项目名称:ratpack-examples,代码行数:20,代码来源:KryoValueSerializer.java
示例3: Route
import ratpack.registry.Registry; //导入依赖的package包/类
public Route(final Resource resource, final Method method) {
final Registry registry = Registry.builder().add(resource).add(method).build();
final Handler chain = Handlers.chain(
RequestLogger.ncsa(LOG),
requestValidationHandler,
Handlers.when(isMode(VrapMode.proxy),
Handlers.chain(
requestProxyHandler,
receivedResponseValidationHandler,
receivedResponseForwardHandler)),
Handlers.when(isMode(VrapMode.example), requestExampleHandler));
this.delegate = Handlers.register(registry, chain);
}
开发者ID:vrapio,项目名称:vrap,代码行数:14,代码来源:RamlRouter.java
示例4: validateRequest
import ratpack.registry.Registry; //导入依赖的package包/类
private void validateRequest(final Context ctx, final TypedData body) throws Exception {
final Validator validator = ctx.get(Validator.class);
final boolean dryRun = ctx.get(VrapApp.VrapOptions.class).getDryRun();
final Method method = ctx.get(Method.class);
final Optional<Validator.ValidationErrors> validationErrors = validator.validateRequest(ctx, body, method);
ctx.next(Registry.of(registrySpec -> {
registrySpec.add(TypedData.class, body);
validationErrors.ifPresent(validationErrors1 -> registrySpec.add(Validator.ValidationErrors.class, validationErrors1));
}));
}
开发者ID:vrapio,项目名称:vrap,代码行数:12,代码来源:RamlRouter.java
示例5: handle
import ratpack.registry.Registry; //导入依赖的package包/类
@Override
public void handle(final Context ctx) throws Exception {
final Request request = ctx.getRequest();
final TypedData body = ctx.get(TypedData.class);
final HttpClient httpClient = ctx.get(HttpClient.class);
final URI proxiedUri = proxiedUri(ctx);
LOG.info("Forward to: {}", proxiedUri);
httpClient.request(proxiedUri, proxyRequest(body, request))
.then(receivedResponse ->
ctx.next(Registry.builder().add(receivedResponse).add(proxiedUri).build()));
}
开发者ID:vrapio,项目名称:vrap,代码行数:13,代码来源:RamlRouter.java
示例6: RamlHandler
import ratpack.registry.Registry; //导入依赖的package包/类
public RamlHandler(FileContentModifier contentModifier) {
final Registry registry = Registry.builder().add("get").build();
final Handler chain = Handlers.chain(
RequestLogger.ncsa(LOG),
Handlers.when(
isJsonFile(),
new JsonFileHandler(contentModifier)
),
new RamlFileHandler(contentModifier)
);
this.delegate = Handlers.register(registry, chain);
}
开发者ID:vrapio,项目名称:vrap,代码行数:13,代码来源:RamlFilesHandler.java
示例7: Route
import ratpack.registry.Registry; //导入依赖的package包/类
public Route(final String authUri) {
requestProxyHandler = new AuthRouter.RequestProxyHandler(authUri);
final Registry registry = Registry.builder().add(authUri).build();
final Handler chain = Handlers.chain(
RequestLogger.ncsa(LOG),
requestProxyHandler
);
this.delegate = Handlers.register(registry, chain);
}
开发者ID:vrapio,项目名称:vrap,代码行数:10,代码来源:AuthRouter.java
示例8: registry
import ratpack.registry.Registry; //导入依赖的package包/类
private static Function<Registry, Registry> registry() {
return Guice.registry(b -> b
.module(ClientModule.class)
.module(ServerModule.class)
.module(DatabaseModule.class)
.module(BotModule.class)
.module(PluginModule.class)
.bind(BotOrchestrationService.class)
);
}
开发者ID:RoyJacobs,项目名称:lazybot,代码行数:11,代码来源:App.java
示例9: check
import ratpack.registry.Registry; //导入依赖的package包/类
@Override
public Promise<Result> check(Registry registry) throws Exception {
return eurekaService.isAvailable().map(available -> {
if (available) {
return Result.healthy();
}
return Result.unhealthy("EurekaService: Not available");
});
}
开发者ID:schibsted,项目名称:ratpack-eureka,代码行数:10,代码来源:EurekaHealthCheck.java
示例10: getRegistry
import ratpack.registry.Registry; //导入依赖的package包/类
@Override
public Registry getRegistry() {
return null;
}
开发者ID:RoyJacobs,项目名称:lazybot,代码行数:5,代码来源:BotOrchestrationStepdefs.java
示例11: init
import ratpack.registry.Registry; //导入依赖的package包/类
public void init() throws Exception {
Registry registry = Registry.builder()
.add(messageRenderer)
.add(ServerErrorHandler.class, errorHandler)
.build();
RatpackServer.start(server -> server
.serverConfig(ServerConfig.embedded().port(port))
.registry(registry)
.handlers(chain -> chain
.all(ctx -> {
ctx.getResponse().getHeaders().add("access-control-allow-origin", "*");
ctx.getResponse().getHeaders().add("access-control-allow-methods", "GET,PUT,POST,PATCH,DELETE,OPTIONS");
ctx.getResponse().getHeaders().add("access-control-allow-credentials", "true");
ctx.getResponse().getHeaders().add("access-control-allow-headers", "Authorization,Content-Type");
ctx.getResponse().getHeaders().add("access-control-expose-headers", "Link,Location");
ctx.getResponse().getHeaders().add("access-control-max-age", "86400");
String jwtHeader = ctx.getRequest().getHeaders().get("Authorization");
if (jwtHeader == null) {
jwtHeader = ctx.getRequest().getQueryParams().get("Authorization");
}
if (jwtHeader != null) {
if (!jwtHeader.matches("Bearer .*")) {
throw new BadRequestException("Authorization header must contain Bearer token in the format <Bearer JWT>");
}
String jwt = jwtHeader.substring("Bearer ".length());
int workerID = jwtHelper.getWorkerID(jwt);
ctx.next(Registry.single(WorkerID.class, new WorkerID(workerID)));
} else {
ctx.next();
}
})
.options(ctx -> {
ctx.getResponse().status(204);
ctx.getResponse().contentType("text/plain");
ctx.render("");
})
.get("experiments/:platform", ctx -> ctx.render(queries.getExperiments(ctx)))
.get("preview/:experiment", ctx -> ctx.render(queries.preview(ctx)))
.get("next/:platform/:experiment", ctx -> ctx.render(queries.getNext(ctx)))
.post("emails/:platform", ctx -> ctx.render(commands.submitEmail(ctx)))
.post("answers", doAuthorized(ctx -> ctx.render(commands.submitAnswer(ctx))))
.post("ratings", doAuthorized(ctx -> ctx.render(commands.submitRating(ctx))))
.post("calibrations", doAuthorized(ctx -> ctx.render(commands.submitCalibration(ctx))))
.post("delete", doAuthorized(ctx -> ctx.render(commands.deleteWorker(ctx))))
)
);
}
开发者ID:coolcrowd,项目名称:worker-service,代码行数:48,代码来源:RatpackRouter.java
注:本文中的ratpack.registry.Registry类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论