Hi Stuart -

At first glance, it seems to look okay.

I am wondering whether you are just running into the difficult dance of
what you need to do to get the service definitions changes updated.

I believe that you will find that you need to do the following when you
iterate over changes in rewrite rules:

1. Change rewrite rule and save
2. restart server
3. touch the topology that hosts the service that you changed the rewrite
for

#3 is the one that always burns me.
Keep in mind that webapps are generated by topologies and regenerated
whenever the topology is changed.

Even if the server is aware of the changes the previous webapp still is
deployed until the topology is changed.

HTH,

--larry


On Wed, Jan 17, 2018 at 12:25 PM, Hickinbottom, Stuart <
stuart.hickinbot...@cgi.com> wrote:

> Using Knox 0.11 and reproduced with Knox 0.14, we're having trouble
> getting basic URL rewriting to work. The real problem is with an
> ExpressJS application, and the URL is part of some JavaScript, but I
> wanted to get this basic example working first. Please may I ask for
> help to spot what I'm doing wrong? The HTML that goes to the browser
> is entirely unchanged from the HTML served by the back end
> application, while I'd expected the href URLs to be changed on the way
> out.
>
> How much parsing does the rules/rewrite filters attempt? How might a
> Webpack encoding affect this? (Although this isn't relevant to this
> simple HTML example.)
>
> Is there a way to turn up logging (already have
> log4j.logger.org.apache.hadoop.gateway=DEBUG) to see what rules and
> filters are being applied (or not)?
>
> example.html
>
> <html>
> <body>
> <a href="/api/v1/user">hello</a>
> <a href="/api/v1">hello</a>
> </body>
> </html>
>
> service.xml
>
> <service role="EXAMPLEUI" name="exampleui" version="0.0.1">
>     <policies>
>         <policy role="webappsec"/>
>         <policy role="authentication" name="Anonymous"/>
>         <policy role="rewrite"/>
>         <policy role="authorization"/>
>     </policies>
>     <routes>
>         <route path="/exampleui">
>             <rewrite apply="EXAMPLEUI/exampleui/inbound/root"
> to="request.url"/>
>             <rewrite apply="EXAMPLEUI/exampleui/outbound/html/filter"
> to="response.body"/>
>         </route>
>         <route path="/exampleui/**">
>             <rewrite apply="EXAMPLEUI/exampleui/inbound/path"
> to="request.url"/>
>             <rewrite apply="EXAMPLEUI/exampleui/outbound/html/filter"
> to="response.body"/>
>         </route>
>     </routes>
>     <dispatch classname="org.apache.hadoop.gateway.dispatch.
> PassAllHeadersDispatch"/>
> </service>
>
> rewrite.xml
>
> <rules>
>     <rule dir="IN" name="EXAMPLEUI/exampleui/inbound/root"
> pattern="*://*:*/**/exampleui/">
>         <rewrite template="{$serviceUrl[EXAMPLEUI]}/"/>
>     </rule>
>     <rule dir="IN" name="EXAMPLEUI/exampleui/inbound/path"
> pattern="*://*:*/**/exampleui/{**}">
>         <rewrite template="{$serviceUrl[EXAMPLEUI]}/{**}"/>
>     </rule>
>
>     <rule dir="OUT" name="EXAMPLEUI/exampleui/outbound/apipath">
>         <rewrite template="{$frontend[path]}/exampleui/api/v1"/>
>     </rule>
>     <filter name="EXAMPLEUI/exampleui/outbound/html/filter">
>         <content type="text/html">
>             <apply path="/api/v1" rule="EXAMPLEUI/exampleui/
> outbound/apipath"/>
>         </content>
>     </filter>
>
> </rules>
>
>
>
> ==> /var/log/hadoop/knox/gateway.log <==
> 2018-01-17 16:54:46,934 DEBUG hadoop.gateway 
> (DefaultDispatch.java:executeOutboundRequest(133))
> - Dispatch response status: 200
> 2018-01-17 16:54:46,935 DEBUG hadoop.gateway (DefaultDispatch.java:
> getInboundResponseContentType(202)) - Using explicit character set UTF-8
> for entity of type text/html
> 2018-01-17 16:54:46,935 DEBUG hadoop.gateway (DefaultDispatch.java:
> getInboundResponseContentType(210)) - Inbound response entity content
> type: text/html; charset=UTF-8
>
> ==> /var/log/hadoop/knox/gateway-audit.log <==
> 18/01/17 16:54:46 ||47193300-cc6c-48e6-aad0-e2b04f2db613|audit|EXAMPLEUI||
> ||dispatch|uri|http://server.project:4201/example.html|success|Response
> status: 200
>
> ==> /var/log/hadoop/knox/gateway.log <==
>
> ==> /var/log/hadoop/knox/gateway-audit.log <==
> 18/01/17 16:54:46 ||47193300-cc6c-48e6-aad0-e2b04f2db613|audit|EXAMPLEUI||
> ||access|uri|/gateway/project/exampleui/example.html|success|Response
> status: 200
>
>
>
> Many thanks for any pointers.
>
> We've read through:
>
> https://github.com/apache/knox/blob/master/gateway-
> service-definitions/src/main/resources/services/ambariui/2.2.0/rewrite.xml
> https://cwiki.apache.org/confluence/display/KNOX/Proxying+a+UI+using+Knox
> https://cwiki.apache.org/confluence/display/KNOX/2017/
> 08/14/Understanding+Rewrite+Rules+for+Apache+Knox#
> UnderstandingRewriteRulesforApacheKnox-JavaScriptURLRewriteFilter
>
> Regards,
> Stuart
>
>

Reply via email to