Exception when setting fixedDelay using Java

928 views
Skip to first unread message

vladi....@gmail.com

unread,
Feb 5, 2016, 7:31:35 PM2/5/16
to wiremock-user
Hi guys, 
I got stuck on this issue. I get exceptions when I call a stub that has been created using Java and has a fixed delay.

stubFor(get(urlMatching(MOCK_PATH)).willReturn(aResponse()
.withHeader("Content-Type", "application/json")
.withBodyFile(payload)
.withFixedDelay(2000)));

is causing an exception:

2016-02-05 16:23:25,262 ERROR [WireMock] (15105658@qtp-89448984-4)  /mock/
java.lang.RuntimeException: wiremock.org.mortbay.jetty.EofException
        at com.github.tomakehurst.wiremock.jetty6.Jetty6HandlerDispatchingServlet.writeAndTranslateExceptions(Jetty6HandlerDispatchingServlet.java:134)
        at com.github.tomakehurst.wiremock.jetty6.Jetty6HandlerDispatchingServlet.applyResponse(Jetty6HandlerDispatchingServlet.java:124)
        at com.github.tomakehurst.wiremock.jetty6.Jetty6HandlerDispatchingServlet.service(Jetty6HandlerDispatchingServlet.java:103)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
        at wiremock.org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
        at wiremock.org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:401)
        at wiremock.org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:766)
        at wiremock.org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114)
        at wiremock.org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
        at wiremock.org.mortbay.jetty.Server.handle(Server.java:326)
        at wiremock.org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
        at wiremock.org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:928)
        at wiremock.org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:549)
        at wiremock.org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)
        at wiremock.org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
        at wiremock.org.mortbay.jetty.bio.SocketConnector$Connection.run(SocketConnector.java:228)
        at com.github.tomakehurst.wiremock.jetty6.DelayableSocketConnector$1.run(DelayableSocketConnector.java:49)
        at wiremock.org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
Caused by: wiremock.org.mortbay.jetty.EofException
        at wiremock.org.mortbay.jetty.HttpGenerator.flush(HttpGenerator.java:791)
        at wiremock.org.mortbay.jetty.AbstractGenerator$Output.flush(AbstractGenerator.java:569)
        at wiremock.org.mortbay.jetty.HttpConnection$Output.flush(HttpConnection.java:1012)
        at com.github.tomakehurst.wiremock.jetty6.Jetty6HandlerDispatchingServlet.writeAndTranslateExceptions(Jetty6HandlerDispatchingServlet.java:131)
        ... 17 more
Caused by: java.net.SocketException: Software caused connection abort: socket write error
        at java.net.SocketOutputStream.socketWrite0(Native Method)
        at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:109)
        at java.net.SocketOutputStream.write(SocketOutputStream.java:153)
        at wiremock.org.mortbay.io.ByteArrayBuffer.writeTo(ByteArrayBuffer.java:368)
        at wiremock.org.mortbay.io.bio.StreamEndPoint.flush(StreamEndPoint.java:129)
        at wiremock.org.mortbay.io.bio.StreamEndPoint.flush(StreamEndPoint.java:161)
        at wiremock.org.mortbay.jetty.HttpGenerator.flush(HttpGenerator.java:714)
        ... 20 more
2016-02-05 16:23:28,013 ERROR [WireMock] (87923312@qtp-89448984-3)  /mock/
java.lang.RuntimeException: wiremock.org.mortbay.jetty.EofException
        at com.github.tomakehurst.wiremock.jetty6.Jetty6HandlerDispatchingServlet.writeAndTranslateExceptions(Jetty6HandlerDispatchingServlet.java:134)
        at com.github.tomakehurst.wiremock.jetty6.Jetty6HandlerDispatchingServlet.applyResponse(Jetty6HandlerDispatchingServlet.java:124)
        at com.github.tomakehurst.wiremock.jetty6.Jetty6HandlerDispatchingServlet.service(Jetty6HandlerDispatchingServlet.java:103)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
        at wiremock.org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
        at wiremock.org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:401)
        at wiremock.org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:766)
        at wiremock.org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114)
        at wiremock.org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
        at wiremock.org.mortbay.jetty.Server.handle(Server.java:326)
        at wiremock.org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
        at wiremock.org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:945)
        at wiremock.org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:756)
        at wiremock.org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:218)
        at wiremock.org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
        at wiremock.org.mortbay.jetty.bio.SocketConnector$Connection.run(SocketConnector.java:228)
        at com.github.tomakehurst.wiremock.jetty6.DelayableSocketConnector$1.run(DelayableSocketConnector.java:49)
        at wiremock.org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
