本文整理汇总了Java中play.mvc.Http.Response类的典型用法代码示例。如果您正苦于以下问题:Java Response类的具体用法?Java Response怎么用?Java Response使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Response类属于play.mvc.Http包,在下文中一共展示了Response类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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());
}
开发者ID:theAgileFactory,项目名称:app-framework,代码行数:21,代码来源:ApiControllerUtilsServiceImpl.java
示例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);
}
}
开发者ID:eBay,项目名称:restcommander,代码行数:25,代码来源:Images.java
示例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;
}
开发者ID:eBay,项目名称:restcommander,代码行数:18,代码来源:DBPlugin.java
示例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);
}
开发者ID:eBay,项目名称:restcommander,代码行数:20,代码来源:Evolutions.java
示例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);
}
开发者ID:eBay,项目名称:restcommander,代码行数:25,代码来源:FunctionalTest.java
示例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);
}
开发者ID:eBay,项目名称:restcommander,代码行数:28,代码来源:FunctionalTest.java
示例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);
}
开发者ID:eBay,项目名称:restcommander,代码行数:27,代码来源:FunctionalTest.java
示例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);
}
开发者ID:eBay,项目名称:restcommander,代码行数:25,代码来源:FunctionalTest.java
示例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;
}
开发者ID:eBay,项目名称:restcommander,代码行数:18,代码来源:FunctionalTest.java
示例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()));
}
};
}
开发者ID:NationStates,项目名称:NationStatesPlusPlus,代码行数:19,代码来源:RMBController.java
示例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;
}
开发者ID:NationStates,项目名称:NationStatesPlusPlus,代码行数:19,代码来源:Utils.java
示例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);
}
});
}
开发者ID:theAgileFactory,项目名称:app-framework,代码行数:9,代码来源:ApiAuthenticationAction.java
示例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);
}
开发者ID:metno,项目名称:poseidon-rest,代码行数:8,代码来源:NoCacheComposition.java
示例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);
}
开发者ID:metno,项目名称:poseidon-rest,代码行数:15,代码来源:CorsComposition.java
示例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);
}
开发者ID:vibe-project,项目名称:vibe-java-platform,代码行数:10,代码来源:PlayServerHttpExchange.java
示例16: unwrap
import play.mvc.Http.Response; //导入依赖的package包/类
/**
* {@link Request} and {@link Response} are available.
*/
@Override
public <T> T unwrap(Class<T> clazz) {
return Request.class.isAssignableFrom(clazz) ?
clazz.cast(request) :
Response.class.isAssignableFrom(clazz) ?
clazz.cast(response) :
null;
}
开发者ID:vibe-project,项目名称:vibe-java-platform,代码行数:12,代码来源:PlayServerHttpExchange.java
示例17: getAppstatsIdFromResponse
import play.mvc.Http.Response; //导入依赖的package包/类
private static String getAppstatsIdFromResponse() {
String result = "nada";
Response request = Response.current();
if (request != null)
{
Header header = request.headers.get("X-TraceUrl");
if (header != null)
{
String value = header.value();
result = value;
if (StringUtils.isNotEmpty(value))
{
String[] parts = value.split("\\?")[1].split("&");
for (String part : parts)
{
String[] nameValue = part.split("=");
if ("time".equals(nameValue[0]))
{
result = nameValue[1];
Logger.info("profiler: appstats " + result);
}
}
}
}
}
return result;
}
开发者ID:PerfectCarl,项目名称:play-profiler,代码行数:29,代码来源:ProfilerEnhancer.java
示例18: apply
import play.mvc.Http.Response; //导入依赖的package包/类
public void apply(Request request, Response response) {
try {
setContentTypeIfNotSet(response, "text/xml");
response.out.write(xml.getBytes(getEncoding()));
} catch(Exception e) {
throw new UnexpectedException(e);
}
}
开发者ID:eBay,项目名称:restcommander,代码行数:9,代码来源:RenderXml.java
示例19: apply
import play.mvc.Http.Response; //导入依赖的package包/类
public void apply(Request request, Response response) {
try {
final String contentType = MimeTypes.getContentType(name, "text/plain");
response.out.write(content.getBytes(getEncoding()));
setContentTypeIfNotSet(response, contentType);
} catch (Exception e) {
throw new UnexpectedException(e);
}
}
开发者ID:eBay,项目名称:restcommander,代码行数:10,代码来源:RenderTemplate.java
示例20: apply
import play.mvc.Http.Response; //导入依赖的package包/类
public void apply(Request request, Response response) {
try {
setContentTypeIfNotSet(response, "text/plain; charset=" + Http.Response.current().encoding);
response.out.write(text.getBytes(getEncoding()));
} catch(Exception e) {
throw new UnexpectedException(e);
}
}
开发者ID:eBay,项目名称:restcommander,代码行数:9,代码来源:RenderText.java
注:本文中的play.mvc.Http.Response类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论