Unable to get stub response

313 views
Skip to first unread message

PrachiT

unread,
Apr 15, 2016, 5:40:11 PM4/15/16
to wiremock-user
I have AService that I am trying to mock with Wiremock and gettign into issues with that...

public class MockAService extends WireMockRule {

    public MockAService(Options options) {
        super(options);
    }

    public MockAService(int port) {
        this(wireMockConfig().port(port));
        wireMockConfig().notifier(new ConsoleNotifier(true));
    }
        
    @Override
    protected void before() {
            
            try {
                byte[] responseBytes = createResponseBody( "src\\test\\resources\\__files\\atlantis\\availDetailResponse.xml", AvailDetailResponse.class);
                stubFor(post(urlPathMatching("/localhost"))
                                 .willReturn(aResponse()
                                 .withStatus(200)
                                 .withHeader("Content-Type", "application/fastinfoset")
                                 .withBody(responseBytes)));
                } catch (Exception e) {
                    e.printStackTrace();
                }
        }
        
        private byte[] createResponseBody(String pathToFile, Class declaredType) throws Exception {            
            JAXBContext jaxbContext = JAXBContext.newInstance(declaredType);
            Source source = new StreamSource(pathToFile);
            ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
            XMLStreamWriter staxDocumentSerializer = new StAXDocumentSerializer(outputStream);
            JAXBElement retrieveResponse = jaxbContext.createUnmarshaller().unmarshal(source, declaredType);
            jaxbContext.createMarshaller().marshal(retrieveResponse, staxDocumentSerializer);
            byte[] outputBytes = outputStream.toByteArray();
            return outputBytes;
        }
}



TEST CLASS....

public class HotelProductControllerSmokeTestIT {

....
    
    @ClassRule
    public static MockAService aServiceMockRule = new MockAService(5082);
      ....

}


However the Stub returns a 404 Response...

Here are the logs that I found:


