[HER-1822] H3: bean browser in non-paused crawl sometimes raises exceptions, doesn't work

* JobRelatedResource.java
    add more property names to blacklist
    route all relevant requests through new utilitiy getPropertyDescriptors method that patches instances as necessary to suppress problems
This commit is contained in:
gojomo
2010-09-21 10:28:29 +00:00
parent 966646871c
commit c701cd391a
@@ -33,6 +33,7 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.commons.collections.SetUtils;
import org.apache.commons.lang.StringUtils;
import org.archive.crawler.framework.CrawlJob;
import org.archive.crawler.framework.Engine;
@@ -110,7 +111,7 @@ public abstract class JobRelatedResource extends Resource {
alreadyWritten.add(obj);
BeanWrapperImpl bwrap = new BeanWrapperImpl(obj);
for (PropertyDescriptor pd : bwrap.getPropertyDescriptors()) {
for (PropertyDescriptor pd : getPropertyDescriptors(bwrap)) {
if (pd.getReadMethod() != null) {
String propName = pd.getName();
Object propValue = bwrap.getPropertyValue(propName);
@@ -299,12 +300,8 @@ public abstract class JobRelatedResource extends Resource {
Collection<Object> properties = new LinkedList<Object>();
BeanWrapperImpl bwrap = new BeanWrapperImpl(object);
for (PropertyDescriptor pd : bwrap.getPropertyDescriptors()) {
if (object instanceof DescriptorUpdater) {
((DescriptorUpdater) object).updateDescriptor(pd);
} else {
defaultUpdateDescriptor(pd);
}
for (PropertyDescriptor pd : getPropertyDescriptors(bwrap)) {
if (pd.getReadMethod() != null && !pd.isHidden()) {
String propName = pd.getName();
if (beanPath != null) {
@@ -366,6 +363,23 @@ public abstract class JobRelatedResource extends Resource {
return info;
}
/**
* Get and modify the PropertyDescriptors associated with the BeanWrapper.
* @param bwrap
* @return
*/
protected PropertyDescriptor[] getPropertyDescriptors(BeanWrapperImpl bwrap) {
PropertyDescriptor[] descriptors = bwrap.getPropertyDescriptors();
for(PropertyDescriptor pd : descriptors) {
if (DescriptorUpdater.class.isAssignableFrom(bwrap.getWrappedClass()) ) {
((DescriptorUpdater) bwrap.getWrappedInstance()).updateDescriptor(pd);
} else {
defaultUpdateDescriptor(pd);
}
}
return descriptors;
}
/**
* Get a map giving object beanNames.
*
@@ -446,12 +460,7 @@ public abstract class JobRelatedResource extends Resource {
pw.println(object.getClass().getName()+"</legend>");
pw.println("<table>");
BeanWrapperImpl bwrap = new BeanWrapperImpl(object);
for(PropertyDescriptor pd : bwrap.getPropertyDescriptors()) {
if(object instanceof DescriptorUpdater) {
((DescriptorUpdater)object).updateDescriptor(pd);
} else {
defaultUpdateDescriptor(pd);
}
for(PropertyDescriptor pd : getPropertyDescriptors(bwrap)) {
if(pd.getReadMethod()!=null && !pd.isHidden()) {
String propName = pd.getName();
if(beanPath!=null) {
@@ -499,13 +508,13 @@ public abstract class JobRelatedResource extends Resource {
pw.write(close);
}
/** suppress problematic properties */
static HashSet<String> HIDDEN_PROPS = new HashSet<String>(
Arrays.asList(new String[]
{"class","declaringClass","keyedProperties","running","first","last","empty"}
{"class","declaringClass","keyedProperties","running","first","last","empty", "inbound", "outbound", "cookiesMap"}
));
protected void defaultUpdateDescriptor(PropertyDescriptor pd) {
// make noneditable
// make non-editable
try {
pd.setWriteMethod(null);
} catch (IntrospectionException e) {