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

swaggerProxy cannot be path-prefixed and swaggerRewriter cannot be used as a stand-in replacement #348

Closed
meyergru opened this issue Jan 21, 2020 · 3 comments

Comments

@meyergru
Copy link

meyergru commented Jan 21, 2020

I tried using the petstore swagger example from the examples:

        <swaggerProxy url="http://petstore.swagger.io/v2/swagger.json">
        </swaggerProxy>

That itself works fine - although the services themselves are not accessible, either (like http://localhost:8080/ works while http://localhost:8080/v2/pet/8 does not).

However, my intent is to user Membrane as a service hub within Tomcat.
Therefore, I need to differentiate services by URL prefix, not by TCP port, which I usually do like this:

        <serviceProxy name="Google">
            <path>/google</path>
            <rewriter>
                <map from="^/google/(.*)" to="/$1" />
            </rewriter>
            <target host="www.google.com" port="443"><ssl/></target>
        </serviceProxy>

I have found no way to use swaggerProxy like soapProxy with different paths pointing to several backend services like this:

        <soapProxy wsdl="http://www.thomas-bayer.com/axis2/services/BLZService?wsdl">
            <path>/blz</path>
            <soapStackTraceFilter />
            <validator />
        </soapProxy>

        <soapProxy wsdl="http://www.thomas-bayer.com/axis2/services/CSV2XMLService?wsdl">
            <path>/csv</path>
            <soapStackTraceFilter />
            <validator />
        </soapProxy>

It seems that swaggerProxy itself does not support a path element.

When I try to use an equivalent serviceProxy with swaggerRewriter instead, it does not work either way:

        <serviceProxy>
            <swaggerRewriter/>
            <target host="petstore.swagger.io" port="80" />
        </serviceProxy>

Gives an exception saying: "com.predic8.membrane.core.resolver.ResourceRetrievalException: null while retrieving swagger.json".

        <serviceProxy>
            <swaggerRewriter swaggerJson="/v2/swagger.json"/>
            <target host="petstore.swagger.io" port="80" />
        </serviceProxy>

Same result. Interesting question: How should swaggerRewriter know which URL to prefix to swaggerJson in order to fetch it? The default of "swagger.json" does not suffice. So I probably need to give a full URL:

        <serviceProxy>
            <swaggerRewriter swaggerJson="http://petstore.swagger.io/v2/swagger.json"/>
            <target host="petstore.swagger.io" port="80" />
        </serviceProxy>

and indeed, that works.

But when I try to combine that with path, it goes horribly wrong, neither:

        <serviceProxy>
	    <path>/petstore</path>
            <swaggerRewriter swaggerJson="http://petstore.swagger.io/v2/swagger.json"/>
            <target host="petstore.swagger.io" port="80" />
        </serviceProxy>

nor

        <serviceProxy>
	    <path>/petstore</path>
            <rewriter>
                <map from="^/petstore/(.*)" to="/$1" />
            </rewriter>
            <swaggerRewriter swaggerJson="http://petstore.swagger.io/v2/swagger.json"/>
            <target host="petstore.swagger.io" port="80" />
        </serviceProxy>

nor the other way around:

        <serviceProxy>
	    <path>/petstore</path>
            <swaggerRewriter swaggerJson="http://petstore.swagger.io/v2/swagger.json"/>
            <rewriter>
                <map from="^/petstore/(.*)" to="/$1" />
            </rewriter>
            <target host="petstore.swagger.io" port="80" />
        </serviceProxy>

work.

But maybe I am doing it wrong?

@symle
Copy link
Contributor

symle commented Aug 13, 2020

Yes there is a bug, in SwaggerProxyKey. It work as

<serviceProxy`` port="8000"> <swaggerRewriter swaggerJson="https://petstore.swagger.io/v2/swagger.json" /> <target host="petstore.swagger.io" port="443" /> </serviceProxy>
For swaggerProxy, I will write the patch

@symle
Copy link
Contributor

symle commented Aug 13, 2020

methodMatch(String method, PathItem path){...

path.getXXX all http methots get always null, the problem occurs because of this.

symle pushed a commit to symle/service-proxy that referenced this issue Aug 14, 2020
@symle
Copy link
Contributor

symle commented Aug 14, 2020

Bug resolved

@rrayst rrayst closed this as completed in 5a1879c Aug 15, 2020
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

2 participants