Orion Application Server error pages - Java question

Status
Not open for further replies.

KarlShea

Ars Tribunus Militum
2,277
Subscriptor++
I hope this is the right forum. What I want to do is make a custom error page in Orion, using the code

Code:
<error-page>
     <error-code>500</error-code>
     <location>/500error.jsp</location>
</error-page>

in the web.xml file for the site.

This works fine, but is there something I can put in the error page JSP to get the current stack trace? I cannot find out how to do this.

Any ideas?
 

PhaserLogic

Seniorius Lurkius
48
Include the following in your 500error.jsp page:
Code:
<%@ page isErrorPage="true" %>
<% exception.printStackTrace(out); %>

The documentation for printStackTrace is here.

Adapted from the sample error page that Orion distributes with their server (default-web-app\examples\jsp\error\errorpge.jsp):
Code:
<html>
<!--
  Copyright (c) 1999 Sun Microsystems, Inc. All Rights Reserved.

 This software is the confidential and proprietary information of Sun
 Microsystems, Inc. ("Confidential Information").  You shall not
 disclose such Confidential Information and shall use it only in
 accordance with the terms of the license agreement you entered into
 with Sun.

 SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
 SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
 IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
 SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
 THIS SOFTWARE OR ITS DERIVATIVES.
-->

<body bgcolor="red">

	<%@ page isErrorPage="true" %>
	<h1> The exception <%= exception.getMessage() %> tells me you
	     made a wrong choice. 
</body>
</html>

Edit: Added link to documentation.

[This message was edited by PhaserLogic on April 06, 2002 at 00:35.]

[This message was edited by PhaserLogic on April 06, 2002 at 00:36.]
 

KarlShea

Ars Tribunus Militum
2,277
Subscriptor++
When I use this code:

Code:
1:  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2:  
3:  <html>
4:  <head>
5:  	<title>500 Internal Server Error</title>
6:  </head>
7:  
8:  <body>
9:  500 Internal Server Error
10: <%@ page isErrorPage="true" %>
11: <%= exception.getMessage() %>
12: 
13: </body>
14: </html>

I get this error:

Code:
Recursive error in error-page calling for /500error.jsp, see the application log for details.

This is in the application log:

Code:
4/6/02 11:08 AM mailthingy: Servlet error
java.lang.NullPointerException
	at /500error.jsp._jspService(/500error.jsp.java:28) (JSP page line 2)
	at com.orionserver[Orion/1.5.2 (build 10460)].http.OrionHttpJspPage.service(Unknown Source)
	at com.evermind[Orion/1.5.2 (build 10460)]._ah._rad(Unknown Source)
	at com.evermind[Orion/1.5.2 (build 10460)].server.http.JSPServlet.service(Unknown Source)
	at com.evermind[Orion/1.5.2 (build 10460)]._cxb._abe(Unknown Source)
	at com.evermind[Orion/1.5.2 (build 10460)]._cxb.include(Unknown Source)
	at com.evermind[Orion/1.5.2 (build 10460)].server.http.EvermindHttpServletResponse.sendError(Unknown Source)
	at com.evermind[Orion/1.5.2 (build 10460)]._ah._rad(Unknown Source)
	at com.evermind[Orion/1.5.2 (build 10460)].server.http.JSPServlet.service(Unknown Source)
	at com.evermind[Orion/1.5.2 (build 10460)]._cxb._abe(Unknown Source)
	at com.evermind[Orion/1.5.2 (build 10460)]._cxb._uec(Unknown Source)
	at com.evermind[Orion/1.5.2 (build 10460)]._io._twc(Unknown Source)
	at com.evermind[Orion/1.5.2 (build 10460)]._io._gc(Unknown Source)
	at com.evermind[Orion/1.5.2 (build 10460)]._if.run(Unknown Source)

Could it be that the 500 errors can't be overridden?
 

KarlShea

Ars Tribunus Militum
2,277
Subscriptor++
Yeah that's what I'm having a problem with. If there is a way to override the error pages I was hoping that an exception was available to the page so something more informative could be printed out than "500 Internal Server Error." Kind of like a session variable or something. I dunno.

With the example pages included with orion it does show that there is an exception called, oddly enough, 'exception' :) but it doesn't look like that's getting passed to the 500 page.
 

KarlShea

Ars Tribunus Militum
2,277
Subscriptor++
This is the new page:

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
	<title>500 Internal Server Error</title>
</head>

<body>
500 Internal Server Error
<%@ page isErrorPage="true" %>

<% 	Exception e = new Exception();
	e.printStackTrace(out);	%>

</body>
</html>

But I get the same recursive error:

Code:
4/6/02 3:43 PM mailthingy: Recursive error in error-page calling for /500error.jsp
javax.servlet.ServletException: Recursive error in error-page calling for /500error.jsp (status 500)

I tried removing the
Code:
<%@ page isErrorPage="true" %>
and that didn't change anything.

[This message was edited by KarlShea on April 06, 2002 at 17:07.]
 

Aatos

Ars Tribunus Militum
2,639
This is something I hacked together, feel free to use if you wish. Hopefully mozilla doesn't screw up the formatting too badly.

