Skip to content

Commit

Permalink
Make request nullable because in the unit/integration tests it might …
Browse files Browse the repository at this point in the history
…not be available
  • Loading branch information
royteeuwen committed Oct 13, 2017
1 parent ce9748e commit d9b165d
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/
package com.cognifide.slice.mapper.impl.processor;

import com.cognifide.slice.api.qualifier.Nullable;
import com.cognifide.slice.mapper.annotation.RequestAttribute;
import com.cognifide.slice.mapper.api.processor.FieldProcessor;
import com.google.inject.Inject;
Expand All @@ -32,6 +33,7 @@
public class RequestAttributeProcessor implements FieldProcessor {

@Inject
@Nullable
private ServletRequest servletRequest;

@Override
Expand All @@ -41,8 +43,11 @@ public boolean accepts(final Resource resource, final Field field) {

@Override
public Object mapResourceToField(Resource resource, ValueMap valueMap, Field field, String propertyName) {
String attributeName = getAttributeName(field);
return servletRequest.getAttribute(attributeName);
if (servletRequest != null) {
String attributeName = getAttributeName(field);
return servletRequest.getAttribute(attributeName);
}
return null;
}

private String getAttributeName(Field field) {
Expand Down

0 comments on commit d9b165d

Please sign in to comment.