本文整理汇总了Java中ratpack.func.Action类的典型用法代码示例。如果您正苦于以下问题:Java Action类的具体用法?Java Action怎么用?Java Action使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Action类属于ratpack.func包,在下文中一共展示了Action类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: init
import ratpack.func.Action; //导入依赖的package包/类
@Override
public void init() {
try {
RatpackServer.start(server -> {
server.serverConfig(c -> {
for(Action<ServerConfigBuilder> cfg : getConfigurators()) {
c = cfg.with(c);
}
});
server.registry(Guice.registry(b -> {
for(Action<BindingsSpec> binding : getBindings()) {
b = binding.with(b);
}
}));
server.handlers(chain -> {
for(Action<Chain> handler : getHandlers()) {
// chain = chain.insert(handler);
chain = handler.with(chain);
}
});
});
} catch (Exception e) {
logger.error("Ratpack failure", e);
}
}
示例2: accept
import ratpack.func.Action; //导入依赖的package包/类
@Override
public void accept(Throwable e) throws Exception {
if (e instanceof OnErrorNotImplementedException) {
Promise.error(e.getCause()).then(Action.noop());
} else if (e instanceof UndeliverableException) {
Promise.error(e.getCause()).then(Action.noop());
} else {
Promise.error(e).then(Action.noop());
}
}
示例3: proxyRequest
import ratpack.func.Action; //导入依赖的package包/类
private Action<RequestSpec> proxyRequest(final TypedData body, final Request request) {
return spec -> {
spec.getBody().buffer(body.getBuffer());
spec.getHeaders().copy(request.getHeaders());
spec.method(request.getMethod());
};
}
示例4: config
import ratpack.func.Action; //导入依赖的package包/类
private static Action<ServerConfigBuilder> config(String[] args) {
final Path baseDir = Paths.get("").toAbsolutePath();
log.info("Using baseDir: " + baseDir);
Action<ServerConfigBuilder> cfg = Action.from(c -> c
.baseDir(baseDir)
.json(Resources.getResource("config-core.json"))
);
if (args.length == 1) {
final String filename = args[0];
final Path configPath = Paths.get(baseDir.toString(), filename);
if (!Files.exists(configPath)) {
throw new UnsupportedOperationException("Could not find config file: " + configPath);
}
cfg = cfg.append(c -> c.json(configPath));
}
cfg = cfg.append(c -> c
.env("LAZYBOT_")
.sysProps("lazybot.")
.require("/hipchat", HipChatConfig.class)
.require("/db", DatabaseConfig.class)
.require("/plugins", PluginConfig.class)
);
return cfg;
}
示例5: request
import ratpack.func.Action; //导入依赖的package包/类
@Override
public Promise<ReceivedResponse> request(URI uri, Action<? super RequestSpec> action) {
final AtomicReference<Span> span = new AtomicReference<>();
return delegate
.request(uri, (RequestSpec requestSpec) -> action.execute(new WrappedRequestSpec(handler, injector, requestSpec, span)))
.wiretap(response -> responseWithSpan(response, span));
}
示例6: requestStream
import ratpack.func.Action; //导入依赖的package包/类
@Override
public Promise<StreamedResponse> requestStream(URI uri, Action<? super RequestSpec> action) {
final AtomicReference<Span> span = new AtomicReference<>();
return delegate
.requestStream(uri, (RequestSpec requestSpec) -> {
WrappedRequestSpec captor = new WrappedRequestSpec(handler, injector, requestSpec, span);
// streamed request doesn't set the http method.
// start span here until a better solution presents itself.
span.set(handler.handleSend(injector, captor.getHeaders(), captor));
action.execute(captor);
})
.wiretap(response -> streamedResponseWithSpan(response, span));
}
示例7: onRedirect
import ratpack.func.Action; //导入依赖的package包/类
@Override
public RequestSpec onRedirect(Function<? super ReceivedResponse, Action<? super RequestSpec>> function) {
Function<? super ReceivedResponse, Action<? super RequestSpec>> wrapped =
(ReceivedResponse response) -> redirectHandler(response).append(function.apply(response));
this.delegate.onRedirect(wrapped);
return this;
}
示例8: config
import ratpack.func.Action; //导入依赖的package包/类
private Action<ServerConfigBuilder> config() {
final Path baseDir = BaseDir.find(PUBLIC);
return Action.from(c -> c
.port(port)
.address(address)
.baseDir(baseDir)
);
}
示例9: BaseServer
import ratpack.func.Action; //导入依赖的package包/类
public BaseServer(Action<Chain> handlers, ServerConfig config, Action<BindingsSpec> binding) throws ServerException {
try {
this.ratpackServer = RatpackServer.of(def ->
def.serverConfig(config)
.registry(Guice.registry(binding))
.handlers(handlers));
} catch (Exception e) {
throw new ServerException("Error in building ratpack server.", e);
}
}
示例10: newErrorAction
import ratpack.func.Action; //导入依赖的package包/类
public static Action<Throwable> newErrorAction(Context context) {
return throwable -> {
if (throwable instanceof InvalidValueException) {
StatusHelper.sendBadRequest(context, throwable.getMessage());
} else if (throwable instanceof ResourceNotFoundException) {
StatusHelper.sendNotFound(context, ((ResourceNotFoundException) throwable).getId());
} else {
StatusHelper.sendInternalError(context, throwable);
}
};
}
示例11: handleAddNewUserAsync
import ratpack.func.Action; //导入依赖的package包/类
void handleAddNewUserAsync(Context context) {
Action<Fulfiller<String>> action = fulfiller -> {
User user = helper.fromBody(context, User.class);
store.saveAsync(user, helper.newJsonConsumer(fulfiller), fulfiller::error);
};
HandlerHelper.handleRequestWithPromise(context, action);
}
示例12: handleConnectionCreationAsync
import ratpack.func.Action; //导入依赖的package包/类
void handleConnectionCreationAsync(Context context) {
Action<Fulfiller<String>> action = fulfiller -> {
String userId = context.getPathTokens().get(USER_PATH_TOKEN);
MultiValueMap<String, String> queryParams = context.getRequest().getQueryParams();
if (!queryParams.containsKey(CONNECT_TO_QUERY_PARAM)) {
throw new InvalidValueException("Query parameter 'to' is required.");
}
String connectTo = queryParams.get(CONNECT_TO_QUERY_PARAM);
store.connectAsync(userId, connectTo, helper.newJsonConsumer(fulfiller), fulfiller::error);
};
HandlerHelper.handleRequestWithPromise(context, action);
}
示例13: handleGetUserConnectionsListAsync
import ratpack.func.Action; //导入依赖的package包/类
void handleGetUserConnectionsListAsync(Context context) {
Action<Fulfiller<String>> action = fulfiller -> {
String userId = context.getPathTokens().get(USER_PATH_TOKEN);
//other parameters like sort and count can be read from query parameters
store.listConnections(userId, 100, helper.newJsonConsumer(fulfiller), fulfiller::error);
};
HandlerHelper.handleRequestWithPromise(context, action);
}
示例14: handleSaveAsync
import ratpack.func.Action; //导入依赖的package包/类
private void handleSaveAsync(Context context) {
Action<Fulfiller<String>> action = fulfiller -> {
//at the moment, we only handle user entity type
User entity = helper.fromBody(context, User.class);
store.saveAsync(entity, helper.newJsonConsumer(fulfiller), fulfiller::error);
};
HandlerHelper.handleRequestWithPromise(context, action);
}
示例15: handleFindByIdAsync
import ratpack.func.Action; //导入依赖的package包/类
private void handleFindByIdAsync(Context context) {
Action<Fulfiller<String>> action = fulfiller -> {
String id = context.getPathTokens().get("id");
store.findById(id, helper.newJsonConsumer(fulfiller), fulfiller::error);
};
HandlerHelper.handleRequestWithPromise(context, action);
}