2016-04-14 16:49:26,109,Type=DEBUG,Category=org.springframework.web.client.RestTemplate,Thread=main,MDC=,Text=Created POST request for "http://localhost:5082"
2016-04-14 16:49:26,115,Type=DEBUG,Category=org.springframework.web.client.RestTemplate,Thread=main,MDC=,Text=Setting request Accept header to [application/octet-stream, application/json, application/*+json, */*]
2016-04-14 16:49:26,115,Type=DEBUG,Category=org.springframework.web.client.RestTemplate,Thread=main,MDC=,Text=Writing [[B@7816f329] using [org.springframework.http.converter.ByteArrayHttpMessageConverter@2ab64657]
2016-04-14 16:49:26,130,Type=DEBUG,Category=org.apache.http.client.protocol.RequestAddCookies,Thread=main,MDC=,Text=CookieSpec selected: default
2016-04-14 16:49:26,131,Type=DEBUG,Category=org.apache.http.client.protocol.RequestAuthCache,Thread=main,MDC=,Text=Auth cache not set in the context
2016-04-14 16:49:26,131,Type=DEBUG,Category=org.apache.http.impl.conn.PoolingHttpClientConnectionManager,Thread=main,MDC=,Text=Connection request: [route: {}->http://localhost:5082][total kept alive: 0; route allocated: 0 of 5; total allocated: 0 of 10]
2016-04-14 16:49:26,131,Type=DEBUG,Category=org.apache.http.impl.conn.PoolingHttpClientConnectionManager,Thread=main,MDC=,Text=Connection leased: [id: 2][route: {}->http://localhost:5082][total kept alive: 0; route allocated: 1 of 5; total allocated: 1 of 10]
2016-04-14 16:49:26,131,Type=DEBUG,Category=org.apache.http.impl.execchain.MainClientExec,Thread=main,MDC=,Text=Opening connection {}->http://localhost:5082
2016-04-14 16:49:26,131,Type=DEBUG,Category=org.apache.http.impl.conn.DefaultHttpClientConnectionOperator,Thread=main,MDC=,Text=Connecting to localhost/127.0.0.1:5082
2016-04-14 16:49:26,132,Type=DEBUG,Category=org.apache.http.impl.conn.DefaultHttpClientConnectionOperator,Thread=main,MDC=,Text=Connection established 127.0.0.1:62470<->127.0.0.1:5082
2016-04-14 16:49:26,132,Type=DEBUG,Category=org.apache.http.impl.execchain.MainClientExec,Thread=main,MDC=,Text=Executing request POST / HTTP/1.1
2016-04-14 16:49:26,132,Type=DEBUG,Category=org.apache.http.impl.execchain.MainClientExec,Thread=main,MDC=,Text=Target auth state: UNCHALLENGED
2016-04-14 16:49:26,132,Type=DEBUG,Category=org.apache.http.impl.execchain.MainClientExec,Thread=main,MDC=,Text=Proxy auth state: UNCHALLENGED
2016-04-14 16:49:26,133,Type=DEBUG,Category=org.apache.http.headers,Thread=main,MDC=,Text=http-outgoing-2 >> POST / HTTP/1.1
2016-04-14 16:49:26,133,Type=DEBUG,Category=org.apache.http.headers,Thread=main,MDC=,Text=http-outgoing-2 >> Accept: application/octet-stream, application/json, application/*+json, */*
2016-04-14 16:49:26,133,Type=DEBUG,Category=org.apache.http.headers,Thread=main,MDC=,Text=http-outgoing-2 >> AvailDetail: true
2016-04-14 16:49:26,133,Type=DEBUG,Category=org.apache.http.headers,Thread=main,MDC=,Text=http-outgoing-2 >> Content-Type: application/octet-stream
2016-04-14 16:49:26,133,Type=DEBUG,Category=org.apache.http.headers,Thread=main,MDC=,Text=http-outgoing-2 >> Message-Id: 53efa782-48a5-4b5f-9819-4374c0341079
2016-04-14 16:49:26,133,Type=DEBUG,Category=org.apache.http.headers,Thread=main,MDC=,Text=http-outgoing-2 >> Content-Length: 1847
2016-04-14 16:49:26,133,Type=DEBUG,Category=org.apache.http.headers,Thread=main,MDC=,Text=http-outgoing-2 >> Host: localhost:5082
2016-04-14 16:49:26,133,Type=DEBUG,Category=org.apache.http.headers,Thread=main,MDC=,Text=http-outgoing-2 >> Connection: Keep-Alive
2016-04-14 16:49:26,133,Type=DEBUG,Category=org.apache.http.headers,Thread=main,MDC=,Text=http-outgoing-2 >> User-Agent: Apache-HttpClient/4.4.1 (Java/1.7.0_06)
2016-04-14 16:49:26,133,Type=DEBUG,Category=org.apache.http.headers,Thread=main,MDC=,Text=http-outgoing-2 >> Accept-Encoding: gzip,deflate
2016-04-14 16:49:26,133,Type=DEBUG,Category=org.apache.http.wire,Thread=main,MDC=,Text=http-outgoing-2 >> "POST / HTTP/1.1[\r][\n]"
2016-04-14 16:49:26,133,Type=DEBUG,Category=org.apache.http.wire,Thread=main,MDC=,Text=http-outgoing-2 >> "Accept: application/octet-stream, application/json, application/*+json, */*[\r][\n]"
2016-04-14 16:49:26,133,Type=DEBUG,Category=org.apache.http.wire,Thread=main,MDC=,Text=http-outgoing-2 >> "AvailDetail: true[\r][\n]"
2016-04-14 16:49:26,133,Type=DEBUG,Category=org.apache.http.wire,Thread=main,MDC=,Text=http-outgoing-2 >> "Content-Type: application/octet-stream[\r][\n]"
2016-04-14 16:49:26,133,Type=DEBUG,Category=org.apache.http.wire,Thread=main,MDC=,Text=http-outgoing-2 >> "Message-Id: 53efa782-48a5-4b5f-9819-4374c0341079[\r][\n]"
2016-04-14 16:49:26,133,Type=DEBUG,Category=org.apache.http.wire,Thread=main,MDC=,Text=http-outgoing-2 >> "Content-Length: 1847[\r][\n]"
2016-04-14 16:49:26,133,Type=DEBUG,Category=org.apache.http.wire,Thread=main,MDC=,Text=http-outgoing-2 >> "Host: localhost:5082[\r][\n]"
2016-04-14 16:49:26,133,Type=DEBUG,Category=org.apache.http.wire,Thread=main,MDC=,Text=http-outgoing-2 >> "Connection: Keep-Alive[\r][\n]"
2016-04-14 16:49:26,133,Type=DEBUG,Category=org.apache.http.wire,Thread=main,MDC=,Text=http-outgoing-2 >> "User-Agent: Apache-HttpClient/4.4.1 (Java/1.7.0_06)[\r][\n]"
2016-04-14 16:49:26,133,Type=DEBUG,Category=org.apache.http.wire,Thread=main,MDC=,Text=http-outgoing-2 >> "Accept-Encoding: gzip,deflate[\r][\n]"
2016-04-14 16:49:26,133,Type=DEBUG,Category=org.apache.http.wire,Thread=main,MDC=,Text=http-outgoing-2 >> "[\r][\n]"
2016-04-14 16:49:26,136,Type=DEBUG,Category=org.apache.http.wire,Thread=main,MDC=,Text=http-outgoing-2 << "HTTP/1.1 404 Not Found[\r][\n]"
2016-04-14 16:49:26,136,Type=DEBUG,Category=org.apache.http.wire,Thread=main,MDC=,Text=http-outgoing-2 << "Content-Type: text/html; charset=iso-8859-1[\r][\n]"
2016-04-14 16:49:26,136,Type=DEBUG,Category=org.apache.http.wire,Thread=main,MDC=,Text=http-outgoing-2 << "Cache-Control: must-revalidate,no-cache,no-store[\r][\n]"
2016-04-14 16:49:26,136,Type=DEBUG,Category=org.apache.http.wire,Thread=main,MDC=,Text=http-outgoing-2 << "Content-Length: 1365[\r][\n]"
2016-04-14 16:49:26,136,Type=DEBUG,Category=org.apache.http.wire,Thread=main,MDC=,Text=http-outgoing-2 << "Server: Jetty(6.1.26)[\r][\n]"
2016-04-14 16:49:26,136,Type=DEBUG,Category=org.apache.http.wire,Thread=main,MDC=,Text=http-outgoing-2 << "[\r][\n]"
2016-04-14 16:49:26,136,Type=DEBUG,Category=org.apache.http.headers,Thread=main,MDC=,Text=http-outgoing-2 << HTTP/1.1 404 Not Found
2016-04-14 16:49:26,136,Type=DEBUG,Category=org.apache.http.headers,Thread=main,MDC=,Text=http-outgoing-2 << Content-Type: text/html; charset=iso-8859-1
2016-04-14 16:49:26,136,Type=DEBUG,Category=org.apache.http.headers,Thread=main,MDC=,Text=http-outgoing-2 << Cache-Control: must-revalidate,no-cache,no-store
2016-04-14 16:49:26,136,Type=DEBUG,Category=org.apache.http.headers,Thread=main,MDC=,Text=http-outgoing-2 << Content-Length: 1365
2016-04-14 16:49:26,136,Type=DEBUG,Category=org.apache.http.headers,Thread=main,MDC=,Text=http-outgoing-2 << Server: Jetty(6.1.26)
2016-04-14 16:49:26,136,Type=DEBUG,Category=org.apache.http.impl.execchain.MainClientExec,Thread=main,MDC=,Text=Connection can be kept alive indefinitely
2016-04-14 16:49:26,137,Type=WARN,Category=org.springframework.web.client.RestTemplate,Thread=main,MDC=,Text=POST request for "http://localhost:5082" resulted in 404 (Not Found); invoking error handler
2016-04-14 16:49:26,137,Type=DEBUG,Category=org.apache.http.wire,Thread=main,MDC=,Text=http-outgoing-2 << "<html>[\n]"
2016-04-14 16:49:26,137,Type=DEBUG,Category=org.apache.http.wire,Thread=main,MDC=,Text=http-outgoing-2 << "<head>[\n]"
2016-04-14 16:49:26,137,Type=DEBUG,Category=org.apache.http.wire,Thread=main,MDC=,Text=http-outgoing-2 << "<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>[\n]"
2016-04-14 16:49:26,137,Type=DEBUG,Category=org.apache.http.wire,Thread=main,MDC=,Text=http-outgoing-2 << "<title>Error 404 NOT_FOUND</title>[\n]"
2016-04-14 16:49:26,137,Type=DEBUG,Category=org.apache.http.wire,Thread=main,MDC=,Text=http-outgoing-2 << "</head>[\n]"
2016-04-14 16:49:26,137,Type=DEBUG,Category=org.apache.http.wire,Thread=main,MDC=,Text=http-outgoing-2 << "<body><h2>HTTP ERROR 404</h2>[\n]"
2016-04-14 16:49:26,137,Type=DEBUG,Category=org.apache.http.wire,Thread=main,MDC=,Text=http-outgoing-2 << "<p>Problem accessing /. Reason:[\n]"
2016-04-14 16:49:26,137,Type=DEBUG,Category=org.apache.http.wire,Thread=main,MDC=,Text=http-outgoing-2 << "<pre>    NOT_FOUND</pre></p><hr /><i><small>Powered by Jetty://</small></i><br/>                                                [\n]"
2016-04-14 16:49:26,137,Type=DEBUG,Category=org.apache.http.wire,Thread=main,MDC=,Text=http-outgoing-2 << "<br/>                                                [\n]"
2016-04-14 16:49:26,137,Type=DEBUG,Category=org.apache.http.wire,Thread=main,MDC=,Text=http-outgoing-2 << "<br/>                                                [\n]"
2016-04-14 16:49:26,137,Type=DEBUG,Category=org.apache.http.wire,Thread=main,MDC=,Text=http-outgoing-2 << "<br/>                                                [\n]"
2016-04-14 16:49:26,137,Type=DEBUG,Category=org.apache.http.wire,Thread=main,MDC=,Text=http-outgoing-2 << "<br/>                                                [\n]"
2016-04-14 16:49:26,137,Type=DEBUG,Category=org.apache.http.wire,Thread=main,MDC=,Text=http-outgoing-2 << "<br/>                                                [\n]"
2016-04-14 16:49:26,137,Type=DEBUG,Category=org.apache.http.wire,Thread=main,MDC=,Text=http-outgoing-2 << "<br/>                                                [\n]"
2016-04-14 16:49:26,137,Type=DEBUG,Category=org.apache.http.wire,Thread=main,MDC=,Text=http-outgoing-2 << "<br/>                                                [\n]"
2016-04-14 16:49:26,137,Type=DEBUG,Category=org.apache.http.wire,Thread=main,MDC=,Text=http-outgoing-2 << "<br/>                                                [\n]"
2016-04-14 16:49:26,137,Type=DEBUG,Category=org.apache.http.wire,Thread=main,MDC=,Text=http-outgoing-2 << "<br/>                                                [\n]"
2016-04-14 16:49:26,137,Type=DEBUG,Category=org.apache.http.wire,Thread=main,MDC=,Text=http-outgoing-2 << "<br/>                                                [\n]"
2016-04-14 16:49:26,137,Type=DEBUG,Category=org.apache.http.wire,Thread=main,MDC=,Text=http-outgoing-2 << "<br/>                                                [\n]"
2016-04-14 16:49:26,137,Type=DEBUG,Category=org.apache.http.wire,Thread=main,MDC=,Text=http-outgoing-2 << "<br/>                                                [\n]"
2016-04-14 16:49:26,138,Type=DEBUG,Category=org.apache.http.wire,Thread=main,MDC=,Text=http-outgoing-2 << "<br/>                                                [\n]"
2016-04-14 16:49:26,138,Type=DEBUG,Category=org.apache.http.wire,Thread=main,MDC=,Text=http-outgoing-2 << "<br/>                                                [\n]"
2016-04-14 16:49:26,138,Type=DEBUG,Category=org.apache.http.wire,Thread=main,MDC=,Text=http-outgoing-2 << "<br/>                                                [\n]"
2016-04-14 16:49:26,138,Type=DEBUG,Category=org.apache.http.wire,Thread=main,MDC=,Text=http-outgoing-2 << "<br/>                                                [\n]"
2016-04-14 16:49:26,138,Type=DEBUG,Category=org.apache.http.wire,Thread=main,MDC=,Text=http-outgoing-2 << "<br/>                                                [\n]"
2016-04-14 16:49:26,138,Type=DEBUG,Category=org.apache.http.wire,Thread=main,MDC=,Text=http-outgoing-2 << "<br/>                                                [\n]"
2016-04-14 16:49:26,138,Type=DEBUG,Category=org.apache.http.wire,Thread=main,MDC=,Text=http-outgoing-2 << "<br/>                                                [\n]"
2016-04-14 16:49:26,138,Type=DEBUG,Category=org.apache.http.wire,Thread=main,MDC=,Text=http-outgoing-2 << "[\n]"
2016-04-14 16:49:26,138,Type=DEBUG,Category=org.apache.http.wire,Thread=main,MDC=,Text=http-outgoing-2 << "</body>[\n]"
2016-04-14 16:49:26,138,Type=DEBUG,Category=org.apache.http.wire,Thread=main,MDC=,Text=http-outgoing-2 << "</html>[\n]"
2016-04-14 16:49:26,138,Type=DEBUG,Category=org.apache.http.impl.conn.PoolingHttpClientConnectionManager,Thread=main,MDC=,Text=Connection [id: 2][route: {}->http://localhost:5082] can be kept alive indefinitely
2016-04-14 16:49:26,138,Type=DEBUG,Category=org.apache.http.impl.conn.PoolingHttpClientConnectionManager,Thread=main,MDC=,Text=Connection released: [id: 2][route: {}->http://localhost:5082][total kept alive: 1; route allocated: 1 of 5; total allocated: 1 of 10]

PrachiT

unread,
Apr 18, 2016, 1:03:35 PM4/18/16
to wiremock-user
Anyone?
Reply all
Reply to author
Forward
0 new messages