axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "marco" <sfma...@hotmail.com>
Subject Suggestion for more detailed information from InvocationTargetException
Date Tue, 30 Jul 2002 19:37:44 GMT
Hi All,

When the method invocations on a bean causes an InvocationTargetException the root cause of
the exception 
is lost. In my opinion it would be beneficial to the WebService user to echo this root cause.

Imagine that on an object the setFoo(String arg_string)  throws a user defined exception that
the value is not within range. At the moment I would only see an InvocationTargetException
without further details. The code change below would show this.

I'm not too familiar with the process how to suggest a change / enhancement.
Do I first have to report a bug? Can some people first review the change and confirm this
is made on the proper location. 

Here is my code (See the  catch (java.lang.reflect.InvocationTargetException ite){...

Regards,

Marco

/**
 * Class which knows how to update a bean property
 */
public class BeanPropertyTarget implements Target {
    protected static Log log =
        LogFactory.getLog(BeanPropertyTarget.class.getName());

    private Object object;
    private BeanPropertyDescriptor pd;
    private int index = -1;

    /**
     * This constructor is used for a normal property.
     * @param object is the bean class
     * @param pd is the property
     **/
    public BeanPropertyTarget(Object object, BeanPropertyDescriptor pd) {
        this.object = object;
        this.pd     = pd;
        this.index  = -1;  // disable indexing
    }

    /**
     * This constructor is used for an indexed property.
     * @param object is the bean class
     * @param pd is the property
     * @param i is the index
     **/
    public BeanPropertyTarget(Object object, BeanPropertyDescriptor pd, int i) {
        this.object = object;
        this.pd     = pd;
        this.index  = i;
    }

    public void set(Object value) throws SAXException {
        try {
            if (index < 0)
                pd.set(object, value);
            else
                pd.set(object, index, value);
        } catch (Exception e) {

            Class type = pd.getType();
            value = JavaUtils.convert(value, type);
            try {
                if (index < 0)
                    pd.set(object, value);
                else
                    pd.set(object, index, value);
            } catch (java.lang.reflect.InvocationTargetException ite){
                  if (log.isErrorEnabled()) {
                    String field= pd.getName();
                    if (index >=0) {
                       field += "[" + index + "]";
                    }
                    String valueType = "null";
                    if (value != null)
                        valueType = value.getClass().getName();
                    log.error(JavaUtils.getMessage("cantConvert02",
                                                   new String[] {
                                                       valueType,
                                                       field,
                                                       pd.getType().getName()}));
                  } //end log.isErrorEnabled
                  //I assume we are more interested in the inner exception
                  throw new SAXException(new Exception(ite.getTargetException()));
            } catch (Exception ex) {
                String field= pd.getName();
                if (index >=0) {
                    field += "[" + index + "]";
                }
                if (log.isErrorEnabled()) {
                    String valueType = "null";
                    if (value != null)
                        valueType = value.getClass().getName();
                    log.error(JavaUtils.getMessage("cantConvert02",
                                                   new String[] {
                                                       valueType,
                                                       field,
                                                       pd.getType().getName()}));
                }
                throw new SAXException(ex);
            }
        }
    }
}






Mime
View raw message