[DS-1210] NullPointerException on /search-filter without field param

This commit is contained in:
KevinVdV
2012-10-11 12:58:10 +02:00
parent d0a7078cd6
commit f7e4b64ad7
4 changed files with 85 additions and 9 deletions

View File

@@ -12,21 +12,20 @@ import java.io.Serializable;
import java.sql.SQLException;
import java.util.*;
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.cocoon.ProcessingException;
import org.apache.cocoon.ResourceNotFoundException;
import org.apache.cocoon.caching.CacheableProcessingComponent;
import org.apache.cocoon.environment.ObjectModelHelper;
import org.apache.cocoon.environment.Request;
import org.apache.cocoon.environment.SourceResolver;
import org.apache.cocoon.environment.http.HttpEnvironment;
import org.apache.cocoon.util.HashUtil;
import org.apache.commons.lang.StringUtils;
import org.apache.excalibur.source.SourceValidity;
import org.apache.log4j.Logger;
import org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer;
import org.dspace.app.xmlui.utils.ContextUtil;
import org.dspace.app.xmlui.utils.DSpaceValidity;
import org.dspace.app.xmlui.utils.HandleUtil;
import org.dspace.app.xmlui.utils.RequestUtils;
import org.dspace.app.xmlui.utils.UIException;
import org.dspace.app.xmlui.utils.*;
import org.dspace.app.xmlui.wing.Message;
import org.dspace.app.xmlui.wing.WingException;
import org.dspace.app.xmlui.wing.element.Body;
@@ -134,6 +133,22 @@ public class ConfigurableBrowse extends AbstractDSpaceTransformer implements
private Message titleMessage = null;
private Message trailMessage = null;
@Override
public void setup(SourceResolver resolver, Map objectModel, String src, Parameters parameters) throws ProcessingException, SAXException, IOException {
super.setup(resolver, objectModel, src, parameters);
//Verify if we have received valid parameters
try {
getUserParams();
} catch (ResourceNotFoundException e) {
throw new BadRequestException("Invalid parameters");
} catch (SQLException e) {
throw new RuntimeException(e);
} catch (UIException e) {
throw new RuntimeException(e);
}
}
public Serializable getKey()
{
try

View File

@@ -7,18 +7,19 @@
*/
package org.dspace.app.xmlui.aspect.discovery;
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.cocoon.ProcessingException;
import org.apache.cocoon.caching.CacheableProcessingComponent;
import org.apache.cocoon.environment.ObjectModelHelper;
import org.apache.cocoon.environment.Request;
import org.apache.cocoon.environment.SourceResolver;
import org.apache.cocoon.util.HashUtil;
import org.apache.commons.lang.StringUtils;
import org.apache.excalibur.source.SourceValidity;
import org.apache.log4j.Logger;
import org.dspace.app.util.Util;
import org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer;
import org.dspace.app.xmlui.utils.DSpaceValidity;
import org.dspace.app.xmlui.utils.HandleUtil;
import org.dspace.app.xmlui.utils.RequestUtils;
import org.dspace.app.xmlui.utils.UIException;
import org.dspace.app.xmlui.utils.*;
import org.dspace.app.xmlui.wing.Message;
import org.dspace.app.xmlui.wing.WingException;
import org.dspace.app.xmlui.wing.element.*;
@@ -84,6 +85,19 @@ public class SearchFacetFilter extends AbstractDSpaceTransformer implements Cach
}
@Override
public void setup(SourceResolver resolver, Map objectModel, String src, Parameters parameters) throws ProcessingException, SAXException, IOException {
super.setup(resolver, objectModel, src, parameters);
Request request = ObjectModelHelper.getRequest(objectModel);
String facetField = request.getParameter(SearchFilterParam.FACET_FIELD);
if(StringUtils.isBlank(facetField))
{
throw new BadRequestException("Invalid " + SearchFilterParam.FACET_FIELD + " parameter");
}
}
/**
* Generate the unique caching key.
* This key must be unique inside the space of this component.

View File

@@ -0,0 +1,32 @@
/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://www.dspace.org/license/
*/
package org.dspace.app.xmlui.utils;
import java.io.IOException;
/**
* Exception thrown in case of bad request syntax
*
* Example: invalid/missing parameters, ...
*
* @author Kevin Van de Velde (kevin at atmire dot com)
*/
public class BadRequestException extends IOException {
public BadRequestException(String message) {
super(message);
}
public BadRequestException(Throwable t) {
super(t);
}
public BadRequestException(String message, Throwable t) {
super(message, t);
}
}

View File

@@ -176,6 +176,7 @@
<map:selector logger="sitemap.selector.exception" name="exception" src="org.apache.cocoon.selection.ExceptionSelector">
<exception name="not-found" class="org.apache.cocoon.ResourceNotFoundException"/>
<exception name="invalid-continuation" class="org.apache.cocoon.components.flow.InvalidContinuationException"/>
<exception name="bad-request" class="org.dspace.app.xmlui.utils.BadRequestException"/>
<!-- The statement below tells the selector to unroll as much exceptions as possible -->
<exception class="java.lang.Throwable" unroll="true"/>
</map:selector>
@@ -655,6 +656,20 @@
<map:handle-errors>
<map:select type="exception">
<map:when test="bad-request">
<map:generate type="exception"/>
<map:transform src="exception2html.xslt">
<map:parameter name="contextPath" value="{request:contextPath}"/>
<map:parameter name="pageTitle" value="Bad request"/>
</map:transform>
<map:act type="locale">
<map:transform type="i18n">
<map:parameter name="locale" value="{locale}"/>
</map:transform>
</map:act>
<map:serialize type="xhtml" status-code="400"/>
</map:when>
<map:when test="not-found">
<map:generate type="exception"/>
<map:transform src="exception2html.xslt">