ClassCastException in 2.1.x version when using WireMock.equalToXml()

562 views
Skip to first unread message

Vipin Jose

unread,
Jul 29, 2016, 4:50:42 PM7/29/16
to wiremock-user
Hello,

I am using 2.1.4-rc3. 
I am getting the following issue with 2.1.9, also, but not with 1.58.

I am getting a ClassCastException from WireMock when i use WireMock.equalToXml().


Following is the code snippet:

...
        requestString = "<RequestRoot><Item Quantity=\"1\"/></RequestRoot>";
        responseString = "<ResponseRoot><Item Ack=\"OK\"/></ResponseRoot>";
        wiremock.register(
                post(urlEqualTo("/update")).withRequestBody(equalToXml(requestString))
                        .willReturn(aResponse().withStatus(HttpStatus.OK.value())
                                .withBody(responseString)));
...


After running this code i test it through PostMan

Body: <RequestRoot><Item Quantity="1"/></RequestRoot>

Response:
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1"/>
        <title>Error 500 </title>
    </head>
    <body>
        <h2>HTTP ERROR: 500</h2>
        <p>Problem accessing /update. Reason:

            <pre>    java.lang.ClassCastException: net.sf.saxon.value.ObjectValue cannot be cast to net.sf.saxon.om.NodeInfo</pre>
        </p>
        <hr />
        <i>
            <small>Powered by Jetty://</small>
        </i>
    </body>
</html>


If i remove the equalToXml() method then the issue does not show up.

Regards,
Vipin

PS: I ran it through java code also and following is the stack trace:

java.lang.ClassCastException: net.sf.saxon.value.ObjectValue cannot be cast to net.sf.saxon.om.NodeInfo
at net.sf.saxon.s9api.DocumentBuilder.wrap(DocumentBuilder.java:511) ~[Saxon-HE-9.6.0-5.jar:na]
at net.sf.saxon.s9api.XsltTransformer.setSource(XsltTransformer.java:209) ~[Saxon-HE-9.6.0-5.jar:na]
at net.sf.saxon.jaxp.TransformerImpl.transform(TransformerImpl.java:90) ~[Saxon-HE-9.6.0-5.jar:na]
at org.xmlunit.transform.Transformation.transformTo(Transformation.java:186) ~[xmlunit-core-2.1.1.jar:2.1.1]
at org.xmlunit.transform.Transformation.transformToDocument(Transformation.java:220) ~[xmlunit-core-2.1.1.jar:2.1.1]
at org.xmlunit.input.CommentLessSource.<init>(CommentLessSource.java:42) ~[xmlunit-core-2.1.1.jar:2.1.1]
at org.xmlunit.builder.DiffBuilder.wrap(DiffBuilder.java:358) ~[xmlunit-core-2.1.1.jar:2.1.1]
at org.xmlunit.builder.DiffBuilder.build(DiffBuilder.java:341) ~[xmlunit-core-2.1.1.jar:2.1.1]
at com.github.tomakehurst.wiremock.matching.EqualToXmlPattern$1.getDistance(EqualToXmlPattern.java:121) ~[wiremock-2.1.9.jar:na]
at com.github.tomakehurst.wiremock.matching.MatchResult$1.getDistance(MatchResult.java:59) ~[wiremock-2.1.9.jar:na]
at com.github.tomakehurst.wiremock.matching.MatchResult$1.getDistance(MatchResult.java:59) ~[wiremock-2.1.9.jar:na]
at com.github.tomakehurst.wiremock.matching.MatchResult.compareTo(MatchResult.java:77) ~[wiremock-2.1.9.jar:na]
at com.github.tomakehurst.wiremock.verification.NearMiss.compareTo(NearMiss.java:75) ~[wiremock-2.1.9.jar:na]
at com.github.tomakehurst.wiremock.verification.NearMissCalculator$1.compare(NearMissCalculator.java:38) ~[wiremock-2.1.9.jar:na]
at com.github.tomakehurst.wiremock.verification.NearMissCalculator$1.compare(NearMissCalculator.java:36) ~[wiremock-2.1.9.jar:na]
at com.google.common.collect.ComparatorOrdering.compare(ComparatorOrdering.java:38) ~[guava-18.0.jar:na]
at java.util.TimSort.countRunAndMakeAscending(TimSort.java:351) ~[na:1.8.0_45]
at java.util.TimSort.sort(TimSort.java:216) ~[na:1.8.0_45]
at java.util.Arrays.sort(Arrays.java:1438) ~[na:1.8.0_45]
at com.google.common.collect.Ordering.immutableSortedCopy(Ordering.java:846) ~[guava-18.0.jar:na]
at com.google.common.collect.FluentIterable.toSortedList(FluentIterable.java:386) ~[guava-18.0.jar:na]
at com.github.tomakehurst.wiremock.verification.NearMissCalculator.sortAndTruncate(NearMissCalculator.java:72) ~[wiremock-2.1.9.jar:na]
at com.github.tomakehurst.wiremock.verification.NearMissCalculator.findNearestTo(NearMissCalculator.java:53) ~[wiremock-2.1.9.jar:na]
at com.github.tomakehurst.wiremock.core.WireMockApp.logUnmatchedRequest(WireMockApp.java:119) ~[wiremock-2.1.9.jar:na]
at com.github.tomakehurst.wiremock.core.WireMockApp.serveStubFor(WireMockApp.java:112) ~[wiremock-2.1.9.jar:na]
at com.github.tomakehurst.wiremock.http.StubRequestHandler.handleRequest(StubRequestHandler.java:32) ~[wiremock-2.1.9.jar:na]
at com.github.tomakehurst.wiremock.http.AbstractRequestHandler.handle(AbstractRequestHandler.java:41) ~[wiremock-2.1.9.jar:na]
at com.github.tomakehurst.wiremock.servlet.WireMockHandlerDispatchingServlet.service(WireMockHandlerDispatchingServlet.java:99) ~[wiremock-2.1.9.jar:na]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729) ~[tomcat-embed-core-8.0.30.jar:8.0.30]
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:812) ~[jetty-servlet-9.2.14.v20151106.jar:9.2.14.v20151106]
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1669) ~[jetty-servlet-9.2.14.v20151106.jar:9.2.14.v20151106]
at org.eclipse.jetty.servlets.UserAgentFilter.doFilter(UserAgentFilter.java:83) ~[jetty-servlets-9.2.14.v20151106.jar:9.2.14.v20151106]
at org.eclipse.jetty.servlets.GzipFilter.doFilter(GzipFilter.java:300) ~[jetty-servlets-9.2.14.v20151106.jar:9.2.14.v20151106]
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652) ~[jetty-servlet-9.2.14.v20151106.jar:9.2.14.v20151106]
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:585) [jetty-servlet-9.2.14.v20151106.jar:9.2.14.v20151106]
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1127) [jetty-server-9.2.14.v20151106.jar:9.2.14.v20151106]
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515) [jetty-servlet-9.2.14.v20151106.jar:9.2.14.v20151106]
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1061) [jetty-server-9.2.14.v20151106.jar:9.2.14.v20151106]
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141) [jetty-server-9.2.14.v20151106.jar:9.2.14.v20151106]
at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:110) [jetty-server-9.2.14.v20151106.jar:9.2.14.v20151106]
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97) [jetty-server-9.2.14.v20151106.jar:9.2.14.v20151106]
at org.eclipse.jetty.server.Server.handle(Server.java:499) [jetty-server-9.2.14.v20151106.jar:9.2.14.v20151106]
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:311) [jetty-server-9.2.14.v20151106.jar:9.2.14.v20151106]
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:257) [jetty-server-9.2.14.v20151106.jar:9.2.14.v20151106]
at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:544) [jetty-io-9.2.14.v20151106.jar:9.2.14.v20151106]
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635) [jetty-util-9.2.14.v20151106.jar:9.2.14.v20151106]
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555) [jetty-util-9.2.14.v20151106.jar:9.2.14.v20151106]
at java.lang.Thread.run(Thread.java:745) [na:1.8.0_45]

Tom Akehurst

unread,
Jul 30, 2016, 5:11:42 AM7/30/16
to wiremock-user
What else have you got on your classpath? My suspicion is that another dependency is pulling in an incompatible version of saxon.
Message has been deleted

Sankar Kishore

unread,
Aug 2, 2016, 6:51:31 AM8/2/16
to wiremock-user
Hi Tom,

I got into similar issues with wiremock:

Below are the dependencies I have added in my pom file:

<dependencies>
  <dependency>
<groupId>com.adobe.store.qa.webservice</groupId>
<artifactId>common-ws</artifactId>
<version>0.0.2-SNAPSHOT</version>
</dependency>
<dependency>
   <groupId>com.github.tomakehurst</groupId>
   <artifactId>wiremock</artifactId>
   <version>2.1.4-rc3</version>
</dependency>
<dependency>
  <groupId>javax</groupId>
  <artifactId>javaee-api</artifactId>
  <version>7.0</version>
</dependency>
<dependency>
  <groupId>javax.servlet</groupId>
  <artifactId>servlet-api</artifactId>
  <version>2.5</version>
</dependency>
<dependency>
   <groupId>com.google.guava</groupId>
   <artifactId>guava</artifactId>
   <version>18.0</version>
</dependency>
<!-- <dependency>
   <groupId>com.github.tomakehurst</groupId>
   <artifactId>wiremock-standalone</artifactId>
   <version>2.1.4-rc3</version>
</dependency> -->
<!-- cxf -->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-rs-client</artifactId>
<version>3.1.1</version>
</dependency>

The whole console Log:

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/C:/Users/sankarv/.m2/repository/org/slf4j/slf4j-jdk14/1.7.7/slf4j-jdk14-1.7.7.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Users/sankarv/.m2/repository/org/slf4j/slf4j-log4j12/1.6.1/slf4j-log4j12-1.6.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Actual binding is of type [org.slf4j.impl.JDK14LoggerFactory]
2016-08-02 16:19:35.823 Verbose logging enabled
Aug 02, 2016 4:19:36 PM org.eclipse.jetty.util.log.Log initialized
INFO: Logging initialized @1586ms
[TestNG] Running:
  C:\Users\sankarv\AppData\Local\Temp\testng-eclipse--736004901\testng-customsuite.xml

Aug 02, 2016 4:19:36 PM org.eclipse.jetty.server.Server doStart
INFO: jetty-9.2.13.v20150730
Aug 02, 2016 4:19:36 PM org.eclipse.jetty.server.handler.ContextHandler doStart
INFO: Started o.e.j.s.ServletContextHandler@54bff557{/__admin,null,AVAILABLE}
Aug 02, 2016 4:19:36 PM org.eclipse.jetty.server.handler.ContextHandler doStart
INFO: Started o.e.j.s.ServletContextHandler@6404f418{/,null,AVAILABLE}
Aug 02, 2016 4:19:36 PM org.eclipse.jetty.server.AbstractConnector doStart
INFO: Started ServerConnector@1b11171f{HTTP/1.1}{0.0.0.0:8089}
Aug 02, 2016 4:19:36 PM org.eclipse.jetty.server.AbstractConnector doStart
INFO: Started ServerConnector@78fa769e{SSL-http/1.1}{0.0.0.0:8443}
Aug 02, 2016 4:19:36 PM org.eclipse.jetty.server.Server doStart
INFO: Started @2026ms
Aug 02, 2016 4:19:37 PM org.eclipse.jetty.server.handler.ContextHandler$Context log
INFO: RequestHandlerClass from context returned com.github.tomakehurst.wiremock.http.AdminRequestHandler. Normalized mapped under returned 'null'
2016-08-02 16:19:37.586 Received request to /mappings/new with body {
  "request" : {
    "url" : "/my/resource",
    "method" : "GET"
  },
  "response" : {
    "status" : 200,
    "body" : "Hello world!",
    "headers" : {
      "Content-Type" : "text/plain"
    }
  }
}
16:19:37,721  INFO webservice.common.HttpServiceConnImpl:46 - ==>get() :: url- http://localhost:8089/my/resource
16:19:37,724  INFO webservice.common.HttpServiceConnImpl:47 - ==>get() :: headers- {Accept=text/xml}
16:19:37,727  INFO webservice.common.HttpServiceConnImpl:294 - ==>getParams() :: http://localhost:8089/my/resource
16:19:37,739  INFO webservice.common.HttpServiceConnImpl:318 - <==getParams()
Aug 02, 2016 4:19:37 PM org.eclipse.jetty.server.handler.ContextHandler$Context log
INFO: RequestHandlerClass from context returned com.github.tomakehurst.wiremock.http.StubRequestHandler. Normalized mapped under returned 'null'
Aug 02, 2016 4:19:37 PM org.eclipse.jetty.servlet.ServletHandler doHandle
WARNING: Error for /my/resource
java.lang.NoSuchMethodError: javax.servlet.http.HttpServletResponse.getHeader(Ljava/lang/String;)Ljava/lang/String;
at org.eclipse.jetty.servlets.GzipFilter.doFilter(GzipFilter.java:322)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:585)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1127)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1061)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:110)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
at org.eclipse.jetty.server.Server.handle(Server.java:499)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:310)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:257)
at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:540)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555)
at java.lang.Thread.run(Thread.java:745)

Aug 02, 2016 4:19:37 PM org.eclipse.jetty.server.HttpChannel handle
WARNING: /my/resource
java.lang.NoSuchMethodError: javax.servlet.http.HttpServletRequest.isAsyncStarted()Z
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:684)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1127)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1061)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:110)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
at org.eclipse.jetty.server.Server.handle(Server.java:499)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:310)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:257)
at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:540)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555)
at java.lang.Thread.run(Thread.java:745)

Aug 02, 2016 4:19:37 PM org.eclipse.jetty.server.HttpChannel handleException
WARNING: Could not send response error 500: java.lang.NoSuchMethodError: javax.servlet.http.HttpServletRequest.isAsyncStarted()Z
16:19:37,794  INFO webservice.common.HttpServiceConnImpl:91 - <==get() :: {STATUSCODE=500, RESPONSEHEADERS={Cache-Control=must-revalidate,no-cache,no-store, Content-Type=text/html; charset=ISO-8859-1, Content-Length=395, Connection=close, Server=Jetty(9.2.13.v20150730)}, RESPONSEBODY=<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1"/>
<title>Error 500 </title>
</head>
<body>
<h2>HTTP ERROR: 500</h2>
<p>Problem accessing /my/resource. Reason:
<pre>    java.lang.NoSuchMethodError: javax.servlet.http.HttpServletResponse.getHeader(Ljava/lang/String;)Ljava/lang/String;</pre></p>
<hr /><i><small>Powered by Jetty://</small></i>
</body>
</html>

Vipin Jose

unread,
Aug 3, 2016, 1:34:37 PM8/3/16
to wiremock-user
Yes, seems like that was the issue.

I ran  mvn dependency:tree and found that there was another saxon jar in the tree. Fiddled around using <exclusions> tag in the main dependency and the issue went away.

Thanks.
Reply all
Reply to author
Forward
0 new messages