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


Java Response.setContentLength方法代码示例

本文整理汇总了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();
}
 
开发者ID:dice-group,项目名称:FOX,代码行数:25,代码来源:FeedbackHttpHandler.java

示例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();
}
 
开发者ID:dice-group,项目名称:FOX,代码行数:25,代码来源:AbstractFoxHttpHandler.java

示例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);
    }
}
 
开发者ID:jembi,项目名称:openhim-mediator-engine-java,代码行数:10,代码来源:MediatorRootActor.java

示例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();
}
 
开发者ID:sumeetchhetri,项目名称:gatf,代码行数:9,代码来源:GatfConfigToolMojo.java

示例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();
}
 
开发者ID:sumeetchhetri,项目名称:gatf,代码行数:10,代码来源:GatfConfigToolMojo.java

示例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();
	    }
	}
   }
 
开发者ID:sumeetchhetri,项目名称:gatf,代码行数:49,代码来源:GatfReportsHandler.java


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