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.

Target Server failed to respond

See original GitHub issue

Hi, I’m currently trying to write a simple pact consumer test with Junit5 & Lambda DSL. I’m stuck with the mock server telling me “Target Server failed to respond”

My versions are: pact-jvm-consumer-junit5 4.0.8 pact-jvm-consumer-java8 4.0.8 Junit Jupiter 5.5.2 Java 11 Kotlin 1.3.70 (I added kotlin-stdlib to my pom.xml with version 1.3.70 for scope test)

I get the following in the logs 07:52:54.773 [main] DEBUG au.com.dius.pact.consumer.junit5.PactConsumerTestExt - Found @PactTestFor annotation on test method 07:52:54.784 [main] DEBUG au.com.dius.pact.consumer.junit5.PactConsumerTestExt - Found @PactTestFor annotation on test class 07:52:54.785 [main] DEBUG au.com.dius.pact.consumer.junit5.PactConsumerTestExt - providerInfo = ProviderInfo(providerName=contract-service, hostInterface=, port=8080, pactVersion=null, providerType=null) 07:52:54.787 [main] DEBUG au.com.dius.pact.consumer.junit5.PactConsumerTestExt - Looking for @Pact method named 'contract' for provider 'contract-service' 07:52:54.790 [main] DEBUG au.com.dius.pact.consumer.junit5.PactConsumerTestExt - Invoking method 'contract' to get Pact for the test 'testContract' 07:52:54.973 [main] DEBUG au.com.dius.pact.consumer.BaseJdkMockServer - Starting mock server 07:52:54.975 [main] DEBUG au.com.dius.pact.consumer.BaseJdkMockServer - Mock server started: /127.0.0.1:8080 07:52:55.539 [HTTP-Dispatcher] DEBUG au.com.dius.pact.consumer.BaseJdkMockServer - Received request: method: GET path: /contracts/13 query: {} headers: {Accept-encoding=[gzip,deflate], Connection=[Keep-Alive], Host=[127.0.0.1:8080], User-agent=[Apache-HttpClient/4.5.6 (Java/11.0.6)]} matchers: MatchingRules(rules={}) generators: Generators(categories={}) body: EMPTY 07:52:55.542 [HTTP-Dispatcher] DEBUG au.com.dius.pact.core.matchers.RequestMatching - comparing to expected request: method: GET path: /contracts/13 query: {} headers: {} matchers: MatchingRules(rules={}) generators: Generators(categories={}) body: MISSING 07:52:56.072 [HTTP-Dispatcher] DEBUG au.com.dius.pact.core.matchers.Matching - Found a matcher for text/plain -> au.com.dius.pact.core.matchers.PlainTextBodyMatcher@aa4b5e0 07:52:56.073 [HTTP-Dispatcher] DEBUG au.com.dius.pact.core.matchers.RequestMatching - Request mismatch: [] Mar 23, 2020 7:52:56 AM org.apache.http.impl.execchain.RetryExec execute INFO: I/O exception (org.apache.http.NoHttpResponseException) caught when processing request to {}->http://127.0.0.1:8080: The target server failed to respond

My code looks like this:

import au.com.dius.pact.consumer.MockServer;
import au.com.dius.pact.consumer.dsl.PactDslWithProvider;
import au.com.dius.pact.consumer.junit5.PactConsumerTestExt;
import au.com.dius.pact.consumer.junit5.PactTestFor;
import au.com.dius.pact.core.model.RequestResponsePact;
import au.com.dius.pact.core.model.annotations.Pact;
import static io.pactfoundation.consumer.dsl.LambdaDsl.newJsonBody;
import io.pactfoundation.consumer.dsl.LambdaDslJsonBody;
import java.io.IOException;
import org.apache.http.HttpResponse;
import org.apache.http.client.fluent.Request;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

import java.util.HashMap;
import java.util.Map;

@ExtendWith(PactConsumerTestExt.class)
@PactTestFor(providerName = "contract-service", port = "8080")
public class PactContractServiceTest {

        private final String CONTRACT = "/contracts";

        private static final String CONTENT_HEADER = "Content-Type";

        private static final String CONTENT_HEADER_VALUE = "application/hal+json";

        @Pact(consumer = "mail-service", provider = "contract-service")
        public RequestResponsePact contract(PactDslWithProvider builder) {

            LambdaDslJsonBody contractEntityJson = newJsonBody((o) -> {
                o.id("id");
                o.stringType("userId");
               … // irrelevant
                o.numberType("amount");
            });

            return builder
                    .given("Contract with id 13 exists")
                    .uponReceiving("retrieving contract info")
                        .path(CONTRACT + "/13")
                        .method("GET")
                    .willRespondWith()
                        .status(200)
                        .headers(responseHeaders())
                        .body(contractEntityJson.build())
                    .toPact();
        }

        @Test
        @PactTestFor(pactMethod = "contract")
        public void testContract(MockServer mockServer) throws IOException {
            HttpResponse httpResponse = Request.Get(mockServer.getUrl() + CONTRACT + "/13").execute().returnResponse();
            assertEquals(httpResponse.getStatusLine().getStatusCode(), 200);
        }

        private Map<String, String> responseHeaders() {
            Map<String, String> headers = new HashMap();
            headers.put(CONTENT_HEADER, CONTENT_HEADER_VALUE);
            return headers;
        }
}

I assume I’m either missing something very basic, or there’s a problem with the versions I use?

Any help is highly appreciated!

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
broesercommented, Mar 24, 2020

I think I fixed it by updating gson to 2.8.6 (I used 2.8.5 before) – I think this should be documented somewhere though (or work out of the box 😉 ).

0reactions
uglyogcommented, Feb 20, 2021

Closing this as it seems to always be due to outdated dependencies causing the issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

HttpClientError: The target server failed to respond
I am trying to hit a server using HTTP client using PoolingClientConnectionManager setting max ... The target server failed to respond org.apache.http.
Read more >
'Target server failed to respond' Message while sending a ...
Issue. 'Target server failed to respond' message while accessing Spectrum service through SOAP UI. kA21E000000TUwpSAG_en_US_5_0 · Cause. This could be caused to ...
Read more >
"The target server failed to respond." | Service Virtualization
Hello everyone,I have a problem that I can't solve.I created a "Execute Script" step in my model file, called getLiveInvocation, ...
Read more >
org.apache.http.NoHttpResponseException: The target server ...
On debug i can see this error : org.apache.http.NoHttpResponseException: The target server failed to respond Sometimes, it's working after many retries ?
Read more >
"The target server failed to respond" - Google Groups
Hi- I'm trying to use JetS3t's synchronize program to backup my company's files on Amazon S3. Unfortunately I'm running into an error on...
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