当前位置: 首页>>代码示例>>Java>>正文


Java Response.setHeader方法代码示例

本文整理汇总了Java中play.mvc.Http.Response.setHeader方法的典型用法代码示例。如果您正苦于以下问题:Java Response.setHeader方法的具体用法?Java Response.setHeader怎么用?Java Response.setHeader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在play.mvc.Http.Response的用法示例。


在下文中一共展示了Response.setHeader方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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

示例3: 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

示例4: 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

示例5: 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

示例6: apply

import play.mvc.Http.Response; //导入方法依赖的package包/类
public void apply(Request request, Response response) {
    try {
        response.status = Http.StatusCode.FOUND;
        response.setHeader("Location", file);
    } catch (Exception e) {
        throw new UnexpectedException(e);
    }
}
 
开发者ID:eBay,项目名称:restcommander,代码行数:9,代码来源:RedirectToStatic.java

示例7: apply

import play.mvc.Http.Response; //导入方法依赖的package包/类
public void apply(Request request, Response response) {
    try {
        if (url.startsWith("http")) {
            //
        } else if (url.startsWith("/")) {
            url = String.format("http%s://%s%s%s", request.secure ? "s" : "", request.domain, (request.port == 80 || request.port == 443) ? "" : ":" + request.port, url);
        } else {
            url = String.format("http%s://%s%s%s%s", request.secure ? "s" : "", request.domain, (request.port == 80 || request.port == 443) ? "" : ":" + request.port, request.path, request.path.endsWith("/") ? url : "/" + url);
        }
        response.status = code;
        response.setHeader("Location", url);
    } catch (Exception e) {
        throw new UnexpectedException(e);
    }
}
 
开发者ID:eBay,项目名称:restcommander,代码行数:16,代码来源:Redirect.java

示例8: writeChunk

import play.mvc.Http.Response; //导入方法依赖的package包/类
public void writeChunk(Request playRequest, Response playResponse, ChannelHandlerContext ctx, HttpRequest nettyRequest, Object chunk) {
    try {
        if (playResponse.direct == null) {
            playResponse.setHeader("Transfer-Encoding", "chunked");
            playResponse.direct = new LazyChunkedInput();
            copyResponse(ctx, playRequest, playResponse, nettyRequest);
        }
        ((LazyChunkedInput) playResponse.direct).writeChunk(chunk);
        chunkedWriteHandler.resumeTransfer();
    } catch (Exception e) {
        throw new UnexpectedException(e);
    }
}
 
开发者ID:eBay,项目名称:restcommander,代码行数:14,代码来源:PlayHandler.java

示例9: apply

import play.mvc.Http.Response; //导入方法依赖的package包/类
@Override
public void apply(final Request request, final Response response) {
	try {
		response.status = 206;
		Header rangeHeader = request.headers.get("range");
		String rangeValue = rangeHeader.value().trim().substring("bytes=".length());
		long fileLength = this.file.length();
		long start, end;
		if (rangeValue.startsWith("-")) {
			end = fileLength - 1;
			start = fileLength - 1 - Long.parseLong(rangeValue.substring("-".length()));
		} else {
			String[] range = rangeValue.split("-");
			start = Long.parseLong(range[0]);
			end = range.length > 1 ? Long.parseLong(range[1]) : fileLength - 1;
		}
		if (end > fileLength - 1) {
			end = fileLength - 1;
		}
		if (start <= end) {
			long contentLength = end - start + 1;
			
			Loggers.Play.debug("Partial download, start: " + start + ", contentLength: " + contentLength);
			
			response.setHeader("Content-Length", contentLength + "");
			response.setHeader("Content-Range", "bytes " + start + "-" + end + "/" + fileLength);
			response.setHeader("Content-Type", mime);
			RandomAccessFile raf = new RandomAccessFile(this.file, "r");
			response.direct = new ChunkedFile(raf, start, contentLength, 8192);
		}
	} catch (Exception e) {
		throw new UnexpectedException(e);
	}
}
 
开发者ID:hdsdi3g,项目名称:MyDMAM,代码行数:35,代码来源:PartialContent.java

示例10: apply

import play.mvc.Http.Response; //导入方法依赖的package包/类
public void apply(Request request, Response response) {
    response.status = Http.StatusCode.NOT_MODIFIED;
    if (etag != null) {
        response.setHeader("Etag", etag);
    }
}
 
开发者ID:eBay,项目名称:restcommander,代码行数:7,代码来源:NotModified.java

示例11: apply

import play.mvc.Http.Response; //导入方法依赖的package包/类
public void apply(Request request, Response response) {
    response.status = Http.StatusCode.UNAUTHORIZED;
    response.setHeader("WWW-Authenticate", "Basic realm=\"" + realm + "\"");
}
 
开发者ID:eBay,项目名称:restcommander,代码行数:5,代码来源:Unauthorized.java

示例12: handleDefaultPostHeaders

import play.mvc.Http.Response; //导入方法依赖的package包/类
public static void handleDefaultPostHeaders(Request request, Response response) {
	response.setHeader("Access-Control-Allow-Origin", "*");
	response.setHeader("Access-Control-Allow-Methods", "POST, GET, HEAD");
	response.setHeader("Access-Control-Max-Age", "60");
	response.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
}
 
开发者ID:NationStates,项目名称:NationStatesPlusPlus,代码行数:7,代码来源:Utils.java


注:本文中的play.mvc.Http.Response.setHeader方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。