本文整理汇总了Java中org.glassfish.grizzly.http.server.Response.setContentLength方法的典型用法代码示例。如果您正苦于以下问题:Java Response.setContentLength方法的具体用法?Java Response.setContentLength怎么用?Java Response.setContentLength使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.glassfish.grizzly.http.server.Response
的用法示例。
在下文中一共展示了Response.setContentLength方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setResponse
import org.glassfish.grizzly.http.server.Response; //导入方法依赖的package包/类
/**
* Writes data to response.
*
* @param response
* @param text
* @param status
* @param contentType
*/
protected void setResponse(final Response response, final String data, final int status,
final String contentType) {
response.setContentType(contentType);
response.setCharacterEncoding("utf-8");
response.setStatus(status);
final byte[] bytes = data.getBytes();
try {
response.setContentLength(bytes.length);
response.getWriter().write(data);
} catch (final IOException e) {
LOG.error("\n", e);
}
response.finish();
}
示例2: setResponse
import org.glassfish.grizzly.http.server.Response; //导入方法依赖的package包/类
/**
* Writes data to response.
*
* @param response
* @param text
* @param status
* @param contentType
*/
protected void setResponse(final Response response, final String data, final int status,
final String contentType) {
response.setContentType(contentType);
response.setCharacterEncoding("utf-8");
response.setStatus(status);
final byte[] bytes = data.getBytes();
try {
response.setContentLength(bytes.length);
response.getWriter().write(data);
} catch (final IOException e) {
LOG.error(e.getLocalizedMessage(), e);
}
response.finish();
}
示例3: handleResponse
import org.glassfish.grizzly.http.server.Response; //导入方法依赖的package包/类
private void handleResponse(Response grizzlyResponseHandle, Integer status, String contentType, String body) throws IOException {
grizzlyResponseHandle.setStatus(status);
if (contentType!=null && body!=null) {
grizzlyResponseHandle.setContentType(contentType);
grizzlyResponseHandle.setContentLength(body.getBytes().length);
grizzlyResponseHandle.setCharacterEncoding("UTF-8");
grizzlyResponseHandle.getWriter().write(body);
}
}
示例4: handleError
import org.glassfish.grizzly.http.server.Response; //导入方法依赖的package包/类
protected static void handleError(Throwable e, Response response, HttpStatus status) throws IOException
{
String configJson = e.getMessage()==null?ExceptionUtils.getStackTrace(e):e.getMessage();
response.setContentLength(configJson.length());
response.getWriter().write(configJson);
response.setStatus(status==null?HttpStatus.INTERNAL_SERVER_ERROR_500:status);
if(status==null)e.printStackTrace();
}
示例5: handleErrorJson
import org.glassfish.grizzly.http.server.Response; //导入方法依赖的package包/类
protected static void handleErrorJson(Throwable e, Response response, HttpStatus status) throws IOException
{
String configJson = e.getMessage()==null?ExceptionUtils.getStackTrace(e):e.getMessage();
response.setContentType(MediaType.APPLICATION_XML);
response.setContentLength(configJson.length());
response.getWriter().write(configJson);
response.setStatus(status==null?HttpStatus.INTERNAL_SERVER_ERROR_500:status);
if(status==null)e.printStackTrace();
}
示例6: service
import org.glassfish.grizzly.http.server.Response; //导入方法依赖的package包/类
@Override
public void service(Request request, Response response) throws Exception {
response.setHeader("Cache-Control", "no-cache, no-store");
try {
final GatfExecutorConfig gatfConfig = GatfConfigToolMojo.getGatfExecutorConfig(mojo, null);
String basepath = gatfConfig.getOutFilesBasePath()==null?mojo.rootDir:gatfConfig.getOutFilesBasePath();
String dirPath = basepath + SystemUtils.FILE_SEPARATOR + gatfConfig.getOutFilesDir();
if(!new File(dirPath).exists()) {
new File(dirPath).mkdir();
}
if(request.getMethod().equals(Method.GET) ) {
new CacheLessStaticHttpHandler(dirPath).service(request, response);
} else if(request.getMethod().equals(Method.PUT) ) {
String action = request.getParameter("action");
String testcaseFileName = request.getParameter("testcaseFileName");
String testCaseName = request.getParameter("testCaseName");
boolean isServerLogsApi = request.getParameter("isServerLogsApi")!=null;
boolean isExternalLogsApi = request.getParameter("isExternalLogsApi")!=null;
TestCaseReport tcReport = null;
if(action.equals("replayTest"))
{
tcReport = new org.codehaus.jackson.map.ObjectMapper().readValue(request.getInputStream(),
TestCaseReport.class);
if(tcReport == null) {
throw new RuntimeException("Invalid testcase report details provided");
}
}
else if(isExternalLogsApi && !action.equals("playTest"))
{
tcReport = new org.codehaus.jackson.map.ObjectMapper().readValue(request.getInputStream(),
TestCaseReport.class);
}
Object[] out = executeTest(gatfConfig, tcReport, action, testcaseFileName, testCaseName, isServerLogsApi, isExternalLogsApi, 0, false);
if(out[1]!=null) {
response.setContentType(out[2].toString());
response.setContentLength(((String)out[1]).length());
response.getWriter().write((String)out[1]);
}
response.setStatus((HttpStatus)out[0]);
}
} catch (Exception e) {
GatfConfigToolMojo.handleError(e, response, null);
} finally {
if(lock.isLocked()) {
lock.unlock();
}
}
}