0

Nexmo プラグインを統合する Grails でエラーが発生します。エラーが発生したファイルは、次のように「NexmoService.groovy」です。

package grails.plugin.nexmo

import groovyx.net.http.HTTPBuilder
import org.springframework.context.i18n.LocaleContextHolder as LCH

import static groovyx.net.http.ContentType.URLENC
import static groovyx.net.http.Method.POST

class NexmoService {

    def grailsApplication
    def messageSource

    def sendSms(String to, String text, String from=config?.sms?.default_from) throws NexmoException {
        if (!to || !text || !from) {
            throw new NexmoException(getMessage("nexmo.sms.error.missing.param"))
        }

        def http = new HTTPBuilder(config?.endpoint)  
        def requestBody = [to: to, text: text, from: from, api_key: config?.api?.key, api_secret: config?.api?.secret]

        http.request(POST) {
            uri.path = "/sms/${config?.format}"
            send(URLENC, requestBody)

            response.success = { resp, data ->
                def message = data?.messages[0]
                def statusCode = message?.status
                if (statusCode != "0") {
                    def error = getMessage("nexmo.sms.status.${statusCode}", [message?."error-text"], getMessage("nexmo.sms.error.default"))
                    throw new NexmoException(error)
                }
                log.info(getMessage("nexmo.sms.success"))
                return [status: message?.status, id: message?."message-id"]
            }
            response.failure = { resp, data ->
                def error = getMessage("nexmo.sms.error.response", [resp?.status], getMessage("nexmo.sms.error.default"))
                throw new NexmoException(error)
            }
        }
    }

    def call(String to, String text, String from="") throws NexmoException {
        if (!to || !text) {
            throw new NexmoException(getMessage("nexmo.call.error.missing.param"))
        }

        def http = new HTTPBuilder(config?.endpoint)
        def requestBody = [to: to, text: text, from: from, api_key: config?.api?.key, api_secret: config?.api?.secret]

        http.request(POST) {
            uri.path = "/tts/${config?.format}"
            send(URLENC, requestBody)

            response.success = { resp, data ->
                def statusCode = data?.status
                if (statusCode != "0") {
                    def error = getMessage("nexmo.call.status.${statusCode}", [data?."error-text"], getMessage("nexmo.call.error.default"))
                    throw new NexmoException(error)
                }
                log.info(getMessage("nexmo.call.success"))
                return [status: data?.status, id: data?."call-id"]
            }
            response.failure = { resp, data ->
                def error = getMessage("nexmo.call.error.response", [resp?.status], getMessage("nexmo.call.error.default"))
                throw new NexmoException(error)
            }
        }
    }

    private ConfigObject getConfig() {
        return grailsApplication.config?.nexmo
    }

    private String getMessage(String code, List args=[], String defaultMessage="") {
        if (messageSource.resolveCode(code, LCH.locale)) {
            return messageSource.getMessage(code, args.toArray(), LCH.locale)
        }
        return defaultMessage
    }
}

エラーは以下のとおりです。

| | エラー コンパイル エラー: 起動に失敗しました: C:\nexmo-master\grails-app\services\grails\plugin\nexmo\NexmoService.groovy: 3: クラス groovyx.net.http.HTTPBuilder @ 行 3、列 1 を解決できません。 groovyx.net.http.HTTPBuilder をインポートします ^

C:\nexmo-master\grails-app\services\grails\plugin\nexmo\NexmoService.groovy: 6: クラス groovyx.net.http.ContentType を解決できません @ 行 6、列 1. import static groovyx.net.http .ContentType.URLENC ^

C:\nexmo-master\grails-app\services\grails\plugin\nexmo\NexmoService.groovy: 7: クラス groovyx.net.http.Method を解決できません @ 行 7、列 1. import static groovyx.net.http .メソッド.POST ^

3 エラー

4

1 に答える 1

1

クラスパスに http-builder ライブラリがありません。このライブラリをインポートする手順については、この投稿を参照してください。groovyx.net.httpまたはhttp://www.groovy-lang.org/mailing-lists.html#nabble-td3995735をインポートする方法

于 2015-10-23T22:29:51.730 に答える