Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot make the mockserver proxy works #1811

Open
fabytta opened this issue Oct 25, 2023 · 3 comments
Open

Cannot make the mockserver proxy works #1811

fabytta opened this issue Oct 25, 2023 · 3 comments

Comments

@fabytta
Copy link

fabytta commented Oct 25, 2023

Describe the issue
I'm using the docker compose to run mockerserver as proxy (in order to generate the recorded exchanges as expectations later)
However It's not working
here is my docker-compose :
"version: "1.0"
services:
mockServer:
image: mockserver/mockserver:java11
command: -logLevel DEBUG -serverPort 1080 -proxyRemotePort 1070
ports:
- 1080:1080
- 1070:1070
environment:
MOCKSERVER_WATCH_INITIALIZATION_JSON: "true"
MOCKSERVER_INITIALIZATION_JSON_PATH: /config/initializerJson.json
MOCKSERVER_ATTEMPT_TO_PROXY_IF_NO_MATCHING_EXPECTATION: "true"
volumes:
- type: bind
source: .
target: /config

"
What you are trying to do
I'm using the docker compose to run mockerserver as proxy (in order to generate the recorded exchanges as expectations later

MockServer version
5.15.0

To Reproduce

  1. run the docker-compose file
    the mockserver is up on the port 1080, and I can check the dashboard, the exectations provided in the initialization mechanism are indded present and can check that they return the desired response with postman (mackserver as mock is working as expected)

  2. now when I configure the proxy 127.0.0.1:1070 in my postman and try to to send some request to an external service, I got :
    Error: tunneling socket could not be established, cause=socket hang up in the console of postman, the proxy is not working
    when I try rather the config proxy 127.0.0.1:1080, I got Error: tunneling socket could not be established, statusCode=502
    MockServer Log
    in a use the port 1070 as proxy port, nothing logged, when I use 1080 as proxy port in my postman config I get
    " 2023-10-25 06:53:06 5.15.0 SEVERE 1080 Connection failed to localhost/127.0.0.1:1070
    server-mockServer-1 | io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection refused: localhost/127.0.0.1:1070
    server-mockServer-1 | Caused by: java.net.ConnectException: Connection refused
    server-mockServer-1 | at java.base/sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
    server-mockServer-1 | at java.base/sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:777)
    server-mockServer-1 | at io.netty.channel.socket.nio.NioSocketChannel.doFinishConnect(NioSocketChannel.java:337)
    server-mockServer-1 | at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:334)
    server-mockServer-1 | at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:776)
    server-mockServer-1 | at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:724)
    server-mockServer-1 | at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:650)
    server-mockServer-1 | at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:562)
    server-mockServer-1 | at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997)
    server-mockServer-1 | at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
    server-mockServer-1 | at java.base/java.lang.Thread.run(Thread.java:829)"

@damoncoo
Copy link

From my understanding, mockserver serves as mocking and proxying on the same port, they should be 1080 in your case.

@damoncoo
Copy link

damoncoo commented Feb 28, 2024

I am using 5.14.0, it works with proxy and mock. For the latest version, it does NOT, hope can be fixed in new release

@stukalin
Copy link

stukalin commented Mar 5, 2024

Hi all! If you don't mind I'll post my question here because i have almost the same issue as the topic starter. Long story short i want to do pretty much the same, i.e. just run the MockServer, watch requests which have been made and then create some expectations. In other words i just want to run it as my traffic sniffer like Fiddler or Postman Proxy kinda thing. I've added the certificate to the trusted root CA, i've started it with the default configuration (i even tried to explicitly set the mockserver.attemptToProxyIfNoMatchingExpectation=true) and pointed the proxy setting like this (yes, it's Windows)
image

but it simply doesn't work, it blocks all the traffic and in the console i have multiple

org.mockserver.httpclient.SocketConnectionException: Channel handler removed before valid response has been received
        at io.netty.channel.DefaultChannelPipeline.fireChannelUnregistered(DefaultChannelPipeline.java:821)
        at io.netty.channel.AbstractChannel$AbstractUnsafe$7.run(AbstractChannel.java:821)
        at io.netty.util.concurrent.AbstractEventExecutor.runTask(AbstractEventExecutor.java:174)
        at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:167)
        at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:470)
        at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:566)
        at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997)
        at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
        ... 1 more
        at org.mockserver.httpclient.HttpClientConnectionErrorHandler.handlerRemoved(HttpClientConnectionErrorHandler.java:21)
        at io.netty.channel.AbstractChannelHandlerContext.callHandlerRemoved(AbstractChannelHandlerContext.java:1122)
        at io.netty.channel.DefaultChannelPipeline.callHandlerRemoved0(DefaultChannelPipeline.java:637)
        at io.netty.channel.DefaultChannelPipeline.destroyDown(DefaultChannelPipeline.java:876)
        at io.netty.channel.DefaultChannelPipeline.destroyUp(DefaultChannelPipeline.java:844)
        at io.netty.channel.DefaultChannelPipeline.destroy(DefaultChannelPipeline.java:836)
        at io.netty.channel.DefaultChannelPipeline.access$700(DefaultChannelPipeline.java:46)
        at io.netty.channel.DefaultChannelPipeline$HeadContext.channelUnregistered(DefaultChannelPipeline.java:1392)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelUnregistered(AbstractChannelHandlerContext.java:215)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelUnregistered(AbstractChannelHandlerContext.java:195)
        at io.netty.channel.DefaultChannelPipeline.fireChannelUnregistered(DefaultChannelPipeline.java:821)
        at io.netty.channel.AbstractChannel$AbstractUnsafe$7.run(AbstractChannel.java:821)
        at io.netty.util.concurrent.AbstractEventExecutor.runTask(AbstractEventExecutor.java:174)
        at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:167)
        at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:470)
        at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:566)
        at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997)
        at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
        at java.base/java.lang.Thread.run(Thread.java:833)

Am i getting it all wrong and the tool cannot be used this way?

PS.
I am using the 5.15.0 as well

UPDATE:
I've tried 5.14.0 and it works a bit better: now at least i now see some of my requests in the logs and it tells me another error now:

INFO 1080 exception decoding client certificate 
java.lang.IllegalStateException: javax.security.cert.CertificateException: Could not find class: java.lang.ClassNotFoundException: com/sun/security/cert/internal/x509/X509V1CertImpl
   at io.netty.handler.ssl.util.LazyJavaxX509Certificate.unwrap(LazyJavaxX509Certificate.java:142)
   at io.netty.handler.ssl.util.LazyJavaxX509Certificate.getSerialNumber(LazyJavaxX509Certificate.java:61)
   at org.mockserver.mappers.JDKCertificateToMockServerX509Certificate.lambda$setClientCertificates$0(JDKCertificateToMockServerX509Certificate.java:34)
   at java.base/java.util.stream.ReferencePipeline$7$1.accept(ReferencePipeline.java:273)
   at java.base/java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:992)
   at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
   at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
   at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921)
   at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
   at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682)
   at org.mockserver.mappers.JDKCertificateToMockServerX509Certificate.setClientCertificates(JDKCertificateToMockServerX509Certificate.java:54)
   at org.mockserver.mappers.FullHttpRequestToMockServerHttpRequest.mapFullHttpRequestToMockServerRequest(FullHttpRequestToMockServerHttpRequest.java:73)
   at org.mockserver.codec.NettyHttpToMockServerHttpRequestDecoder.decode(NettyHttpToMockServerHttpRequestDecoder.java:36)
   at org.mockserver.codec.NettyHttpToMockServerHttpRequestDecoder.decode(NettyHttpToMockServerHttpRequestDecoder.java:18)
   at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:88)
   at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:251)
   at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
   at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
   at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
   at org.mockserver.dashboard.DashboardWebSocketHandler.channelRead(DashboardWebSocketHandler.java:137)
   at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
   at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
   at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
   at org.mockserver.netty.websocketregistry.CallbackWebSocketServerHandler.channelRead(CallbackWebSocketServerHandler.java:57)
   at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
   at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
   at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
   at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103)
   at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
   at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
   at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
   at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103)
   at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
   at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
   at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
   at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103)
   at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
   at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
   at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
   at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelRead(CombinedChannelDuplexHandler.java:436)
   at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:327)
   at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:299)
   at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:251)
   at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
   at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
   at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
   at org.mockserver.netty.unification.PortUnificationHandler.switchToHttp(PortUnificationHandler.java:279)
   at org.mockserver.netty.unification.PortUnificationHandler.decode(PortUnificationHandler.java:153)
   at io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:510)
   at io.netty.handler.codec.ReplayingDecoder.callDecode(ReplayingDecoder.java:366)
   at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:279)
   at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
   at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
   at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
   at io.netty.handler.ssl.SslHandler.unwrap(SslHandler.java:1373)
   at io.netty.handler.ssl.SslHandler.decodeJdkCompatible(SslHandler.java:1236)
   at io.netty.handler.ssl.SslHandler.decode(SslHandler.java:1285)
   at io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:510)
   at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:449)
   at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:279)
   at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
   at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
   at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
   at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)
   at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
   at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
   at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)
   at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:166)
   at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:722)
   at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:658)
   at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:584)
   at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:496)
   at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997)
   at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
   at java.base/java.lang.Thread.run(Thread.java:833)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants