Package org.jrest4guice.rest.writer

Examples of org.jrest4guice.rest.writer.ResponseWriter


            } catch (Exception e) {
            }
          }else if (ResponseWriter.class.isAssignableFrom(clazz)) {
            // 注册ResponseWriter
            try {
              ResponseWriter writer = (ResponseWriter) clazz
                  .newInstance();
              mimiType = writer.getMimeType();
              mimiTypes = mimiType.split(",");
              for (String mt : mimiTypes) {
                if (!mt.trim().equals(""))
                  writerRegister.registResponseWriter(mt
                      .trim(), clazz);
View Full Code Here


      result = new Exception("服务端没有提供{" + accept + "}类型的数据返回");
      mimeType = MimeType.MIME_OF_ALL;
    }

    // 向客户端写回结果数据
    ResponseWriter responseWriter = responseWriterRegister
        .getResponseWriter(mimeType);
    if (responseWriter != null) {
      try {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        //将结果写入缓冲区
        responseWriter.writeResult(method, out, result, charset, this.options);
       
        final byte[] bytes = out.toByteArray();
        if (bytes.length > 0) {
          //将结果写回客户端
          response.setCharacterEncoding(charset);
          response.setContentType(responseWriter.getMimeType()+";charset="+charset);
          response.getOutputStream().write(bytes);
         
          //如果方法打开了缓存声明,则将结果缓存到服务器
          if (method.isAnnotationPresent(Cache.class)) {
            ResourceCacheManager.getInstance().cacheStaticResource(
                RestContextManager.getCurrentRestUri(),
                responseWriter.getMimeType(), bytes, request);
          }
        }
      } catch (Need2RedirectException e) {
        try {
          response.sendRedirect(e.getRedirectUrl());
View Full Code Here

TOP

Related Classes of org.jrest4guice.rest.writer.ResponseWriter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.