001/* 002 * (C) Copyright 2006-2009 Nuxeo SAS (http://nuxeo.com/) and contributors. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * 016 * $Id$ 017 */ 018 019package org.nuxeo.ecm.platform.error.web; 020 021import java.io.PrintWriter; 022import java.io.StringWriter; 023 024import javax.ws.rs.GET; 025import javax.ws.rs.Path; 026import javax.ws.rs.Produces; 027import javax.ws.rs.WebApplicationException; 028import javax.ws.rs.core.Response; 029 030import org.nuxeo.ecm.core.api.DocumentSecurityException; 031import org.nuxeo.ecm.core.api.NuxeoException; 032import org.nuxeo.ecm.webengine.WebException; 033import org.nuxeo.ecm.webengine.model.WebObject; 034import org.nuxeo.ecm.webengine.model.impl.ModuleRoot; 035 036@Path("/error") 037@WebObject(type = "error") 038@Produces("text/html; charset=UTF-8") 039public class WebengineError extends ModuleRoot { 040 041 /** 042 * Default view 043 */ 044 @GET 045 public Object doGet() { 046 return getView("index"); 047 } 048 049 @Path("webException") 050 public Object getWebException() { 051 throw new WebException("Web exception"); 052 } 053 054 @Path("checkedError") 055 public Object getCheckedError() { 056 throw new NuxeoException("CheckedError in webengine"); 057 } 058 059 @Path("uncheckedError") 060 public Object getUncheckedError() { 061 throw new NullPointerException("UncheckedError in webengine"); 062 } 063 064 @Path("securityError") 065 public Object getSecurityError() throws DocumentSecurityException { 066 throw new DocumentSecurityException("Security error in webengine"); 067 } 068 069 public Object handleError(WebApplicationException e) { 070 StringWriter sw = new StringWriter(); 071 PrintWriter pw = new PrintWriter(sw); 072 pw.println("<html>"); 073 pw.println("<head><title>WebEbgine Error Test</title></head>"); 074 pw.println("<body>"); 075 pw.println("WEBENGINE HANDLED ERROR: "); 076 e.printStackTrace(pw); 077 pw.println("</body>"); 078 pw.println("</html>"); 079 pw.close(); 080 return Response.status(500).entity(sw.toString()).build(); 081 } 082 083}