HttpResponseException消息null由未找到引起

时间:2016-01-17 22:56:45

标签: json groovy

这是我的控制器

package course_management_collection

import groovyx.net.http.HTTPBuilder

class CourseController {

    def equellaService
    def search() {
        if (params.courseCodeQuery) {
            def clientId = '2191fc19-2084-46f0-ab8e-aef7a912ff54'
            def clientSecret = '24f83161-09df-47a2-aa70-7929d96cd4a9'        
            def http = new HTTPBuilder('https://eqtst.uow.edu.au/uow/')        
            def accessToken = equellaService.getAccessToken(http, clientId, clientSecret)

            def itemInfo = equellaService.getItemInfo(http, accessToken, params.courseCodeQuery, "81895979-822f-41b6-9a61-4629216f727d" )
            // def itemInfo = equellaService.getItemInfo(http, accessToken, "a05bc842-8226-4773-a64a-f92d20bd9834", 1)
            // def course= equellaService.getCourse(http, accessToken, "81895979-822f-41b6-9a61-4629216f727d")
            return [courseCodeQuery: params.courseCodeQuery, itemInfo: itemInfo]
            // return [courseCodeQuery: params.courseCodeQuery, course: course]
        }
    }
}

我编辑了EquellaService.groovy如下:

    package course_management_collection

    import grails.transaction.Transactional
    import static groovyx.net.http.Method.GET
    import static groovyx.net.http.ContentType.JSON

    @Transactional
    class EquellaService {

        def getAccessToken(http, clientId, clientSecret) {
        def accessToken
        http.request(GET, JSON) {
                uri.path = 'oauth/access_token'
                uri.query = [grant_type: 'client_credentials', client_id: clientId, client_secret: clientSecret, redirect_uri: 'default']

                response.success = { resp, json ->
                    accessToken = json.access_token
                }
        }

        return accessToken
  }


def getItemInfo(http, accessToken, params.courseCodeQuery, collection) {
    def itemInfo

    http.request(GET, JSON) {
    uri.path = "api/search/${params.courseCodeQuery}/${collection}"
      uri.query = [info: 'all']
        headers.'X-Authorization' = "access_token=${accessToken}"

        response.success = { resp, json ->
        itemInfo = json
      }
      }

    return itemInfo

    }
}

回应:

URI
/
Class
groovyx.net.http.HttpResponseException
Message
null
Caused by
Not Found
Around line 30 of grails-app\services\course_management_collection\EquellaService.groovy
27:def getItemInfo(http, accessToken, params.courseCodeQuery, collection) {
28:def itemInfo
29:
30:http.request(GET, JSON) {
31:uri.path = "api/search/${params.courseCodeQuery}/${collection}"
32:  uri.query = [info: 'all']
33:    headers.'X-Authorization' = "access_token=${accessToken}"
Around line 18 of grails-app\controllers\course_management_collection\CourseController.groovy
15:            def http = new HTTPBuilder('https://eqtst.uow.edu.au/uow/')        
16:            def accessToken = equellaService.getAccessToken(http, clientId, clientSecret)
17:           
18:            def itemInfo = equellaService.getItemInfo(http, accessToken, params.courseCodeQuery, "81895979-822f-41b6-9a61-4629216f727d" )
19:           // def itemInfo = equellaService.getItemInfo(http, accessToken, "a05bc842-8226-4773-a64a-f92d20bd9834", 1)
20:           //def course= equellaService.getCourse(http, accessToken, "81895979-822f-41b6-9a61-4629216f727d")
21:            return [courseCodeQuery: params.courseCodeQuery, itemInfo: itemInfo]
Trace
    Line | Method
->> 1110 | runWorker in java.util.concurrent.ThreadPoolExecutor
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|    603 | run       in java.util.concurrent.ThreadPoolExecutor$Worker
^    722 | run . . . in java.lang.Thread

Caused by HttpResponseException: Not Found

2 个答案:

答案 0 :(得分:2)

你的行

def itemInfo = equellaService.getItemInfo(http, accessToken, courseCodeQuery, "81895979-822f-41b6-9a61-4629216f727d" )

应该是

def itemInfo = equellaService.getItemInfo(http, accessToken, params.courseCodeQuery, "81895979-822f-41b6-9a61-4629216f727d" )

请注意params.

答案 1 :(得分:0)

因为你没有名为'courseCodeQuery'的变量,你有'params.courseCodeQuery'吗?