question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

WireMockRule cause error 500 when getInputStream from urlConnection

See original GitHub issue

Is it normal that the code above cause a HTTP response code: 500 ? :

public class MyTest {

    @Rule
    public WireMockRule wireMockRule = new WireMockRule(7032);

    @Test
    public void exampleTest() throws IOException {
        stubFor(get(urlEqualTo("/my/resource"))
                .withHeader("Accept", equalTo("text/xml"))
                .willReturn(aResponse()
                        .withStatus(200)
                        .withHeader("Content-Type", "text/xml")
                        .withBody("<response>Some content</response>")));

        URLConnection urlConnection = new URL("http://localhost:7032/my/resource").openConnection();
        Assert.assertNotNull(urlConnection.getInputStream()); // java.io.IOException: Server returned HTTP response code: 500 for URL: http://localhost:7032/my/resource
    }

}

It’s throw

java.io.IOException: Server returned HTTP response code: 500 for URL: http://localhost:7032/my/resource

I am using Wiremock 2.5.1 with JUnit 4.12.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
Aure77commented, Feb 1, 2017

I found the problem. My projet (target 1.6) use servlet-api 2.5 as dependency to compile my sources (I am using an old application server).

<dependency>
	<groupId>javax.servlet</groupId>
	<artifactId>servlet-api</artifactId>
	<version>2.5</version>
	<scope>provided</scope>
</dependency>

But it is in conflict with Wiremock jetty servlet api version 3.1 causing this error 500… Do you have any solution to isolate wiremock test dependencies (I can’t upgrade my project to servlet api 3.1) ?

0reactions
tomakehurstcommented, Feb 2, 2017

That’s a hard one to solve unfortunately, other than by running WireMock in a separate process.

Read more comments on GitHub >

github_iconTop Results From Across the Web

WireMockRule cause error 500 when getInputStream ... - GitHub
Is it normal that the code above cause a HTTP response code: 500 ? : public class MyTest { @Rule public WireMockRule wireMockRule...
Read more >
HttpURLConnection always return error 500 - Stack Overflow
i'm trying to run a soap request in a basic http request...naturally i tried with external tools the message and is correct, ...
Read more >
Trouble Getting Started - Google Groups
1) WireMock is running, your client is connecting to it but something about how/where you're running it is causing it to throw a...
Read more >
Getting a 500 HTTP status returned from my web service with ...
getInputStream. No errors appear in the glassfish log on the server so I'm at a loss as to what I have done wrong...
Read more >
Testing server faults with Wiremock - allegro.tech blog
Due to an error in the service implementation, the server returned 200 OK instead of 500, but the response body was as for...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found