Skip to content

Instantly share code, notes, and snippets.

@justinhrobbins
Created September 1, 2012 20:43
@Override
public Response handleResponse(Message m, OperationResourceInfo ori,
Response response) {
// exit now if not an http GET method
if (!ori.getHttpMethod().equals("GET"))
return null;
// exit now if not a 200 response, no sense in apply filtering if not a
// '200 OK'
if (response.getStatus() != 200)
return null;
// exit now if we are not returning json
if (!ori.getProduceTypes().get(0).toString()
.equals(MediaType.APPLICATION_JSON))
return null;
// get a reference to the response entity. the entity holds the payload
// of our response
Object entity = response.getEntity();
// try to get the 'fields' parameter from the QueryString
String fields = uriInfo.getQueryParameters().getFirst("fields");
// if the 'fields' QueryString is blank, then check to see if we have
// @DefaultValue for 'fields'
if (StringUtils.isBlank(fields)) {
// get the Parameters for this Resource
List<Parameter> parameters = ori.getParameters();
for (Parameter parm : parameters) {
// is the current Parameter named 'fields'?
if (parm.getName().equals("fields")) {
// get the default value for 'fields'
fields = parm.getDefaultValue();
// now that we found 'fields', there's no need to keep
// looping
break;
}
}
// If 'fields' is still blank then we don't have a value from either
// the QueryString or @DefaultValue
if (StringUtils.isBlank(fields)) {
logger.debug("Did not find 'fields' pararm for Resource '"
+ uriInfo.getPath() + "'");
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment