首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Wiremock通过前向代理记录/回放

Wiremock通过前向代理记录/回放
EN

Stack Overflow用户
提问于 2019-02-06 13:15:05
回答 1查看 2.4K关注 0票数 1

我正在尝试使用wiremock (目前是独立的)来记录/回放所有向外部SaaS系统提出的请求。然而,我正在尝试通过一个公司网络,其中所有的请求都需要代理。

真正的要求是:

代码语言:javascript
运行
复制
curl -v -k --proxy "mycompany.proxy:81111" "https://api.thirdparty.com/api/v1/soap?wsdl"

返回一个结果。

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

代码语言:javascript
运行
复制
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 ..。

代码语言:javascript
运行
复制
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

在遥控器上..。

代码语言:javascript
运行
复制
    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.

代码语言:javascript
运行
复制
$ 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

任何帮助都很感激。

EN

回答 1

Stack Overflow用户

发布于 2019-06-13 12:21:51

根据Wiremock文件,您可以通过代理(但不是通过JSON)将程序设置为针对end。

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

代码语言:javascript
运行
复制
WireMockServer wireMockServer = new WireMockServer(options()
    .proxyVia("proxy.mycorp.com", 8080)
);
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54554527

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档