Ask a Question

[Resolved] JSON conversion to XML does not work

UPC_Broadband_L
Occasional Contributor

[Resolved] JSON conversion to XML does not work

Hi,

Right now, I'm using a REST api for a Jira plugin, Zephyr (here's the documentation for reference [though not necessary for this issue]: http://docs.getzephyr.apiary.io/).

They all return JSON responses. SoapUI seems to automatically convert these to XML so they can be edited / processed.
However, one of them returns this:

{
"status": {
"1": {
"id": 1,
"color": "#75B000",
"description": "Test was executed and passed successfully.",
"name": "PASSED"
},
"2": {
"id": 2,
"color": "#CC3300",
"description": "Test was executed and failed.",
"name": "FAILED"
},
"3": {
"id": 3,
"color": "#ffff00",
"description": "Test is Not tested in this cycle.",
"name": "NOT TESTED"
},
"4": {
"id": 4,
"color": "#6693B0",
"description": "The test execution of this test was suspended.",
"name": "TEST SUSPENDED"
},
"6": {
"id": 6,
"color": "#ff9900",
"description": "Test is failed, but not a high priority issue",
"name": "ACCEPTED FAILED"
},
"-1": {
"id": -1,
"color": "#bbbbbb",
"description": "The test has not yet been executed.",
"name": "SCHEDULED"
}
},
"issueId": 1234,
"executions": [ {
"id": 1234,
"executionStatus": "-1",
"comment": "",
"htmlComment": "",
"cycleId": 1234,
"cycleName": "Cycle Name 2014-06-05",
"versionId": 1234,
"versionName": "version",
"projectId": 1234,
"issueId": 1234,
"issueKey": "TEST-1234",
"summary": "Summary Sample 1",
"issueDescription": "<p>&lt;p&gt;&lt;span style=\"color: rgb(51, 51, 51); font-family: Arial, sans-serif; font-size: 14px; line-height: 20px;\"&gt;test &amp; test.&lt;/span&gt;&lt;/p&gt;<\/p>",
"label": "TEST, TEST2",
"component": "TEST",
"projectKey": "TEST"
}],
"currentlySelectedExecutionId": "",
"recordsCount": 1
}


Apparently soapUI's automatic JSON to XML conversion fails.
It returns this: <xml/>

Ergo, I can't manipulate it, transfer properties, etc.
Trying to use a groovy script to retrieve only the JSON as a string always returns the "<xml/>" response. Ex:
- def response = context.expand( '${name#Response}' ).toString()
- responseContent = testRunner.testCase.getTestStepByName("name").getPropertyValue("response")

ResponseAsXml does not work in this case, since the XML was not properly converted.
- Note: The error returned is "NCNames cannot start with the character 2d", probably because one of the elements starts with a number and that does not follow XML conventions.

Is there a way to:
1- Fix the response so it's "XML convertible" JSON?
or
2- Fetch the response as JSON only, not wrongly converted XML, so that it can be slurped?
11 REPLIES 11

On my local using  ReadyAPi 2.8.2 UI-Interface i was able to execute the project  successfully. Where we have jenkins machine( on linux) and iam getting issue. when i execute project.

