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


Java Response.setContentType方法代码示例

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


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

示例1: service

import org.glassfish.grizzly.http.server.Response; //导入方法依赖的package包/类
@Override
public void service(Request request, Response resp) throws Exception {
    resp.setCharacterEncoding("utf-8");
    resp.setContentType("text/html");
    Writer writer = resp.getWriter();
    writer.write("<html><head><title>HtmlSocket</title></head><body>");
    writer.write("<h3>HtmlSocket manger</h3><hr><ul>");

    int count = 0;
    MessageCenter sever = ctx.getMessageCenter();
    Collection<ThreadMap> allsub = sever.getSubscribers();
    for (ThreadMap subs : allsub) {
        for (Map.Entry<Long, ISubscriber> item : subs.entrySet()) {
            if (count++ < 20) {
                ISubscriber value = item.getValue();
                String topic = value.getTopic();
                long id = value.getId();
                writer.write(String.format("<li>ID:[%s],Topic:[%s]-[%s]</li>", id, topic, value));
            }
        }
    }
    writer.write("</ul><hr>");
    writer.write(String.format("订阅者[%s]", count));
    writer.write("</body></html>");
}
 
开发者ID:coderczp,项目名称:HtmlSocket,代码行数:26,代码来源:AdminServlet.java

示例2: send404

import org.glassfish.grizzly.http.server.Response; //导入方法依赖的package包/类
private void send404(Response response) {
    response.setStatus(HttpStatus.NOT_FOUND_404);

    response.setContentType("image/png");

    try (InputStream is = this.getClass().getResourceAsStream("/404.png");
        OutputStream os = response.getOutputStream();) {
        byte[] b = new byte[1024];
        while (is.read(b) >= 0) {
            os.write(b);
        }

    } catch (IOException e) {
        logger.error(e);
    }
}
 
开发者ID:mba811,项目名称:loli.io,代码行数:17,代码来源:RedirectFilter.java

示例3: send403

import org.glassfish.grizzly.http.server.Response; //导入方法依赖的package包/类
private void send403(Response response) {
    response.setStatus(HttpStatus.FORBIDDEN_403);

    response.setContentType("image/png");

    try (InputStream is = this.getClass().getResourceAsStream("/403.png");
        OutputStream os = response.getOutputStream();) {
        byte[] b = new byte[1024];
        while (is.read(b) >= 0) {
            os.write(b);
        }

    } catch (IOException e) {
        logger.error(e);
    }
}
 
开发者ID:mba811,项目名称:loli.io,代码行数:17,代码来源:RedirectFilter.java

示例4: handlePost

import org.glassfish.grizzly.http.server.Response; //导入方法依赖的package包/类
@Override
public void handlePost(ByteBuffer postBytes, Request req, Response resp)
		throws IOException {
	try {
		ServerStatusQuery query = ServerStatusQuery.parseFrom(ByteString.copyFrom(postBytes));
		m_processor.processEvent(new PersistEntityEvent(
				new ServerStatusQueryData(query, req.getRemoteAddr(),  req.getRequest().getHttpHeader().toString(), new Date().getTime())));
		ServerStatusResponse.Builder response = ServerStatusResponse.newBuilder();
		response.setServerDate(new Date().getTime());
		response.setStatusCode(getStatusCode(query));
		
		NIOOutputStream out = resp.getNIOOutputStream();
		try {
			resp.setContentType(PROTOBUF_CONTENT_TYPE);
			response.build().writeTo(out);
		} finally {
			out.close();
		}
				
	} finally {
		resp.resume();
	}
}
 
开发者ID:davruet,项目名称:shenanigans.io,代码行数:24,代码来源:VersionCheckHandler.java

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

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

示例7: service

import org.glassfish.grizzly.http.server.Response; //导入方法依赖的package包/类
@Override
public void service(Request request, Response response) throws Exception {

    response.setContentType("application/osm");
    String uri = request.getDecodedRequestURI();
    int suffixIndex = uri.lastIndexOf('.');
    String fileType = uri.substring(suffixIndex);
    OutputStream outStream = response.getOutputStream();
    try {
        String[] coords = uri.substring(1, suffixIndex).split("[,;]");
        double minLat = Double.parseDouble(coords[0]);
        double minLon = Double.parseDouble(coords[1]);
        double maxLat = Double.parseDouble(coords[2]);
        double maxLon = Double.parseDouble(coords[3]);
        if (minLat >= maxLat || minLon >= maxLon || minLat < -90 || maxLat > 90 || minLon < -180 || maxLon > 180) {
            throw new IllegalArgumentException();
        }
        /* Respond to head requests to let the client know the server is alive and the request is valid. */
        if (request.getMethod() == Method.HEAD) {
            response.setStatus(HttpStatus.OK_200);
            return;
        }
        /* TODO filter out buildings on the server side. */
        boolean buildings = coords.length > 4 && "buildings".equalsIgnoreCase(coords[4]);

        OSMEntitySink sink = OSMEntitySink.forStream(uri, outStream);
        TileOSMSource tileSource = new TileOSMSource(osm);
        tileSource.setBoundingBox(minLat, minLon, maxLat, maxLon);
        tileSource.copyTo(sink);
        response.setStatus(HttpStatus.OK_200);
    } catch (Exception ex) {
        response.setStatus(HttpStatus.BAD_REQUEST_400);
        outStream.write("URI format: /min_lat,min_lon,max_lat,max_lon[.pbf|.vex] (all coords in decimal degrees)\n".getBytes());
        ex.printStackTrace();
    } finally {
        outStream.close();
    }
}
 
开发者ID:conveyal,项目名称:osm-lib,代码行数:39,代码来源:VanillaExtract.java

示例8: serveSingleJpeg

import org.glassfish.grizzly.http.server.Response; //导入方法依赖的package包/类
/**
 * Serves the latest image (if any) once.
 * @param request
 * @param response
 */
private void serveSingleJpeg(Request request, Response response) throws IOException {
    final eu.hgross.blaubot.blaubotcam.server.model.ImageMessage lastImageMessage = camDevice.getLastImageMessage();
    response.setHeader("Server", HTTP_HEADER_SERVER_FIELD);
    if (lastImageMessage == null) {
        response.setStatus(HttpStatus.NO_CONTENT_204);
        return;
    }
    response.setContentType(ContentType.newContentType("image/jpeg"));
    response.getOutputStream().write(lastImageMessage.getJpegData());
}
 
开发者ID:Blaubot,项目名称:Blaubot,代码行数:16,代码来源:IPCamServer.java

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

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

示例11: service

import org.glassfish.grizzly.http.server.Response; //导入方法依赖的package包/类
@Override
public void service(Request request, Response response) throws Exception {
    response.setCharacterEncoding("UTF-8");
    response.setContentType("text/javascript");
    response.getWriter().append(
        "function ldCls(res) {\n"
        + "  var request = new XMLHttpRequest();\n"
        + "  request.open('GET', '/classes/' + res, false);\n"
        + "  request.send();\n"
        + "  var arr = eval('(' + request.responseText + ')');\n"
        + "  return arr;\n"
        + "}\n"
        + "var vm = new bck2brwsr(ldCls);\n");
}
 
开发者ID:jtulach,项目名称:dew,代码行数:15,代码来源:DewLauncher.java

示例12: writeOutput

import org.glassfish.grizzly.http.server.Response; //导入方法依赖的package包/类
public void writeOutput(Response response, String contentType, String output) throws IOException {
    response.setContentType(contentType);
    response.setCharacterEncoding("UTF-8");
    response.addHeader("Access-Control-Allow-Origin", "*");
    response.getWriter().write(output);
}
 
开发者ID:dhfbk,项目名称:tint,代码行数:7,代码来源:TintHandler.java

示例13: writeOutput

import org.glassfish.grizzly.http.server.Response; //导入方法依赖的package包/类
public void writeOutput(Response response, String contentType, String output) throws IOException {
	response.setContentType(contentType);
	response.addHeader("Access-Control-Allow-Origin", "*");
	response.getWriter().write(output);
}
 
开发者ID:dkmfbk,项目名称:pikes,代码行数:6,代码来源:AbstractHandler.java

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

示例15: service

import org.glassfish.grizzly.http.server.Response; //导入方法依赖的package包/类
@Override
public void service(Request request, Response response) throws Exception {
    
    if ( request.getMethod() == Method.POST ) {
        InputStream is = request.getInputStream();
        JSONTokener tok = new JSONTokener(new InputStreamReader(is));
        JSONObject obj = new JSONObject(tok);
        String tmpHtml = obj.getString("html");
        String tmpJava = obj.getString("java");
        
        Compile res = Compile.create(tmpHtml, tmpJava);
        List<Diagnostic<? extends JavaFileObject>> err = res.getErrors();
        if (err.isEmpty()) {
            data = res;
            response.getOutputStream().write("[]".getBytes());
            response.setStatus(HttpStatus.OK_200);
        } else {
            
            JSONArray errors = new JSONArray();
            
            for (Diagnostic<? extends JavaFileObject> d : err) {
                JSONObject e = new JSONObject();
                e.put("col", d.getColumnNumber());
                e.put("line", d.getLineNumber());
                e.put("kind", d.getKind().toString());
                e.put("msg", d.getMessage(Locale.ENGLISH));
                errors.put(e);
            }
            
            errors.write(response.getWriter());                
            response.setStatus(HttpStatus.PRECONDITION_FAILED_412);
        }
        
        return;
    }
    
    String r = request.getHttpHandlerPath();
    if (r == null || r.equals("/")) {
        r = "index.html";
    }
    if (r.equals("/result.html")) {
        response.setContentType("text/html");
        if (data != null) {
            response.getOutputBuffer().write(data.getHtml());
        }
        response.setStatus(HttpStatus.OK_200);
        return;
    }
    
    if (r.startsWith("/")) {
        r = r.substring(1);
    }
    
    if (r.endsWith(".html") || r.endsWith(".xhtml")) {
        response.setContentType("text/html");
    }
    OutputStream os = response.getOutputStream();
    try (InputStream is = Dew.class.getResourceAsStream(r) ) {
        copyStream(is, os, request.getRequestURL().toString() );
    } catch (IOException ex) {
        response.setDetailMessage(ex.getLocalizedMessage());
        response.setError();
        response.setStatus(404);
    }
}
 
开发者ID:jtulach,项目名称:dew,代码行数:66,代码来源:Dew.java


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