Caused by: wiremock.org.mortbay.jetty.EofException
        at wiremock.org.mortbay.jetty.HttpGenerator.flush(HttpGenerator.java:791)
        at wiremock.org.mortbay.jetty.AbstractGenerator$Output.flush(AbstractGenerator.java:569)
        at wiremock.org.mortbay.jetty.HttpConnection$Output.flush(HttpConnection.java:1012)
        at com.github.tomakehurst.wiremock.jetty6.Jetty6HandlerDispatchingServlet.writeAndTranslateExceptions(Jetty6HandlerDispatchingServlet.java:131)
        ... 17 more
Caused by: java.net.SocketException: Software caused connection abort: socket write error
        at java.net.SocketOutputStream.socketWrite0(Native Method)
        at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:109)
        at java.net.SocketOutputStream.write(SocketOutputStream.java:153)
        at wiremock.org.mortbay.io.ByteArrayBuffer.writeTo(ByteArrayBuffer.java:368)
        at wiremock.org.mortbay.io.bio.StreamEndPoint.flush(StreamEndPoint.java:129)
        at wiremock.org.mortbay.io.bio.StreamEndPoint.flush(StreamEndPoint.java:161)
        at wiremock.org.mortbay.jetty.HttpGenerator.flush(HttpGenerator.java:714)
        ... 20 more

Same configuration using JSON and Postman is working with no issues.
And If I remove the delay the exception goes away.

Let me know if I am doing anything wrong here or there is an actual problem.

Thank you in advance!
Vlad

Tom Akehurst

unread,
Feb 7, 2016, 4:45:25 PM2/7/16
to wiremock-user
Can you give any details as to how you're calling WireMock? Sounds like it might be a problem with your HTTP client config.

Vlad

unread,
Feb 7, 2016, 5:19:21 PM2/7/16
to wiremock-user
Unfortunately I don't have a lot of details on how the mock is being called. It is an existing product that is calling an external service that way, and is working.
I am trying to replicate the existing service so that I can test various behaviors - different responses, delays, etc.

Is there something I can do to get more information to help resolve the issue? I know that the product uses httpclient but I am not aware of any specific configurations that could be a problem. Is there debug log that I can enable?

Thanks!

Tom Akehurst

unread,
Feb 8, 2016, 3:58:19 AM2/8/16
to wiremock-user
The apache client uses commons-logging so providing a impl of this e.g. log4j with a config file enabling debug messages will cause it to log out quite a lot of detail. You can also do this with WireMock if you're starting it from your Java project.

Alternatively I'd suggest using tcpdump if you're on osx or linux to look at the raw exchange between the client and server.

Vlad

unread,
Feb 8, 2016, 2:45:01 PM2/8/16
to wiremock-user
I used rawcap to get the wire exchange and there here is what I get when the exception happens:

POST /mock/ HTTP/1.1

Content-Length: 659

Content-Type: application/x-www-form-urlencoded; charset=ISO-8859-1

Host: localhost:8089

Connection: Keep-Alive


body

HTTP/1.1 200 OK

Content-Type: application/x-www-form-urlencoded

Transfer-Encoding: chunked

Server: Jetty(6.1.x)


8C4


For this case I used timeout of 3000ms
The main difference is that the response body is not there, compared to the case there the timeout is 100ms I receive the whole response I created in wiremock.

I am running standalone wiremock:
java -jar wiremock-1.57-standalone.jar --port 8089 --verbose

I suspect the problem is because the caller side just drops the connection and does not wait for the response. But even if this is the case wiremock should be able to handle it, correct?

Thanks!
Vlad

Vlad

unread,
Feb 8, 2016, 5:20:07 PM2/8/16
to wiremock-user
I asked our developers and they said that probably WireMock just don't handle the errors right, we use standard apache httpclient underneath.

What we do on our side is that we timeout with read timeout:
exception=IOException EndPoint endpoint=http://localhost:8089/mock/ exception=java.net.SocketTimeoutException Read timed out

To explain the case better = we have timeout on ourside of 3000ms. We need to test it so that WireMock should do 3005ms for example and we will timeout before that.

Vlad

unread,
Feb 8, 2016, 5:32:46 PM2/8/16
to wiremock-user
Which causes on WireMock side:

Vlad

unread,
Feb 8, 2016, 8:54:58 PM2/8/16
to wiremock-user
One more thing - there is no exception when using wiremock-standalone-2.0.8-beta as standalone.
Unfortunately when I switched to 2.0.8-beta in the pom it fails to run completely.

Tom Akehurst

unread,
Feb 9, 2016, 4:10:42 AM2/9/16
to wiremock-user
What kind and length of timeout are you using in the client?

I find it odd that a read or connect timeout would have any effect in the scenario you captured with rawcap since wiremock managed to return a response.

Vlad

unread,
Feb 9, 2016, 11:44:25 AM2/9/16
to wiremock-user
Client=2000ms, WireMock=3000ms.
Works such no problem with 2.0.8-beta standalone. Unfortunately 2.0.8-beta for Java (TestNG) does not work, it breaks the build.

I think WireMock will establish the connection but will wait to send the payload. In the rawcap scenario the actual wiremock payload is missing, the connection was abandoned from client side because of read timeout. 

Tom Akehurst

unread,
Feb 9, 2016, 12:14:57 PM2/9/16
to wiremock-user
Can you elaborate the problems you're having with 2.0.8?

It seems it'd be more productive trying to get that working than fixing problems with a version based on Jetty 6.

Vlad

unread,
Feb 9, 2016, 1:47:48 PM2/9/16
to wiremock-user
Hi Tom, 
First of all I would like to thank you for trying to help me on this problem.

Here is how I include the dependency in the pom, let me know if this is correct:

<dependency>
<groupId>com.github.tomakehurst</groupId>
<artifactId>wiremock-standalone</artifactId>
<version>2.0.8-beta</version>
</dependency>

Without changing the way wiremock is being imported, instantiated and used, when I run the code I am getting an exception:

Caused by: java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/servlet/DispatcherType
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
        at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        at com.github.tomakehurst.wiremock.jetty9.JettyHttpServerFactory.buildHttpServer(JettyHttpServerFactory.java:31)
        at com.github.tomakehurst.wiremock.WireMockServer.<init>(WireMockServer.java:106)
        ... 28 more

        at org.apache.maven.plugin.surefire.booterclient.ForkStarter.fork(ForkStarter.java:479)
        at org.apache.maven.plugin.surefire.booterclient.ForkStarter.fork(ForkStarter.java:352)
        at org.apache.maven.plugin.surefire.booterclient.ForkStarter.run(ForkStarter.java:158)
        at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeProvider(AbstractSurefireMojo.java:958)
        at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeAfterPreconditionsChecked(AbstractSurefireMojo.java:822)
        at org.apache.maven.plugin.surefire.AbstractSurefireMojo.execute(AbstractSurefireMojo.java:720)
        at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
        ... 21 more
[ERROR]
[ERROR] Re-run Maven using the -X switch to enable full debug logging.

Do you know if the latest version is backwards compatible? Should I use it in a different way compared to 1.58?

Thanks!
Vlad

Vlad

unread,
Feb 9, 2016, 6:28:32 PM2/9/16
to wiremock-user
To reproduce the delay exception problem you don't need httpclient at all.

The same problem occurs with Postman or any other client. Here are the steps to reproduce:

{
    "request": {
        "method": "GET",
        "urlPattern": "/mock/timeout"
    },
    "response": {
        "status": 200,
        "fixedDelayMilliseconds": 6000,
        "body": "Timeout"
    }
}


3. After 2-3 seconds (while Postman is still waiting for the response) hit Reset this tab (or close Postman)

Result in WireMock console:

2016-02-09 15:23:49.285 /mock/timeout
Caused by: java.net.SocketException: Software caused connection abort: socket write error
        at java.net.SocketOutputStream.socketWrite0(Native Method)
        at java.net.SocketOutputStream.socketWrite(Unknown Source)
        at java.net.SocketOutputStream.write(Unknown Source)
        at wiremock.org.mortbay.io.ByteArrayBuffer.writeTo(ByteArrayBuffer.java:368)
        at wiremock.org.mortbay.io.bio.StreamEndPoint.flush(StreamEndPoint.java:129)
        at wiremock.org.mortbay.io.bio.StreamEndPoint.flush(StreamEndPoint.java:161)
        at wiremock.org.mortbay.jetty.HttpGenerator.flush(HttpGenerator.java:714)
        ... 20 more


Notes: 
This happens ONLY if there is a body specified. If there is no body it's all good.
The problem is for both GET and POST.
It takes about one more second after the connection is closed for the exception to show.

Vlad

unread,
Feb 9, 2016, 7:30:18 PM2/9/16
to wiremock-user
The 2.0.8-beta issues were fixed by adding the following dependency to my pom:

<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
</dependency>


This should be a wiremock dependency, but it works as a workaround for now.

Vlad

unread,
Feb 9, 2016, 8:06:05 PM2/9/16
to wiremock-user
Well.... this fixed the broken build but it did not fix the code. Still having issues.. :(

Tom Akehurst

unread,
Feb 10, 2016, 4:00:00 AM2/10/16
to wiremock-user
That's very odd. I've never heard of anyone having to do that before. It certainly shouldn't be necessary.

Is there any chance you have another depenency that's pulling an incompatible servlet api transitively?

Vlad

unread,
Feb 10, 2016, 11:00:54 AM2/10/16
to wiremock-user
I will check this, thanks.

How about the delay exceptions? It is definitely on the wiremock side and I am surprised it was not hit till now.

Vlad

unread,
Feb 10, 2016, 1:42:39 PM2/10/16
to wiremock-user
Created issue #361 for the exception when call is being closed before the delay.

Regarding 2.0.8-beta issues I have a transient dependency for javaee-api 6.0. Upping this to 7.0 fixes the build but I am getting a lot of warnings:

2016-02-10 10:40:12,229 WARN  [wiremock.org.eclipse.jetty.server.HttpChannel] (qtp1861971862-17)  Could not send response error 500: java.lang.NoSuchMethodError: javax.servlet.http.HttpServletRequest.isAsyncStarted()Z
2016-02-10 10:40:12,234 WARN  [wiremock.org.eclipse.jetty.server.HttpChannel] (qtp1861971862-18)  Could not send response error 500: java.lang.NoSuchMethodError: javax.servlet.http.HttpServletRequest.isAsyncStarted()Z
2016-02-10 10:40:15,221 WARN  [wiremock.org.eclipse.jetty.servlet.ServletHandler] (qtp1861971862-16)  Error for /mock/
java.lang.NoSuchMethodError: javax.servlet.http.HttpServletResponse.getHeader(Ljava/lang/String;)Ljava/lang/String;
        at wiremock.org.eclipse.jetty.servlets.GzipFilter.doFilter(GzipFilter.java:322)
        at wiremock.org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652)
        at wiremock.org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:585)
        at wiremock.org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1127)
        at wiremock.org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515)
        at wiremock.org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1061)
        at wiremock.org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
        at wiremock.org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:110)

        at wiremock.org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
        at wiremock.org.eclipse.jetty.server.Server.handle(Server.java:499)
        at wiremock.org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:310)
        at wiremock.org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:257)
        at wiremock.org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:540)
        at wiremock.org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635)
        at wiremock.org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555)
        at java.lang.Thread.run(Thread.java:745)

Any idea what is causing this?
Thanks!
Vlad

Vlad

unread,
Feb 10, 2016, 1:57:21 PM2/10/16
to wiremock-user
Fixed by adding explicitly to the pom:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
</dependency>

Tom Akehurst

unread,
Feb 11, 2016, 7:52:39 AM2/11/16
to wiremock-user
And you're definitely on a 2.x version of WireMock?

I really don't understand that. Adding that dependency should break it, as 2.x uses Jetty 9 which in turn includes Servlet 3.0. Is there any chance you could post a full dependency dump from your project?

Leandro Garcia

unread,
Jun 29, 2016, 2:10:05 PM6/29/16
to wiremock-user
Hello, any idea what could be causing this? I get a similar error on version 2.1.0-beta :(

Tom Akehurst

unread,
Jun 29, 2016, 2:41:17 PM6/29/16
to wiremock-user
Which error are you seeing exactly?

And what else do you have on your classpath?

Jim Scarborough

unread,
Jan 8, 2020, 10:12:56 AM1/8/20
to wiremock-user
I'm seeing a very similar stack trace, these four lines, and the rest above:

  java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/servlet/DispatcherType
  ...
  at java.lang.Class.forName(Class.java:264) 
  at com.github.tomakehurst.wiremock.jetty9.JettyHttpServerFactory.getServerConstructor(JettyHttpServerFactory.java:35) 
  at com.github.tomakehurst.wiremock.jetty9.JettyHttpServerFactory.<clinit>(JettyHttpServerFactory.java:30) 
  at com.github.tomakehurst.wiremock.core.WireMockConfiguration.<init>(WireMockConfiguration.java:78)
  ...

using wiremock-jre8-standalone 2.24.1.  The exception comes when getServerConstructor attempts to get the class for name "com.github.tomakehurst.wiremock.jetty94.Jetty94HttpServer". I can fix it with a dependency on javaee-api as before:

        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-api</artifactId>
            <version>8.0</version>
            <scope>test</scope>
        </dependency>
Reply all
Reply to author
Forward
0 new messages