Karate: Unexpected end of file from server - When calling local standalone wiremock server.

Created on 3 Apr 2017  ·  6Comments  ·  Source: intuit/karate

Running a simple wiremock standalone server

java -jar wiremock-standalone-2.5.1.jar --port=9000 --verbose

The server is available via http://localhost:9000 and can be accessed via postman/curl etc

When attempting to run a test from Karate using the url above, I get the following error

Scenario: Service calls product service to get a SPORTS OFFERING  Time elapsed: 0.004 sec  <<< ERROR!
javax.ws.rs.ProcessingException: java.net.SocketException: Unexpected end of file from server
        at org.glassfish.jersey.client.internal.HttpUrlConnector.apply(HttpUrlConnector.java:287)
        at org.glassfish.jersey.client.ClientRuntime.invoke(ClientRuntime.java:252)
        at org.glassfish.jersey.client.JerseyInvocation$1.call(JerseyInvocation.java:684)
        at org.glassfish.jersey.client.JerseyInvocation$1.call(JerseyInvocation.java:681)
        at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
        at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
        at org.glassfish.jersey.internal.Errors.process(Errors.java:228)
        at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:444)
        at org.glassfish.jersey.client.JerseyInvocation.invoke(JerseyInvocation.java:681)
        at org.glassfish.jersey.client.JerseyInvocation$Builder.method(JerseyInvocation.java:411)
        at com.intuit.karate.StepDefs.method(StepDefs.java:318)
        at ✽.When method get(services/product/offerings.feature:11)
Caused by: java.net.SocketException: Unexpected end of file from server
        at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:792)
        at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:647)
        at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:789)
        at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:647)
        at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1569)
        at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1474)
        at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:480)
        at org.glassfish.jersey.client.internal.HttpUrlConnector._apply(HttpUrlConnector.java:399)
        at org.glassfish.jersey.client.internal.HttpUrlConnector.apply(HttpUrlConnector.java:285)
        at org.glassfish.jersey.client.ClientRuntime.invoke(ClientRuntime.java:252)
        at org.glassfish.jersey.client.JerseyInvocation$1.call(JerseyInvocation.java:684)
        at org.glassfish.jersey.client.JerseyInvocation$1.call(JerseyInvocation.java:681)
        at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
        at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
        at org.glassfish.jersey.internal.Errors.process(Errors.java:228)
        at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:444)
        at org.glassfish.jersey.client.JerseyInvocation.invoke(JerseyInvocation.java:681)
        at org.glassfish.jersey.client.JerseyInvocation$Builder.method(JerseyInvocation.java:411)
        at com.intuit.karate.StepDefs.method(StepDefs.java:318)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at cucumber.runtime.Utils$1.call(Utils.java:40)
        at cucumber.runtime.Timeout.timeout(Timeout.java:16)
        at cucumber.runtime.Utils.invoke(Utils.java:34)
        at cucumber.runtime.java.JavaStepDefinition.execute(JavaStepDefinition.java:38)
        at cucumber.runtime.StepDefinitionMatch.runStep(StepDefinitionMatch.java:37)
        at cucumber.runtime.Runtime.runStep(Runtime.java:300)
        at cucumber.runtime.model.StepContainer.runStep(StepContainer.java:44)
        at cucumber.runtime.model.StepContainer.runSteps(StepContainer.java:39)
        at cucumber.runtime.model.CucumberScenario.run(CucumberScenario.java:44)
        at cucumber.runtime.junit.ExecutionUnitRunner.run(ExecutionUnitRunner.java:102)
        at cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:63)
        at cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:18)
        at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
        at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
        at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
        at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
        at cucumber.runtime.junit.FeatureRunner.run(FeatureRunner.java:70)
        at com.intuit.karate.junit4.Karate.runChild(Karate.java:60)
        at com.intuit.karate.junit4.Karate.runChild(Karate.java:25)
        at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
        at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
        at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
        at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
        at com.intuit.karate.junit4.Karate.run(Karate.java:66)
        at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252)
        at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
        at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
        at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
        at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
        at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
        at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)

We are able to run against a version of the wiremock server hosted in CI via TeamCity with no issues.

Any ideas?

Thanks in advance :)

invalid

Most helpful comment

Just to revisit this @ptrthomas

Got this working now for my local wiremock service, by changing the port to 1705 rather than 9000!

thanks again!

 java -jar wiremock-standalone-2.5.1.jar --root-dir=stubs --port=1705 --verbose

All 6 comments

Quick one, can you add a -Dhttp.keepAlive=false to the wiremock start and see if that helps ? something like java -jar -Dhttp.keepAlive=false [..]

Thanks for the response chap.

Tried

java -jar -DKeepAlive=false wiremock-standalone-2.5.1.jar --port=9000 --verbose

to no avail. Still getting the same error - javax.ws.rs.ProcessingException: java.net.SocketException: Unexpected end of file from server

Had looked at the wiremock documentation and they don't appear to support setting of keep-alive

http://wiremock.org/docs/running-standalone/

Wonder if I may be able to via an extension.

Tres bizarre!

Karate uses WireMock for the unit-test: https://github.com/intuit/karate/tree/master/karate-junit4/src/test/java/com/intuit/karate/junit4/wiremock

So if you can use that as a starting point and replicate, that might help. Also ensure that wiremock is started on Java 8. Try -Dfile.encoding=utf-8 - is the TeamCity JAR / java version the same.

Also it does look like a known issue with WireMock: https://github.com/tomakehurst/wiremock/issues/132#issuecomment-288984013
https://github.com/tomakehurst/wiremock/issues/256

As per some stackoverflow posts I read, this can also happen if there are spaces or special characters in the URL.

Will close as unable to replicate.

Thanks buddy for suggesting some investigation routes.

I had seen that issue listed on wiremock and upon checking stackoverflow too.

I will do some investigation and should I find a solution, I will post back.
👍

Just to revisit this @ptrthomas

Got this working now for my local wiremock service, by changing the port to 1705 rather than 9000!

thanks again!

 java -jar wiremock-standalone-2.5.1.jar --root-dir=stubs --port=1705 --verbose

really appreciate you reporting this back, this will help others. maybe there was a process that had locked that port or it was a permissions issue.

Was this page helpful?
0 / 5 - 0 ratings