Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
package org.rapidoid.http.fast.handler;
/*
* #%L
* rapidoid-http-fast
* %%
* Copyright (C) 2014 - 2015 Nikolche Mihajlovski and contributors
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
import java.util.concurrent.Future;
import org.rapidoid.annotation.Authors;
import org.rapidoid.annotation.Since;
import org.rapidoid.cls.Cls;
import org.rapidoid.ctx.Ctx;
import org.rapidoid.ctx.Ctxs;
import org.rapidoid.http.Req;
import org.rapidoid.http.fast.FastHttp;
import org.rapidoid.http.fast.HttpStatus;
import org.rapidoid.http.fast.HttpWrapper;
import org.rapidoid.lambda.Mapper;
import org.rapidoid.mime.MediaType;
import org.rapidoid.net.abstracts.Channel;
import org.rapidoid.u.U;
@Authors("Nikolche Mihajlovski")
@Since("4.3.0")
public abstract class AbstractAsyncHttpHandler extends AbstractFastHttpHandler {
private static final String CTX_TAG_HANDLER = "handler";
protected final HttpWrapper[] wrappers;
public AbstractAsyncHttpHandler(FastHttp http, MediaType contentType, HttpWrapper[] wrappers) {
super(http, contentType);
this.wrappers = wrappers;
}
@Override
public HttpStatus handle(Channel ctx, boolean isKeepAlive, Req req) {
try {
ctx.async();
execHandlerJob(ctx, isKeepAlive, req);
} catch (Throwable e) {
return http.error(ctx, isKeepAlive, e);
}
return HttpStatus.ASYNC;
}
@SuppressWarnings("unchecked")
protected Object postprocessResult(Object result) throws Exception {
if (result instanceof Req) {
return result; // the Req object will do the rendering
} else if (result == null) {
return result; // not found
} else if (result instanceof Future>) {
result = ((Future