【问题标题】:Wiremock - Record/Playback via forward proxyWiremock - 通过转发代理记录/播放
【发布时间】:2019-02-06 13:15:05
【问题描述】:

我正在尝试使用 wiremock(目前是独立的)来记录/播放对外部 SaaS 系统发出的所有请求。但是,我正在尝试通过需要代理所有请求的公司网络。

真正的要求是:

curl -v -k --proxy "mycompany.proxy:81111" "https://api.thirdparty.com/api/v1/soap?wsdl"

返回结果

从 Wiremock 文档中,我尝试了以下配置:

java -jar wiremock-standalone-2.21.0.jar --https-port 443 --record-mappings --proxy-all="https://api.thirdparty.com" --preserve-host-header --proxy-via="http://mycompany.proxy:81111" --verbose --print-all-network-traffic

但是,使用 Wiremock 时,我似乎无法得到相同的响应。

如果我尝试通过 HTTPS 访问 Wiremock...

curl -v -k "https://localhost:443/api/v1/soap?wsdl"

* timeout on name lookup is not supported
*   Trying 127.0.0.1...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                             Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--   0 
* Connected to localhost (127.0.0.1) port 443 (#0)
* ALPN, offering http/1.1
* Cipher selection: 
ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
* successfully set certificate verify locations:
*   CAfile: C:/path/to/gitbash/ssl/certs/ca-bundle.crt  CApath: none
* TLSv1.2 (OUT), TLS header, Certificate Status (22):
 } [5 bytes data]
 * TLSv1.2 (OUT), TLS handshake, Client hello (1):
 } [512 bytes data]
   0     0    0     0    0     0      0      0 --:--:--  0:00:30 --:--:--     
 0* Unknown SSL protocol error in connection to localhost:443
   0     0    0     0    0     0      0      0 --:--:--  0:00:30 --:--:--     0
 * Closing connection 0
 curl: (35) Unknown SSL protocol error in connection to localhost:443

在wiremock控制台上......

    2019-02-06 13:00:08.017 Problem decoding network traffic
java.nio.charset.MalformedInputException: Input length = 1
        at java.nio.charset.CoderResult.throwException(Unknown Source)
        at java.nio.charset.CharsetDecoder.decode(Unknown Source)
        at com.github.tomakehurst.wiremock.http.trafficlistener.ConsoleNotifyingWiremockNetworkTrafficListener.incoming(ConsoleNotifyingWiremockNetworkTrafficListener.java:40)
        at com.github.tomakehurst.wiremock.jetty9.JettyHttpServer$NetworkTrafficListenerAdapter.incoming(JettyHttpServer.java:435)
        at wiremock.org.eclipse.jetty.io.NetworkTrafficSelectChannelEndPoint.notifyIncoming(NetworkTrafficSelectChannelEndPoint.java:125)
        at wiremock.org.eclipse.jetty.io.NetworkTrafficSelectChannelEndPoint.fill(NetworkTrafficSelectChannelEndPoint.java:48)
        at wiremock.org.eclipse.jetty.io.ssl.SslConnection$DecryptedEndPoint.fill(SslConnection.java:516)
        at wiremock.org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:240)
        at wiremock.org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:544)
        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(Unknown Source)

如果,我尝试使用 http 访问wiremock...

$ curl -v -k "http://localhost:8080/api/v1/soap?wsdl"
* timeout on name lookup is not supported
*   Trying 127.0.0.1...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                             Dload  Upload   Total   Spent    Left  Speed
   0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0    * Connected to localhost (127.0.0.1) port 8080 (#0)
> GET /api/v1/soap?wsdl HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.46.0
> Accept: */*
>
< HTTP/1.1 404 Not Found
< Content-Type: text/plain
< Transfer-Encoding: chunked
< Server: Jetty(9.2.z-SNAPSHOT)
<
{ [95 bytes data]
 100    84    0    84    0     0   2709      0 --:--:-- --:--:-- --:--:--  5600
No response could be served as there are no stub mappings in this WireMock instance.
* Connection #0 to host localhost left intact

非常感谢任何帮助。

【问题讨论】:

    标签: wiremock


    【解决方案1】:

    根据Wiremock documentation,您可以通过代理(但不能通过 JSON)以编程方式设置目标 API。

    通过另一个代理服务器代理

    如果您所在的网络只允许 HTTP 流量传出到 通过不透明代理上网,您可能希望设置代理映射 该路由通过此服务器。这可以通过编程方式配置 将配置对象传递给 WireMockServer 的构造函数或 JUnit 规则如下:

    WireMockServer wireMockServer = new WireMockServer(options()
        .proxyVia("proxy.mycorp.com", 8080)
    );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-03
      • 2023-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多