[ERROR] Failed to execute goal com.smartbear:ready-api-maven-plugin:2.8.2:test (1) on project Testing: Execution 1 of goal com.smartbear:ready-api-maven-plugin:2.8.2:test failed: An API incompatibility was encountered while executing com.smartbear:ready-api-maven-plugin:2.8.2:test: java.lang.NoSuchMethodError: org.apache.commons.lang.ArrayUtils.isNotEmpty([Ljava/lang/Object;)Z

[ERROR] -----------------------------------------------------

[ERROR] realm =    plugin>com.smartbear:ready-api-maven-plugin:2.8.2

[ERROR] strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy

[ERROR] urls[0] = file:/var/lib/jenkins/.m2/repository/com/smartbear/ready-api-maven-plugin/2.8.2/ready-api-maven-plugin-2.8.2.jar

[ERROR] urls[1] = file:/var/lib/jenkins/.m2/repository/org/codehaus/groovy/groovy/2.4.4/groovy-2.4.4.jar

[ERROR] urls[2] = file:/var/lib/jenkins/.m2/repository/net/sf/json-lib/json-lib/2.4/json-lib-2.4.jar

[ERROR] urls[3] = file:/var/lib/jenkins/.m2/repository/commons-beanutils/commons-beanutils/1.9.3/commons-beanutils-1.9.3.jar

[ERROR] urls[4] = file:/var/lib/jenkins/.m2/repository/commons-collections/commons-collections/3.2.2/commons-collections-3.2.2.jar

[ERROR] urls[5] = file:/var/lib/jenkins/.m2/repository/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar

[ERROR] urls[6] = file:/var/lib/jenkins/.m2/repository/net/sf/ezmorph/ezmorph/1.0.1/ezmorph-1.0.1.jar

[ERROR] urls[7] = file:/var/lib/jenkins/.m2/repository/net/sourceforge/jexcelapi/jxl/2.6.12/jxl-2.6.12.jar

[ERROR] urls[8] = file:/var/lib/jenkins/.m2/repository/postgresql/postgresql/postgresql-9.3-1104.jdbc41/postgresql-postgresql-9.3-1104.jdbc41.jar

 

[ERROR] urls[194] = file:/var/lib/jenkins/.m2/repository/wsdl4j/wsdl4j/1.6.2-fixed/wsdl4j-1.6.2-fixed.jar

[ERROR] urls[195] = file:/var/lib/jenkins/.m2/repository/commons-ssl/not-yet-commons-ssl/0.3.17/not-yet-commons-ssl-0.3.17.jar

[ERROR] urls[196] = file:/var/lib/jenkins/.m2/repository/commons-cli/commons-cli/1.3.1/commons-cli-1.3.1.jar

[ERROR] urls[197] = file:/var/lib/jenkins/.m2/repository/swingx/swingx/soapui/swingx-soapui.jar

[ERROR] urls[198] = file:/var/lib/jenkins/.m2/repository/commons-codec/commons-codec/1.6/commons-codec-1.6.jar

[ERROR] urls[199] = file:/var/lib/jenkins/.m2/repository/org/mozilla/rhino/1.7.10/rhino-1.7.10.jar

[ERROR] urls[200] = file:/var/lib/jenkins/.m2/repository/xmlunit/xmlunit/1.2/xmlunit-1.2.jar

[ERROR] urls[201] = file:/var/lib/jenkins/.m2/repository/org/bouncycastle/bcprov-jdk15/1.46/bcprov-jdk15-1.46.jar

[ERROR] urls[202] = file:/var/lib/jenkins/.m2/repository/jtidy/jtidy/r872-jdk15/jtidy-r872-jdk15.jar

[ERROR] urls[203] = file:/var/lib/jenkins/.m2/repository/javax/jms/jms/1.1/jms-1.1.jar

[ERROR] urls[204] = file:/var/lib/jenkins/.m2/repository/hermesjms/hermes/1.14/hermes-1.14.jar

[ERROR] urls[205] = file:/var/lib/jenkins/.m2/repository/amf/flex-messaging-common/1.0/flex-messaging-common-1.0.jar

[ERROR] urls[206] = file:/var/lib/jenkins/.m2/repository/amf/flex-messaging-core/1.0/flex-messaging-core-1.0.jar

[ERROR] urls[207] = file:/var/lib/jenkins/.m2/repository/thoughtworks/xstream/1.3.1/xstream-1.3.1.jar

[ERROR] urls[208] = file:/var/lib/jenkins/.m2/repository/net/sourceforge/nekohtml/nekohtml/1.9.14/nekohtml-1.9.14.jar

[ERROR] urls[209] = file:/var/lib/jenkins/.m2/repository/xerces/xercesImpl/2.9.1/xercesImpl-2.9.1.jar

[ERROR] urls[210] = file:/var/lib/jenkins/.m2/repository/xml-apis/xml-apis/1.3.04/xml-apis-1.3.04.jar

[ERROR] urls[211] = file:/var/lib/jenkins/.m2/repository/l2fprod/l2fprod-common-fontchooser/7.3/l2fprod-common-fontchooser-7.3.jar

[ERROR] urls[212] = file:/var/lib/jenkins/.m2/repository/org/apache/ws/commons/util/ws-commons-util/1.0.2/ws-commons-util-1.0.2.jar

[ERROR] urls[213] = file:/var/lib/jenkins/.m2/repository/com/github/markusbernhardt/proxy-vole/1.0.4/proxy-vole-1.0.4.jar

 

 

 

Below is my pom.xml:-

 

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>API_Testing</groupId>
<artifactId>Testing</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>Testing</name>
<url>https://maven.apache.org</url>

<properties>
<readyapi.version>2.8.2</readyapi.version>
<groovy.version>2.4.4</groovy.version>
<postgresql.version>postgresql-9.3-1104.jdbc41</postgresql.version>
<maven.clean.version>3.0.0</maven.clean.version>
<jxl.version>2.6.12</jxl.version>
<jtds.version>1.3.0</jtds.version>
<xmlunit.version>2.2.1</xmlunit.version>
<json.version>20160807</json.version>
<poi.version>3.12</poi.version>
<commonlang.version>2.3</commonlang.version>
<jsonlib.version>2.4</jsonlib.version>
<ezmorph.version>1.0.1</ezmorph.version>

</properties>
<!-- SmartBearPluginRepository plugin is necessary to add -->
<pluginRepositories>
<pluginRepository>
<id>SmartBearPluginRepository</id>
<url></url>
<!-- <url>https://maven.gridpoint.com/nexus/content/groups/public/</url> -->
</pluginRepository>
</pluginRepositories>
<build>
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>${maven.clean.version}</version>
<configuration>
<filesets>
<fileset>
<directory>${logDir}</directory>
<includes>
<include>**/*.log.*</include>
</includes>
</fileset>
</filesets>
</configuration>
</plugin>
<!-- soapui-pro-maven-plugin -->
<plugin>
<groupId>com.smartbear</groupId>
<artifactId>ready-api-maven-plugin</artifactId>
<version>${readyapi.version}</version>
<dependencies>
<!-- Dependency to read external file's -->
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy</artifactId>
<version>${groovy.version}</version>
</dependency>
<!-- Dependancy to Groovy jar to parse json to xml -->
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>${jsonlib.version}</version>
</dependency>

<dependency>
<groupId>net.sf.ezmorph</groupId>
<artifactId>ezmorph</artifactId>
<version>${ezmorph.version}</version>
</dependency>
<!-- Dependency to read excel files -->
<dependency>
<groupId>net.sourceforge.jexcelapi</groupId>
<artifactId>jxl</artifactId>
<version>${jxl.version}</version>
</dependency>

<!-- Dependency to read data from postgres database -->
<dependency>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>${postgresql.version}</version>
</dependency>
<!-- Dependency to read data from sqlserver database -->

<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>${commonlang.version}</version>
</dependency>
<!-- Dependency to convert unicode values -->
<dependency>
<groupId>net.sourceforge.jtds</groupId>
<artifactId>jtds</artifactId>
<version>${jtds.version}</version>
</dependency>
<dependency>
<groupId>org.gridpoint</groupId>
<artifactId>SinglePeriod</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/jars/SinglePeriod_1.0.jar</systemPath>
</dependency>
<dependency>
<groupId>org.xmlunit</groupId>
<artifactId>xmlunit-matchers</artifactId>
<version>${xmlunit.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>${poi.version}</version>
</dependency>

<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>${json.version}</version>
</dependency>


</dependencies>

<executions>
<execution>
<id>1</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<!-- Project path -->
<projectFile>${projectFile}</projectFile>
<!-- Reports Output folder -->
<outputFolder>MobileProjectReports</outputFolder>
<junitReport>true</junitReport>
<printReport>true</printReport>
<exportAll>false</exportAll>
<testFailIgnore>true</testFailIgnore>
<readyApiProperties>
<property>
<name>soapui.home</name>
<value>${soapuiHome}</value>
</property>
<property>
<name>test.history.disabled</name>
<value>true</value>
</property>
<property>
<name>soapui.scripting.library</name>
<value>${project.basedir}/src/main/java/GlobalScripts</value>
</property>
<property>
<name>soapui.ext.libraries</name>
<value>${project.basedir}/src/main/java/GlobalScripts</value>
</property>
</readyApiProperties>
<!--soapuiProperties> <property> <name>soapui.scripting.library</name>
<value>${project.basedir}\src\main\java\GlobalScripts</value> </property>
<property> <name>soapui.ext.libraries</name> <value>${project.basedir}\src\main\java\GlobalScripts</value>
</property> </soapuiProperties -->
</configuration>
</execution>

</executions>
</plugin>
</plugins>
</build>
</project>

 

 

Note:- I tried to open support ticket filling the form more than 4 times. Looks like they have some issue. Its keep throughing error.

AlexKaras
Champion Level 3

Hi,

 

My knowledge of Java/Groovy architecture is very limited, but based on

> java.lang.NoSuchMethodError: org.apache.commons.lang.ArrayUtils.isNotEmpty()

it is my understanding that corresponding class/method was not found.

According to https://www.google.com/search?q=groovy+jar+for+org.apache.commons.lang.ArrayUtils, ArrayUtils class must be in, for example, commons-lang-X.X.jar (https://repo1.maven.org/maven2/commons-lang/commons-lang/2.6/commons-lang-2.6.jar)

Neither your .pom nor the posted error log mention commons-lang*.jar, so I think that you should add it as a dependency. (Not sure where and how though.)

 

Regards,
  /Alex [Community Champion]
____
[Community Champions] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Champions]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Champion] signature is assigned on quarterly basis and is used with permission by SmartBear Software.
https://community.smartbear.com/t5/Community-Champions/About-the-Community-Champions-Program/gpm-p/252662
================================
cancel
Showing results for 
Search instead for 
Did you mean: