Re: [rest-assured] Parsing XML that references a DTD that doesn't exist

187 views
Skip to first unread message

Johan Haleby

unread,
May 14, 2013, 9:36:05 AM5/14/13
to rest-a...@googlegroups.com
Hi, 

I don't think there's support for this. Could you please add it as an issue at the issue track at google code and I'll see what I can do. 

Regards,
/Johan


On Tue, May 14, 2013 at 3:21 PM, Casey Dunham <casey....@gmail.com> wrote:
I'm using version 1.7.2 of RestAssured and I am attempting to write a few integration tests for a legacy service. I've run into a problem and was wondering if there is already a mechanism in RestAssured to work around this.

The service I am testing returns XML with a DTD declared that doesn't exist. For example

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE LegacyService SYSTEM "http://example.com/dtd/NonExistent.dtd">
<LegacyService>
    ...
</LegacyService>

The DTD referenced above is not retrievable, which results in the below stack trace. I'm not too familiar with Groovy at the moment, but according to this http://groovy.329449.n5.nabble.com/XmlParser-XmlSlurper-howto-disable-DTD-validation-td353673.html
being able to set the features on the XmlSlurper should be able to solve this.

Is there a configuration option I'm missing that would allow features to be set on the XmlSlurper or a way I can get at the actual XmlSlurper implementation to set them myself? 

Thanks!

com.jayway.restassured.exception.ParsePathException: Failed to parse the XML document
at com.jayway.restassured.path.xml.XmlPath$ExceptionCatcher.invoke(XmlPath.java:767)
at com.jayway.restassured.path.xml.XmlPath.parseInputStream(XmlPath.java:713)
at com.jayway.restassured.path.xml.XmlPath.<init>(XmlPath.java:195)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:77)
at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrapNoCoerce.callConstructor(ConstructorSite.java:102)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:54)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:182)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:194)
at com.jayway.restassured.internal.RestAssuredResponseImpl.newXmlPath(RestAssuredResponseImpl.groovy:422)
at com.jayway.restassured.internal.RestAssuredResponseImpl.this$2$newXmlPath(RestAssuredResponseImpl.groovy)
at com.jayway.restassured.internal.RestAssuredResponseImpl$this$2$newXmlPath.callCurrent(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:46)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:133)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:141)
at com.jayway.restassured.internal.RestAssuredResponseImpl.xmlPath(RestAssuredResponseImpl.groovy:316)
at bt.listener.it.BaseIT.validateApprovedResponse(BaseIT.java:50)
at bt.listener.it.BaseIT.testSale(BaseIT.java:64)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:77)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:195)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:63)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: java.io.FileNotFoundException: http://example.com/dtd/NonExistent.dtd
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1434)
at java.net.URL.openStream(URL.java:1010)
at org.apache.xerces.impl.XMLEntityManager.setupCurrentEntity(Unknown Source)
at org.apache.xerces.impl.XMLEntityManager.startEntity(Unknown Source)
at org.apache.xerces.impl.XMLEntityManager.startDTDEntity(Unknown Source)
at org.apache.xerces.impl.XMLDTDScannerImpl.setInputSource(Unknown Source)
at org.apache.xerces.impl.XMLDocumentScannerImpl$DTDDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at groovy.util.XmlSlurper.parse(XmlSlurper.java:146)
at groovy.util.XmlSlurper.parse(XmlSlurper.java:183)
at com.jayway.restassured.path.xml.XmlPath$3.method(XmlPath.java:715)
at com.jayway.restassured.path.xml.XmlPath$ExceptionCatcher.invoke(XmlPath.java:765)
... 47 more

--
You received this message because you are subscribed to the Google Groups "REST assured" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rest-assured...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Casey Dunham

unread,
May 14, 2013, 11:04:43 AM5/14/13
to rest-a...@googlegroups.com
Hi Johan,

I've created Issue 237 (https://code.google.com/p/rest-assured/issues/detail?id=237) which also includes a simple test project which reproduces this using rest assured 1.8.0.

I may take a shot at this tonight but I'm not currently sure of the best way to approach this issue. The XmlSlurper setFeature method is documented as being

public void setFeature(java.lang.String uri, boolean value)

It would probably be useful and reduce issues later if we could pass a feature collection (e.g. Map<String, boolean>) at some point in the creation of the Request / Response and just set the features on the XmlSlurper when it is created. 

Johan Haleby

unread,
May 15, 2013, 2:23:10 AM5/15/13
to rest-a...@googlegroups.com
Thanks Casey, I'll try to fix it when I find some time.
Reply all
Reply to author
Forward
0 new messages