Package dovetaildb.servlet

Source Code of dovetaildb.servlet.HttpReturnThrowable

package dovetaildb.servlet;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import dovetaildb.api.ApiException;



public class HttpReturnThrowable extends RuntimeException {

  private static final long serialVersionUID = 8830785031961251854L;
 
  int status;
  List<String> headers;
  String content;
 
  public HttpReturnThrowable(int status, List<String> headers, String content) {
    super(content);
    this.status = status;
    this.headers = headers;
    this.content = content;
  }
 
  public void respond(HttpServletResponse response) {
    for(String header : headers) {
      int colonPos = header.indexOf(":");
      if (colonPos == -1) throw new ApiException("InvalidHttpHeader", "Header must contain a colon character");
      response.addHeader(header.substring(0, colonPos), header.substring(colonPos+1));
    }
    try {
      response.getWriter().write(content);
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
    response.setStatus(status);
  }
}
TOP

Related Classes of dovetaildb.servlet.HttpReturnThrowable

TOP
Copyright © 2018 www.massapi.com. 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.