2016-03-02 3 views
0

Im новичок в заводной и пытается разобрать XML и вставить результирующих записей в базе данных MySQL Образец ответа SOAP XMLSoapUI Groovy разбора ответ XML и вставить его в базу данных MySQL

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
     <soap:Body> 
      <GetCitiesByCountryResponse xmlns="http://www.webserviceX.NET"> 
      <GetCitiesByCountryResult><NewDataSet> 
     <Table> 
     <Country>British Indian Ocean Territory</Country> 
     <City>Diego Garcia</City> 
     </Table> 
     <Table> 
     <Country>India</Country> 
     <City>Ahmadabad</City> 
     </Table> 
     <Table> 
     <Country>India</Country> 
     <City>Akola</City> 
     </Table> 
    </NewDataSet></GetCitiesByCountryResult> 
      </GetCitiesByCountryResponse> 
     </soap:Body> 
    </soap:Envelope> 

SoapUI GROOVY teststep сценарий

import groovy.sql.Sql 
def sql = Sql.newInstance('jdbc:mysql://localhost:3306/weather', 'root', 'security', 'com.mysql.jdbc.Driver') 
def response = context.expand('${GetCitiesByCountry#Response}') 
def xml = new XmlSlurper().parseText(response).Body.GetCitiesByCountryResponse.GetCitiesByCountryResult.NewDataSet.Table 
//log.info xml 
xml.each{ node -> 
    sql.execute("INSERT INTO indcit(country,city) VALUES (?,?)" ,[node.Country, node.City]) 
    //sql.execute("INSERT INTO indcit(country,city) VALUES (${node.Country},${node.City})") 
    //log.info node.Country 
    //log.info node.City 
    } 

Когда пытался как sql.execute линии бросает ту же ниже ошибку java.sql.SQLException: Недействительное значение аргумента: java.io.NOTSerializableException

Журнал ошибок

Thu Mar 03 01:16:36 IST 2016:ERROR:java.sql.SQLException: Invalid argument value: java.io.NotSerializableException 
    java.sql.SQLException: Invalid argument value: java.io.NotSerializableException 
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:910) 
    at com.mysql.jdbc.PreparedStatement.setSerializableObject(PreparedStatement.java:3415) 
    at com.mysql.jdbc.PreparedStatement.setObject(PreparedStatement.java:3066) 
    at groovy.sql.Sql.setObject(Sql.java:3655) 
    at groovy.sql.Sql.setParameters(Sql.java:3620) 
    at groovy.sql.Sql.getPreparedStatement(Sql.java:3881) 
    at groovy.sql.Sql.getPreparedStatement(Sql.java:3928) 
    at groovy.sql.Sql.execute(Sql.java:2287) 
    at groovy.sql.Sql$execute.call(Unknown Source) 
    at Script62$_run_closure1.doCall(Script62.groovy:7) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 
    at java.lang.reflect.Method.invoke(Unknown Source) 
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90) 
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233) 
    at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:272) 
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:909) 
    at groovy.lang.Closure.call(Closure.java:411) 
    at groovy.lang.Closure.call(Closure.java:427) 
    at org.codehaus.groovy.runtime.DefaultGroovyMethods.each(DefaultGroovyMethods.java:1325) 
    at org.codehaus.groovy.runtime.DefaultGroovyMethods.each(DefaultGroovyMethods.java:1297) 
    at org.codehaus.groovy.runtime.dgm$148.doMethodInvoke(Unknown Source) 
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1085) 
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:909) 
    at groovy.lang.DelegatingMetaClass.invokeMethod(DelegatingMetaClass.java:149) 
    at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:39) 
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45) 
    at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:54) 
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116) 
    at Script62.run(Script62.groovy:6) 
    at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.run(SoapUIGroovyScriptEngine.java:92) 
    at com.eviware.soapui.impl.wsdl.teststeps.WsdlGroovyScriptTestStep.run(WsdlGroovyScriptTestStep.java:141) 
    at com.eviware.soapui.impl.wsdl.panels.teststeps.GroovyScriptStepDesktopPanel$RunAction$1.run(GroovyScriptStepDesktopPanel.java:250) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) 
    at java.lang.Thread.run(Unknown Source) 

Спасибо за любую помощь заранее!

+0

Вы сначала зарегистрировать JDBC? https://www.soapui.org/scripting-properties/tips-tricks.html#10-Use-a-JDBC-Driver-from-inside-a-groovy-script – SiKing

+0

Спасибо за выделение –

ответ

1

Try вызова text() на своих узлах, то есть:

sql.execute("INSERT INTO indcit(country,city) VALUES (?,?)" ,[node.Country.text(), node.City.text()]) 
+0

Спасибо тонне ... Он отлично работал –