cjstehno / ersatz

🤖 A simulated HTTP server for testing client code with configurable responses.
https://cjstehno.github.io/ersatz
Apache License 2.0
47 stars 5 forks source link

binary compatibility with Undertow 1.3.x #56

Closed musketyr closed 6 years ago

musketyr commented 7 years ago

If not really necessary it would be nice if Ersatz server is compatible with Undertow 1.3.x (namely 1.3.15.Final) which is used by various spring boot related libraries (https://mvnrepository.com/artifact/io.undertow/undertow-core/1.3.25.Final/usages). This disqualifies from using Ersatz with Spring Boot or Grails 3. The construct offending the compatibility is currently server.listenerInfo:

            actualHttpPort = (server.listenerInfo[0].address as InetSocketAddress).port

            if (httpsEnabled) {
                actualHttpsPort = (server.listenerInfo[1].address as InetSocketAddress).port
            }
cjstehno commented 7 years ago

See the pull request comment, but I think I should be able to just use the latest version of 1.3 with some minor changes... I just went for "most current" when I picked one. :-)

cjstehno commented 7 years ago

Ok, I did a little testing and it seems that I can use 1.3.15 (and will try to track with boot/grails going forward). All I had to do was pull out the port updating into a non-static-compiled method and do some groovy digging :-)

@CompileStatic(SKIP)
private void applyPorts() {
    actualHttpPort = server.channels[0].channel.localAddress.holder.port

    if (httpsEnabled) {
        actualHttpsPort = server.channels[1].tcpServer.channel.localAddress.holder.port
    }
}

If just using 1.3.15 will solve the problem you ran into I will just use this version (and the code above) going forward. Thanks for your help. If this doesn't do it, let me know what I missed.

I guess I need to add a contributors page now.

musketyr commented 7 years ago

I'm happy with this solution as well :-) just wonder why do go through tcpServer for HTTPS and not for HTTP? (I don't know the internals of Undertow or XNIO it just looks weird to me 😄 ).

No need for contributors page yet, wait for real contribution 😄 But new release including this fix would be great 🍾

cjstehno commented 7 years ago

Ok, try v1.2.1 which was just released. It's available on bintray but might take a bit longer to become available on maven central. Let me know if this takes care of the issue and I will close it out. Thanks.

musketyr commented 7 years ago

works great! thank you!

musketyr commented 6 years ago

The compatibility seems to be broken again in 1.5.0. With 1.3.0 it was ok.

java.lang.NoSuchMethodError: io.undertow.Undertow.getListenerInfo()Ljava/util/List;

    at com.stehno.ersatz.ErsatzServer.applyPorts(ErsatzServer.groovy:498)
    at com.stehno.ersatz.ErsatzServer.start(ErsatzServer.groovy:399)
    at com.stehno.ersatz.ErsatzServer.expectations(ErsatzServer.groovy:245)
cjstehno commented 6 years ago

Yes. Now in order to work in a scenario like that you need to use the safe (shadowed) jar (see Shadow Jar section in User Guide). I didn't want to hold back the internal version of Undertow since realistically two versions of Boot or Grails could both use a different version of Undertow - it and its internal-required libraries are all bundled with the shadow jar. The down side is that you no longer get the other transitive dependencies, such as Hamcrest.

This is somewhat experimental, but I have tested it to work on it's own. If you find any issues, feel free to register them and I will jump right on it.

I will leave this issue open for now - please respond or close it if the safe distribution works for you.

musketyr commented 6 years ago

works well. maybe it is worth to mention this directly in README file.

cjstehno commented 6 years ago

Thanks. Agreed! I will add it to the README. I am also planning on being a bit more rigorous with my release notes going forward. Hindsight, I should have asked you to test this before releasing it since you are the only know use case. ;-) Glad it works for you.