本文整理汇总了Java中play.mvc.Http.Response方法的典型用法代码示例。如果您正苦于以下问题:Java Http.Response方法的具体用法?Java Http.Response怎么用?Java Http.Response使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类play.mvc.Http
的用法示例。
在下文中一共展示了Http.Response方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: rawInvocation
import play.mvc.Http; //导入方法依赖的package包/类
@Override
public boolean rawInvocation(Http.Request request, Http.Response response) throws Exception {
// Mark an evolution as resolved
if (Play.mode.isDev() && request.method.equals("POST") && request.url.matches("^/@evolutions/force/[0-9]+$")) {
int revision = Integer.parseInt(request.url.substring(request.url.lastIndexOf("/") + 1));
resolve(revision);
new Redirect("/").apply(request, response);
return true;
}
// Apply the current evolution script
if (Play.mode.isDev() && request.method.equals("POST") && request.url.equals("/@evolutions/apply")) {
applyScript(true);
new Redirect("/").apply(request, response);
return true;
}
return super.rawInvocation(request, response);
}
示例2: setRequest
import play.mvc.Http; //导入方法依赖的package包/类
public static void setRequest(String body) {
Http.Request mockRequest = mock(Http.Request.class);
when(mockRequest.body()).thenReturn(new Http.RequestBody(Json.parse(body)));
Http.Response mockResponse = mock(Http.Response.class);
doNothing().when(mockResponse).setHeader(
any(String.class), any(String.class));
Http.Context mockContext = mock(Http.Context.class);
when(mockContext.request()).thenReturn(mockRequest);
when(mockContext.response()).thenReturn(mockResponse);
Http.Context.current.set(mockContext);
}
示例3: call
import play.mvc.Http; //导入方法依赖的package包/类
@Override
public Promise<Result> call(Http.Context ctx) throws java.lang.Throwable {
long startTime = System.currentTimeMillis();
ProjectLogger.log("Learning Service Call start for api ==" + ctx.request().path()
+ " start time " + startTime, LoggerEnum.PERF_LOG);
Promise<Result> result = null;
Http.Response response = ctx.response();
response.setHeader("Access-Control-Allow-Origin", "*");
String message = RequestInterceptor.verifyRequestData(ctx);
if (message.contains("{userId}")) {
ctx.flash().put(JsonKey.USER_ID, message.replace("{userId}", ""));
ctx.flash().put(JsonKey.IS_AUTH_REQ, "false");
for(String uri : RequestInterceptor.restrictedUriList){
if(ctx.request().path().contains(uri)){
ctx.flash().put(JsonKey.IS_AUTH_REQ, "true");
break;
}
}
result = delegate.call(ctx);
} else if (!ProjectUtil.isStringNullOREmpty(message)) {
result = onDataValidationError(ctx.request(), message,ResponseCode.UNAUTHORIZED.getResponseCode());
} else {
result = delegate.call(ctx);
}
ProjectLogger.log("Learning Service Call Ended for api ==" + ctx.request().path()
+ " end time " + System.currentTimeMillis() + " Time taken "
+ (System.currentTimeMillis() - startTime), LoggerEnum.PERF_LOG);
return result;
}
示例4: propagateAction
import play.mvc.Http; //导入方法依赖的package包/类
private Action propagateAction(Map<String, String> headers) {
return new Action.Simple() {
@Override
public CompletionStage<Result> call(Http.Context ctx) {
CompletionStage<Result> result = delegate.call(ctx);
Http.Response response = ctx.response();
response.setHeader("Cache-Control", "no-cache;no-store");
response.setHeader("Pragma", "no-cache");
for (Map.Entry<String, String> entry : headers.entrySet()) {
response.setHeader(entry.getKey(), entry.getValue());
}
return result;
}
};
}
示例5: getStatus
import play.mvc.Http; //导入方法依赖的package包/类
private String getStatus(Http.Request request, Http.Response response) {
/* It seems as though the Response.current() is only valid when the request is handled by a controller
Serving static files, static 404's and 500's etc don't populate the same Response.current()
This prevents us from getting the bytes sent and response status all of the time
*/
if (request.action != null && response.out.size() > 0) {
return response.status.toString();
}
return "-";
}
示例6: getBytes
import play.mvc.Http; //导入方法依赖的package包/类
private String getBytes(Http.Request request, Http.Response response) {
/* It seems as though the Response.current() is only valid when the request is handled by a controller
Serving static files, static 404's and 500's etc don't populate the same Response.current()
This prevents us from getting the bytes sent and response status all of the time
*/
if (request.action != null && response.out.size() > 0) {
return String.valueOf(response.out.size());
}
return "-";
}
示例7: replaceResponse
import play.mvc.Http; //导入方法依赖的package包/类
private String replaceResponse(Http.Response response, String line) {
if (logResponse && isErrorStatus(response) && response.out != null) {
String value = response.out.toString();
if (StringUtils.isNotEmpty(value)) {
line = StringUtils.replaceOnce(line, "%response", value);
} else {
// leave quotes in the logged string to show it was an empty response
line = StringUtils.remove(line, "%response");
}
} else {
line = StringUtils.remove(line, "\"%response\"");
}
return line;
}
示例8: getRequestHashCode
import play.mvc.Http; //导入方法依赖的package包/类
private int getRequestHashCode() {
Http.Request request = Http.Request.current();
Http.Response response = Http.Response.current();
String requestSig = request.host;
requestSig += request.remoteAddress;
requestSig += getUser(request);
requestSig += request.method;
requestSig += request.url;
requestSig += getStatus(request, response);
requestSig += getBytes(request, response);
requestSig += getReferrer(request);
requestSig += getUserAgent(request);
return requestSig.hashCode();
}
示例9: addCorsHeader
import play.mvc.Http; //导入方法依赖的package包/类
public void addCorsHeader() {
final Http.Request request = Http.Request.current();
if (Play.mode.isDev() && request != null && request.headers.get("origin") != null) {
final Http.Response response = Http.Response.current();
response.setHeader("Access-Control-Allow-Origin", request.headers.get("origin").value());
response.setHeader("Access-Control-Allow-Credentials", "true");
response.setHeader("Access-Control-Max-Age", "3600");
response.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization");
}
}
示例10: log
import play.mvc.Http; //导入方法依赖的package包/类
private synchronized void log() {
if (!enabled) {
return;
}
Http.Request request = Http.Request.current();
Http.Response response = Http.Response.current();
if (request == null || response == null) {
return;
}
long requestProcessingTime = System.currentTimeMillis() - request.date.getTime();
String line = FORMAT;
line = StringUtils.replaceOnce(line, "%v", request.host);
line = StringUtils.replaceOnce(line, "%h", request.remoteAddress);
line = StringUtils.replaceOnce(line, "%u", getUser(request));
line = StringUtils.replaceOnce(line, "%t", request.date.toString());
line = StringUtils.replaceOnce(line, "%m", request.method);
line = StringUtils.replaceOnce(line, "%r", request.url);
line = StringUtils.replaceOnce(line, "%s", getStatus(request, response));
line = StringUtils.replaceOnce(line, "%b", getBytes(request, response));
line = StringUtils.replaceOnce(line, "%ref", getReferrer(request));
line = StringUtils.replaceOnce(line, "%ua", getUserAgent(request));
line = StringUtils.replaceOnce(line, "%rt", String.valueOf(requestProcessingTime));
line = replaceRequestHeaders(request, line);
line = replacePost(request, line);
line = replaceResponse(response, line);
line = StringUtils.trim(line);
// Check for duplicates
int requestHashCode = getRequestHashCode();
if (lastRequestHashCode == requestHashCode) {
previousLine = line;
duplicates++;
} else {
lastRequestHashCode = requestHashCode;
if (duplicates > 0) {
logLine(previousLine);
logLine(" + " + duplicates + " duplicates");
duplicates = 0;
}
logLine(line);
}
}
示例11: isErrorStatus
import play.mvc.Http; //导入方法依赖的package包/类
private boolean isErrorStatus(Http.Response response) {
int statusCode = response.status / 100;
return statusCode == 4 || statusCode == 5;
}