I noticed that AssertionFailedErrorWrapper doesn't actually build up a StackTraceElement array from the text based stack trace. This works ok until your IDE calls e.getStackTrace() and gets the stack from the httpclient which isn't that useful.

So anyways, I fixed it to rebuild the stack from the stack trace message and now you can call e.getStackTrace() and get meaningful results.

Can someone out there commit this change to SVN?

Mark

--
Mark Robinson, EIT - Mizar LLC
mark.robin...@mizar.com
111-1010 McKenzie Ave.
Victoria, BC
V8X 4B2
(360) 296-4125

/* 
 * ========================================================================
 * 
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 * ========================================================================
 */
package org.apache.cactus.internal.client;

import java.io.Console;
import java.io.PrintStream;
import java.io.PrintWriter;

import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import junit.framework.AssertionFailedError;

/**
 * Same as <code>ServletExceptionWrapper</code> except that this exception class
 * extends JUnit <code>AssertionFailedError</code> so that JUnit will
 * print a different message in it's runner console.
 *
 * @version $Id: AssertionFailedErrorWrapper.java 238991 2004-05-22 11:34:50Z 
vmassol $
 */
public class AssertionFailedErrorWrapper extends AssertionFailedError
{
    /**
     * The stack trace that was sent back from the servlet redirector as a
     * string.
     */
    private String stackTrace;

    /**
     * The class name of the exception that was raised on the server side.
     */
    private String className;

    /**
     * Standard throwable constructor.
     *
     * @param theMessage the exception message
     */
    public AssertionFailedErrorWrapper(String theMessage)
    {
        super(theMessage);
    }

    /**
     * Standard throwable constructor.
     */
    public AssertionFailedErrorWrapper()
    {
        super();
    }

    /**
   * The constructor to use to simulate a real exception.
   *
   * @param theMessage the server exception message
   * @param theClassName the server exception class name
   * @param theStackTrace the server exception stack trace
   */
  public AssertionFailedErrorWrapper(String theMessage, String theClassName, 
String theStackTrace) {
    super(theMessage);
    this.className = theClassName;
    this.stackTrace = theStackTrace;
    Pattern pattern = Pattern.compile("at 
((\\S*)\\.(\\w*))\\((\\S*):(\\d*)\\)");
    Matcher matcher = pattern.matcher(theStackTrace);
    Console console = System.console();

    ArrayList elements = new ArrayList();

    while (matcher.find()) {
      System.out.println("Match found: " + matcher.group());
      System.out.println("I found : " + matcher.groupCount() + " groups");

      String className = matcher.group(2);
      String methodName = matcher.group(3);
      String fileName = matcher.group(4);
      String lineNumberString = matcher.group(5);
      int lineNumber = Integer.parseInt(lineNumberString, 10);
      elements.add(new StackTraceElement(className, methodName, fileName, 
lineNumber));

    }
    this.setStackTrace((StackTraceElement[])elements.toArray(new 
StackTraceElement[0]));
  }

    /**
     * Simulates a printing of a stack trace by printing the string stack trace.
     *
     * @param thePs the stream to which to output the stack trace
     */
    public void printStackTrace(PrintStream thePs)
    {
        if (this.stackTrace == null)
        {
            thePs.print(getMessage());
        }
        else
        {
            thePs.print(this.stackTrace);
        }
    }

    /**
     * Simulates a printing of a stack trace by printing the string stack trace.
     *
     * @param thePw the writer to which to output the stack trace
     */
    public void printStackTrace(PrintWriter thePw)
    {
        if (this.stackTrace == null)
        {
            thePw.print(getMessage());
        }
        else
        {
            thePw.print(this.stackTrace);
        }
    }

    /**
     * @return the wrapped class name
     */
    public String getWrappedClassName()
    {
        return this.className;
    }
}

---------------------------------------------------------------------
To unsubscribe, e-mail: cactus-dev-unsubscr...@jakarta.apache.org
For additional commands, e-mail: cactus-dev-h...@jakarta.apache.org

Reply via email to