本文整理汇总了Java中play.mvc.Http.Response类的典型用法代码示例。如果您正苦于以下问题:Java Response类的具体用法?Java Response怎么用?Java Response使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Response类属于play.mvc.Http包,在下文中一共展示了Response类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getJsonResponse
import play.mvc.Http.Response; //导入依赖的package包/类
@Override
public Result getJsonResponse(Object obj, int code, Response response) {
StringWriter w = new StringWriter();
try {
getMapper().writeValue(w, obj);
} catch (Exception e) {
String message = "Error while marshalling the application response";
ApiLog.log.error(message, e);
try {
getMapper().writeValue(w, new ApiError(message));
} catch (Exception exp) {
throw new RuntimeException("Unexpected error while mashalling an ApiError message");
}
code = ERROR_API_RESPONSE_CODE;
}
response.setContentType("application/json");
response.setHeader("Access-Control-Allow-Origin", "*");
response.setHeader("Access-Control-Allow-Headers", authorizedHeaders);
return Controller.status(code, w.toString());
}
示例2: check
import play.mvc.Http.Response; //导入依赖的package包/类
void check() {
try {
if (bais == null) {
if (text == null) {
text = getText();
}
BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
DefaultWordRenderer renderer = new DefaultWordRenderer(textColor, fonts);
bi = background.addBackground(bi);
renderer.render(text, bi);
if (noise != null) {
new CurvedLineNoiseProducer(noise, 3.0f).makeNoise(bi);
}
gimpy.gimp(bi);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(bi, "png", baos);
bais = new ByteArrayInputStream(baos.toByteArray());
//
Response.current().contentType = "image/png";
}
} catch (Exception e) {
throw new UnexpectedException(e);
}
}
示例3: rawInvocation
import play.mvc.Http.Response; //导入依赖的package包/类
@Override
public boolean rawInvocation(Request request, Response response) throws Exception {
if (Play.mode.isDev() && request.path.equals("/@db")) {
response.status = Http.StatusCode.MOVED;
// For H2 embeded database, we'll also start the Web console
if (h2Server != null) {
h2Server.stop();
}
h2Server = org.h2.tools.Server.createWebServer();
h2Server.start();
response.setHeader("Location", "http://localhost:8082/");
return true;
}
return false;
}
示例4: rawInvocation
import play.mvc.Http.Response; //导入依赖的package包/类
@Override
public boolean rawInvocation(Request request, 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);
}
示例5: GET
import play.mvc.Http.Response; //导入依赖的package包/类
/**
* sends a GET request to the application under tests.
* @param request
* @param url relative url such as <em>"/products/1234"</em>
* @return the response
*/
public static Response GET(Request request, Object url) {
String path = "";
String queryString = "";
String turl = url.toString();
if (turl.contains("?")) {
path = turl.substring(0, turl.indexOf("?"));
queryString = turl.substring(turl.indexOf("?") + 1);
} else {
path = turl;
}
request.method = "GET";
request.url = turl;
request.path = path;
request.querystring = queryString;
request.body = new ByteArrayInputStream(new byte[0]);
if (savedCookies != null) request.cookies = savedCookies;
return makeRequest(request);
}
示例6: POST
import play.mvc.Http.Response; //导入依赖的package包/类
/**
* Sends a POST request to the application under tests.
* @param request
* @param url relative url such as <em>"/products/1234"</em>
* @param contenttype content-type of the request
* @param body posted data
* @return the response
*/
public static Response POST(Request request, Object url, String contenttype, InputStream body) {
String path = "";
String queryString = "";
String turl = url.toString();
if (turl.contains("?")) {
path = turl.substring(0, turl.indexOf("?"));
queryString = turl.substring(turl.indexOf("?") + 1);
} else {
path = turl;
}
request.method = "POST";
request.contentType = contenttype;
request.url = turl;
request.path = path;
request.querystring = queryString;
request.body = body;
if (savedCookies != null) request.cookies = savedCookies;
return makeRequest(request);
}
示例7: PUT
import play.mvc.Http.Response; //导入依赖的package包/类
/**
* Sends a PUT request to the application under tests.
* @param request
* @param url relative url such as <em>"/products/1234"</em>
* @param contenttype content-type of the request
* @param body data to send
* @return the response
*/
public static Response PUT(Request request, Object url, String contenttype, String body) {
String path = "";
String queryString = "";
String turl = url.toString();
if (turl.contains("?")) {
path = turl.substring(0, turl.indexOf("?"));
queryString = turl.substring(turl.indexOf("?") + 1);
} else {
path = turl;
}
request.method = "PUT";
request.contentType = contenttype;
request.url = turl;
request.path = path;
request.querystring = queryString;
request.body = new ByteArrayInputStream(body.getBytes());
return makeRequest(request);
}
示例8: DELETE
import play.mvc.Http.Response; //导入依赖的package包/类
/**
* Sends a DELETE request to the application under tests.
* @param request
* @param url relative url eg. <em>"/products/1234"</em>
* @return the response
*/
public static Response DELETE(Request request, Object url) {
String path = "";
String queryString = "";
String turl = url.toString();
if (turl.contains("?")) {
path = turl.substring(0, turl.indexOf("?"));
queryString = turl.substring(turl.indexOf("?") + 1);
} else {
path = turl;
}
request.method = "DELETE";
request.url = turl;
request.path = path;
request.querystring = queryString;
if (savedCookies != null) request.cookies = savedCookies;
request.body = new ByteArrayInputStream(new byte[0]);
return makeRequest(request);
}
示例9: makeRequest
import play.mvc.Http.Response; //导入依赖的package包/类
public static Response makeRequest(final Request request) {
Response response = newResponse();
makeRequest(request, response);
if (response.status == 302) { // redirect
// if Location-header is pressent, fix it to "look like" a functional-test-url
Http.Header locationHeader = response.headers.get("Location");
if (locationHeader != null) {
String locationUrl = locationHeader.value();
if (locationUrl.startsWith("http://localhost/")) {
locationHeader.values.clear();
locationHeader.values.add( locationUrl.substring(16));//skip 'http://localhost'
}
}
}
return response;
}
示例10: getAsyncResult
import play.mvc.Http.Response; //导入依赖的package包/类
private static Function<JsonNode, Promise<Result>> getAsyncResult(final Request request, final Response response, final String cacheLen) {
return new Function<JsonNode, Promise<Result>>() {
@Override
public Promise<Result> apply(final JsonNode node) throws Throwable {
return Promise.wrap(akka.dispatch.Futures.future((new Callable<Result>() {
@Override
public Result call() throws Exception {
Result result = Utils.handleDefaultGetHeaders(request, response, String.valueOf(node.hashCode()), cacheLen);
if (result != null) {
return result;
}
return Results.ok(node).as("application/json");
}
}), Akka.system().dispatcher()));
}
};
}
示例11: handleDefaultGetHeaders
import play.mvc.Http.Response; //导入依赖的package包/类
public static Result handleDefaultGetHeaders(Request request, Response response, String calculatedEtag, String seconds) {
response.setHeader("Access-Control-Allow-Origin", "*");
response.setHeader("Access-Control-Allow-Methods", "POST, GET, HEAD");
response.setHeader("Access-Control-Max-Age", seconds);
response.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
response.setHeader("Cache-Control", "public, max-age=" + seconds);
response.setHeader("Expires", new DateTime().plusHours(1).plusSeconds(Integer.parseInt(seconds)).toString(Utils.HTTP_DATE_TIME));
response.setHeader("Last-Modified", new DateTime().plusHours(-1).plusSeconds(-Integer.parseInt(seconds)).toString(Utils.HTTP_DATE_TIME));
response.setHeader("Vary", "Accept-Encoding");
if (calculatedEtag != null) {
response.setHeader("ETag", calculatedEtag);
String eTag = request.getHeader("If-None-Match");
if (calculatedEtag != null && calculatedEtag.equals(eTag)) {
return Results.status(304);
}
}
return null;
}
示例12: returnUnauthorized
import play.mvc.Http.Response; //导入依赖的package包/类
private Promise<Result> returnUnauthorized(final String message, final Response response) {
return Promise.promise(new Function0<Result>() {
@Override
public Result apply() throws Throwable {
return getApiControllerUtilsService().getJsonErrorResponse(new ApiError(HttpURLConnection.HTTP_UNAUTHORIZED, message), response);
}
});
}
示例13: call
import play.mvc.Http.Response; //导入依赖的package包/类
public F.Promise<Result> call(Context context) throws Throwable {
Response response = context.response();
response.setHeader("Cache-Control","no-cache, no-store, must-revalidate");
response.setHeader("Pragma","no-cache");
response.setHeader("Expires","0");
return delegate.call(context);
}
示例14: call
import play.mvc.Http.Response; //导入依赖的package包/类
public F.Promise<Result> call(Context context) throws Throwable {
Response response = context.response();
response.setHeader("Access-Control-Allow-Origin",configuration.value());
if ( context.request().method().equals("OPTIONS")) {
response.setHeader("Access-Control-Allow-Methods","POST, DELETE");
response.setHeader("Access-Control-Max-Age","3600");
response.setHeader("Access-Control-Allow-Headers","Origin, X-Requested-With, Content-Type, Accept, Authorization, Call-Origin");
return F.Promise.pure((Result)ok());
}
response.setHeader("Access-Control-Allow-Headers","X-Requested-With");
return delegate.call(context);
}
示例15: doSetHeader
import play.mvc.Http.Response; //导入依赖的package包/类
@Override
protected void doSetHeader(String name, String value) {
throwIfWritten();
// https://github.com/playframework/playframework/issues/2726
if (name.equalsIgnoreCase(Response.CONTENT_TYPE)) {
name = Response.CONTENT_TYPE;
}
response.setHeader(name, value);
}