Code:
<%@ page isErrorPage="true" %> <%@ page import="java.util.*, java.io.*" %> 
<%@ page import="javax.mail.*, javax.mail.internet.*" %>
Error in application:
<%= exception %>
<%= makeErrorReport(request, exception) %>
<% 

try { 
  String mailServer = "10.0.0.1"; 
  String subject = "JSP Error Notification"; 
  String [] to = { "foo@bar" }; 
  String from = "foo@bar"; 

  sendEmail(mailServer, subject, to, from, makeErrorReport(request, exception)); 
} catch (AddressException e) { } 
  catch (MessagingException e) { } 
%> 
<%! 
public String makeErrorReport (HttpServletRequest req, Throwable e) {    

  StringBuffer buffer = new StringBuffer(); 
  reportException(buffer, e);    
  reportRequest(buffer, req); 
  reportParameters(buffer, req);  

  reportHeaders(buffer, req); 
  reportCookies(buffer, req); 
  return buffer.toString(); 
} 

public void reportException (StringBuffer   
  buffer, Throwable e) { 

StringWriter writer = new StringWriter(); 
e.printStackTrace(new PrintWriter(writer)); buffer.append(writer.getBuffer()); 
buffer.append('\n'); 
} 

public void reportRequest (StringBuffer buffer, HttpServletRequest req) { 
buffer.append("Request: "); 
buffer.append(req.getMethod()); 
buffer.append(' '); 
buffer.append(HttpUtils.getRequestURL(req)); 
String queryString = req.getQueryString(); 

if (queryString != null) { 
 buffer.append('?'); 
 buffer.append(queryString); 
} 

buffer.append("\nSession ID: "); 
String sessionId = req.getRequestedSessionId(); 
if (sessionId == null) { 
  buffer.append("none"); 
} else if (req.isRequestedSessionIdValid()) { 
 buffer.append(sessionId); 
 buffer.append(" (from "); 
 if (req.isRequestedSessionIdFromCookie()) 
   buffer.append("cookie)\n"); 
  else if (req.isRequestedSessionIdFromURL()) 
   buffer.append("url)\n"); 
  else buffer.append("unknown)\n"); 
} else { buffer.append("invalid\n"); } 
} 

public void reportParameters (StringBuffer buffer, HttpServletRequest req) { 

 Enumeration names = req.getParameterNames(); 
 if (names.hasMoreElements()) { 
   buffer.append("Parameters:\n"); 
   while (names.hasMoreElements()) { 
     String name = (String) names.nextElement(); 
     String[] values = req.getParameterValues(name); 
     for (int i = 0; i < values.length; ++i) { 
       buffer.append(" "); 
       buffer.append(name); 
       buffer.append(" = "); 
       buffer.append(values[i]); 
       buffer.append('\n'); 
} } } }

public void reportHeaders (StringBuffer buffer, HttpServletRequest req) { 

Enumeration names = req.getHeaderNames(); 
if (names.hasMoreElements()) { 
  buffer.append("Headers:\n"); 
  while (names.hasMoreElements()) { 
    String name = (String) names.nextElement(); 
    String value = (String) req.getHeader(name); 
    buffer.append(" "); buffer.append(name); 
    buffer.append(": "); buffer.append(value); 
    buffer.append('\n'); 
 } } 
public void reportCookies (StringBuffer buffer, HttpServletRequest req) { 
Cookie[] cookies = req.getCookies(); 
int l = cookies.length; 
if (l > 0) { 
  buffer.append("Cookies:\n"); 
  for (int i = 0; i < l; ++i) { 
  Cookie cookie = cookies[i]; 
  buffer.append(" "); 
  buffer.append(cookie.getName()); 
  buffer.append(" = "); 
  buffer.append(cookie.getValue()); 
  buffer.append('\n'); } } } 

public void sendEmail (String mailServer, String subject, String to[], String from, String messageText) throws AddressException, MessagingException { 
//Create session 
Properties mailProps = new Properties(); mailProps.put("mail.smtp.host", mailServer); //mailProps.put("mail.debug", true); Session mailSession = Session.getDefaultInstance(mailProps, null); //mailSession.setDebug(true); // Construct addresses 
int toCount = to.length; 
InternetAddress[] toAddrs = new InternetAddress[toCount]; 
for (int i = 0; i < toCount; ++i) { 
  toAddrs[i] = new InternetAddress(to[i]); 
} 
InternetAddress fromAddr = new InternetAddress(from); // Create and 
initialize message Message message = new MimeMessage(mailSession); 
message.setFrom(fromAddr); 
message.setRecipients(Message.RecipientType.TO, toAddrs);
message.setSubject(subject); 
message.setContent(messageText.toString(), "text/plain"); // Send 
message Transport.send(message); 
} 
%>
 

KarlShea

Ars Tribunus Militum
2,277
Subscriptor++
Yeah, I have forced the exception in web.xml, and everything works fine for all the exceptions I'm overriding (400 and 404) except when I try to override the 500 error and print the stack trace. If I don't try and get what the exception was, everything works fine (like I can print out "500 Server Error", but I can't print out what it actually was).

I'll check out that website though, thanks.
 
Status
Not open for further replies.