Grails RestBuilder投了一个错误

时间:2014-05-23 16:23:42

标签: rest grails

我正在使用Grails RestBuilder插件,但是当我尝试使用xml发送一个post请求时,会抛出异常:

Cannot cast object '<BookingRetrievalRQ xmlns="http://www.expediaconnect.com/EQC/BR/2014/01"><Authentication username="testuser" password="ECLPASS"/></BookingRetrievalRQ>' 
with class 'java.lang.String' to class 'grails.converters.XML'

但我不明白为什么会这样。

这是我在服务类中的代码请求:

def resource = XmlUtil.marshal(msg)
    def rest = new RestBuilder()
    def resp = rest.post('https://simulator.expediaquickconnect.com/connect/br') {
        contentType "application/xml"
        xml resource
    }
    return XmlUtil.unMarshal(resp.xml, BookingRetrievalRS.class)

[XmlUtil.class]

static String marshal(def source) {
        StringWriter writer = new StringWriter()
        JAXBContext context = JAXBContext.newInstance(source.class)
        Marshaller marshaller = context.createMarshaller()
        marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE)
        marshaller.marshal(source, writer)
        return writer.toString()
    }   


    static def unMarshal(String strXml, Class targetClass){
        JAXBContext context = JAXBContext.newInstance(targetClass)
        def unMarshaller = context.createUnmarshaller()
        return unMarshaller.unmarshal(new StringReader(strXml))
    }

当我尝试这个时:

def rest = new RestBuilder()
def resp = rest.post("https://simulator.expediaquickconnect.com/connect/br") {
        accept 'application/xml'
        contentType 'application/xml'
                    xml {
                        BookingRetrievalRQ(xmlns: "http://www.expediaconnect.com/EQC/BR/2014/01") {
                            Authentication(username: "testuser", password: "ECLPASS")
                        }
                    }
            }

我有以下错误消息:

unable to find valid certification path to requested target

1 个答案:

答案 0 :(得分:1)

免责声明:这是从问题中提取的。

我通过使用本教程在开发模式下注册bean来解决问题:java https problem