Skip to content

Commit

Permalink
Renamed HTTP "Response" class to "Resp".
Browse files Browse the repository at this point in the history
  • Loading branch information
nmihajlovski committed Dec 13, 2015
1 parent 8adf095 commit eff7def
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 44 deletions.
2 changes: 1 addition & 1 deletion rapidoid-ctx/src/main/java/org/rapidoid/http/Req.java
Expand Up @@ -138,7 +138,7 @@ public interface Req {


/* RESPONSE: */ /* RESPONSE: */


Response response(); Resp response();


OutputStream out(); OutputStream out();


Expand Down
Expand Up @@ -25,49 +25,49 @@


import org.rapidoid.commons.MediaType; import org.rapidoid.commons.MediaType;


public interface Response { public interface Resp {


Response content(Object content); Resp content(Object content);


Object content(); Object content();


Response code(int code); Resp code(int code);


int code(); int code();


Map<String, String> headers(); Map<String, String> headers();


Map<String, String> cookies(); Map<String, String> cookies();


Response contentType(MediaType contentType); Resp contentType(MediaType contentType);


MediaType contentType(); MediaType contentType();


Response redirect(String redirect); Resp redirect(String redirect);


String redirect(); String redirect();


Response filename(String filename); Resp filename(String filename);


String filename(); String filename();


Response file(File file); Resp file(File file);


File file(); File file();


Response view(String view); Resp view(String view);


String view(); String view();


Req done(); Req done();


Response plain(Object content); Resp plain(Object content);


Response html(Object content); Resp html(Object content);


Response json(Object content); Resp json(Object content);


Response binary(Object content); Resp binary(Object content);


Req request(); Req request();


Expand Down
Expand Up @@ -29,12 +29,12 @@
import org.rapidoid.annotation.Since; import org.rapidoid.annotation.Since;
import org.rapidoid.commons.MediaType; import org.rapidoid.commons.MediaType;
import org.rapidoid.http.Req; import org.rapidoid.http.Req;
import org.rapidoid.http.Response; import org.rapidoid.http.Resp;
import org.rapidoid.u.U; import org.rapidoid.u.U;


@Authors("Nikolche Mihajlovski") @Authors("Nikolche Mihajlovski")
@Since("5.0.2") @Since("5.0.2")
public class HttpResponse implements Response { public class HttpResponse implements Resp {


private final ReqImpl req; private final ReqImpl req;


Expand All @@ -61,7 +61,7 @@ public HttpResponse(ReqImpl req) {
} }


@Override @Override
public synchronized Response content(Object content) { public synchronized Resp content(Object content) {
ensureCanChange(); ensureCanChange();
this.content = content; this.content = content;
return this; return this;
Expand All @@ -73,7 +73,7 @@ public synchronized Object content() {
} }


@Override @Override
public synchronized Response code(int code) { public synchronized Resp code(int code) {
ensureCanChange(); ensureCanChange();
this.code = code; this.code = code;
return this; return this;
Expand All @@ -95,7 +95,7 @@ public Map<String, String> cookies() {
} }


@Override @Override
public synchronized Response contentType(MediaType contentType) { public synchronized Resp contentType(MediaType contentType) {
ensureCanChange(); ensureCanChange();
this.contentType = contentType; this.contentType = contentType;
return this; return this;
Expand All @@ -107,7 +107,7 @@ public synchronized MediaType contentType() {
} }


@Override @Override
public synchronized Response redirect(String redirect) { public synchronized Resp redirect(String redirect) {
ensureCanChange(); ensureCanChange();
this.redirect = redirect; this.redirect = redirect;
return this; return this;
Expand All @@ -119,7 +119,7 @@ public synchronized String redirect() {
} }


@Override @Override
public synchronized Response filename(String filename) { public synchronized Resp filename(String filename) {
ensureCanChange(); ensureCanChange();
this.filename = filename; this.filename = filename;
return this; return this;
Expand All @@ -131,7 +131,7 @@ public synchronized String filename() {
} }


@Override @Override
public synchronized Response file(File file) { public synchronized Resp file(File file) {
ensureCanChange(); ensureCanChange();
this.file = file; this.file = file;
return this; return this;
Expand All @@ -157,22 +157,22 @@ public Req done() {
} }


@Override @Override
public Response html(Object content) { public Resp html(Object content) {
return contentType(MediaType.HTML_UTF_8).content(content); return contentType(MediaType.HTML_UTF_8).content(content);
} }


@Override @Override
public Response plain(Object content) { public Resp plain(Object content) {
return contentType(MediaType.PLAIN_TEXT_UTF_8).content(content); return contentType(MediaType.PLAIN_TEXT_UTF_8).content(content);
} }


@Override @Override
public Response json(Object content) { public Resp json(Object content) {
return contentType(MediaType.JSON_UTF_8).content(content); return contentType(MediaType.JSON_UTF_8).content(content);
} }


@Override @Override
public Response binary(Object content) { public Resp binary(Object content) {
return contentType(MediaType.BINARY).content(content); return contentType(MediaType.BINARY).content(content);
} }


Expand All @@ -182,7 +182,7 @@ public synchronized String view() {
} }


@Override @Override
public synchronized Response view(String view) { public synchronized Resp view(String view) {
this.view = view; this.view = view;
return this; return this;
} }
Expand Down
Expand Up @@ -30,7 +30,7 @@
import org.rapidoid.config.Conf; import org.rapidoid.config.Conf;
import org.rapidoid.data.JSON; import org.rapidoid.data.JSON;
import org.rapidoid.http.Req; import org.rapidoid.http.Req;
import org.rapidoid.http.Response; import org.rapidoid.http.Resp;
import org.rapidoid.io.Res; import org.rapidoid.io.Res;
import org.rapidoid.log.Log; import org.rapidoid.log.Log;
import org.rapidoid.u.U; import org.rapidoid.u.U;
Expand Down Expand Up @@ -144,17 +144,17 @@ public static String renderState(Map<String, Serializable> pageLocals) {
} }
} }


public static void setContentTypeForFile(Response resp, File file) { public static void setContentTypeForFile(Resp resp, File file) {
U.must(file.exists()); U.must(file.exists());
setContentType(resp, MediaType.getByFileName(file.getAbsolutePath())); setContentType(resp, MediaType.getByFileName(file.getAbsolutePath()));
} }


public static void setContentTypeForResource(Response resp, Res resource) { public static void setContentTypeForResource(Resp resp, Res resource) {
U.must(resource.exists()); U.must(resource.exists());
setContentType(resp, MediaType.getByFileName(resource.getShortName())); setContentType(resp, MediaType.getByFileName(resource.getShortName()));
} }


public static void setContentType(Response resp, MediaType mediaType) { public static void setContentType(Resp resp, MediaType mediaType) {
resp.contentType(mediaType); resp.contentType(mediaType);
} }


Expand Down Expand Up @@ -207,13 +207,13 @@ public static String getErrorMessage(Throwable err) {
} }
} }


public static void postProcessResponse(Response resp) { public static void postProcessResponse(Resp resp) {
postProcessRedirect(resp); postProcessRedirect(resp);
postProcessFile(resp); postProcessFile(resp);
postProcessFilename(resp); postProcessFilename(resp);
} }


private static void postProcessFile(Response resp) { private static void postProcessFile(Resp resp) {
File file = resp.file(); File file = resp.file();
if (file != null) { if (file != null) {
U.must(file.exists()); U.must(file.exists());
Expand All @@ -228,15 +228,15 @@ private static void postProcessFile(Response resp) {
} }
} }


private static void postProcessFilename(Response resp) { private static void postProcessFilename(Resp resp) {
String filename = resp.filename(); String filename = resp.filename();
if (filename != null) { if (filename != null) {
resp.headers().put(HttpHeaders.CONTENT_DISPOSITION.name(), "attachment; filename=\"" + filename + "\""); resp.headers().put(HttpHeaders.CONTENT_DISPOSITION.name(), "attachment; filename=\"" + filename + "\"");
resp.headers().put(HttpHeaders.CACHE_CONTROL.name(), "private"); resp.headers().put(HttpHeaders.CACHE_CONTROL.name(), "private");
} }
} }


private static void postProcessRedirect(Response resp) { private static void postProcessRedirect(Resp resp) {
String redirect = resp.redirect(); String redirect = resp.redirect();
if (redirect != null) { if (redirect != null) {
resp.code(303); resp.code(303);
Expand Down
Expand Up @@ -33,7 +33,7 @@
import org.rapidoid.cls.Cls; import org.rapidoid.cls.Cls;
import org.rapidoid.commons.MediaType; import org.rapidoid.commons.MediaType;
import org.rapidoid.http.Req; import org.rapidoid.http.Req;
import org.rapidoid.http.Response; import org.rapidoid.http.Resp;
import org.rapidoid.net.abstracts.Channel; import org.rapidoid.net.abstracts.Channel;
import org.rapidoid.u.U; import org.rapidoid.u.U;
import org.rapidoid.util.Constants; import org.rapidoid.util.Constants;
Expand Down Expand Up @@ -70,7 +70,7 @@ public class ReqImpl implements Req, Constants {


private final Map<String, Object> attrs = Collections.synchronizedMap(new HashMap<String, Object>()); private final Map<String, Object> attrs = Collections.synchronizedMap(new HashMap<String, Object>());


private volatile Response response; private volatile Resp response;


private volatile boolean rendering; private volatile boolean rendering;


Expand Down Expand Up @@ -321,7 +321,7 @@ private <T> T withDefault(Object value, T defaultValue) {
/************************** RESPONSE **************************/ /************************** RESPONSE **************************/


@Override @Override
public synchronized Response response() { public synchronized Resp response() {
if (response == null) { if (response == null) {
response = new HttpResponse(this); response = new HttpResponse(this);
if (defaultContentType != null) { if (defaultContentType != null) {
Expand Down
Expand Up @@ -30,7 +30,7 @@
import org.rapidoid.ctx.Ctx; import org.rapidoid.ctx.Ctx;
import org.rapidoid.ctx.Ctxs; import org.rapidoid.ctx.Ctxs;
import org.rapidoid.http.Req; import org.rapidoid.http.Req;
import org.rapidoid.http.Response; import org.rapidoid.http.Resp;
import org.rapidoid.http.fast.FastHttp; import org.rapidoid.http.fast.FastHttp;
import org.rapidoid.http.fast.HttpStatus; import org.rapidoid.http.fast.HttpStatus;
import org.rapidoid.http.fast.HttpWrapper; import org.rapidoid.http.fast.HttpWrapper;
Expand Down Expand Up @@ -65,7 +65,7 @@ public HttpStatus handle(Channel ctx, boolean isKeepAlive, Req req) {


@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
protected Object postprocessResult(Req req, Object result) throws Exception { protected Object postprocessResult(Req req, Object result) throws Exception {
if (result instanceof Req || result instanceof Response) { if (result instanceof Req || result instanceof Resp) {
return result; return result;


} else if (result == null) { } else if (result == null) {
Expand Down Expand Up @@ -184,7 +184,7 @@ public void complete(Channel ctx, boolean isKeepAlive, Req req, Object result) {


return; return;


} else if (result instanceof Response) { } else if (result instanceof Resp) {
U.must(req.response() == result); U.must(req.response() == result);


// the Req object will do the rendering // the Req object will do the rendering
Expand Down
Expand Up @@ -61,7 +61,7 @@ public Object handle(final Req req) throws Exception {
@Override @Override
public void run() { public void run() {
U.must(Reqs.req() == req); U.must(Reqs.req() == req);
Response resp = req.response(); Resp resp = req.response();
resp.content(req.data()).done(); resp.content(req.data()).done();
} }
}, 1000, TimeUnit.MILLISECONDS); }, 1000, TimeUnit.MILLISECONDS);
Expand Down
Expand Up @@ -47,7 +47,7 @@
import org.rapidoid.dispatch.impl.DispatchReqKind; import org.rapidoid.dispatch.impl.DispatchReqKind;
import org.rapidoid.dispatch.impl.PojoDispatcherImpl; import org.rapidoid.dispatch.impl.PojoDispatcherImpl;
import org.rapidoid.http.Req; import org.rapidoid.http.Req;
import org.rapidoid.http.Response; import org.rapidoid.http.Resp;
import org.rapidoid.u.U; import org.rapidoid.u.U;


@Authors("Nikolche Mihajlovski") @Authors("Nikolche Mihajlovski")
Expand All @@ -60,13 +60,13 @@ public WebPojoDispatcher(Classes components) {


@Override @Override
protected boolean isCustomType(Class<?> type) { protected boolean isCustomType(Class<?> type) {
return Req.class.isAssignableFrom(type) || Response.class.isAssignableFrom(type) || type.equals(byte[].class) return Req.class.isAssignableFrom(type) || Resp.class.isAssignableFrom(type) || type.equals(byte[].class)
|| type.equals(byte[][].class) || super.isCustomType(type); || type.equals(byte[][].class) || super.isCustomType(type);
} }


@Override @Override
protected Object getCustomArg(PojoRequest request, Class<?> type, String[] parts, int paramsFrom, int paramsSize) { protected Object getCustomArg(PojoRequest request, Class<?> type, String[] parts, int paramsFrom, int paramsSize) {
if (Req.class.isAssignableFrom(type) || Response.class.isAssignableFrom(type)) { if (Req.class.isAssignableFrom(type) || Resp.class.isAssignableFrom(type)) {
return req(request); return req(request);


} else if (type.equals(byte[].class)) { } else if (type.equals(byte[].class)) {
Expand Down

0 comments on commit eff7def

Please sign in to comment.