我自己已经解决了这个问题,我只从过滤器中删除了名称空间,所以过滤器看起来像这样:
package filter.api
import grails.converters.JSON
class ApiFilters {
def apiService
def filters = {
apiSafetyCheck(controller: "customer|status", action: "*") {
before = {
if(!apiService?.checkIncludedApiKey(params)) { //Simply returns true if the apiKey was found in the database!
def returnMap = [
"error": "API key was not found",
"statusCode": 401 //Just for testing!
]
if(params.outputFormat && params.outputFormat ?.equals("xml")) {
def textToRender = apiService?.createXmlFromMapInstance(returnMap)
owner?.render(status: 401, contentType: "text/xml", text: textToRender)
} else owner?.render(status: 401, contentType: "application/json", text: (returnMap as JSON))
return false //We don't want the action to be processed!
}
}
}
}
就是这样,它对我有效:-)