You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@knox.apache.org by Kevin Minder <ke...@hortonworks.com> on 2016/01/26 15:45:45 UTC

Re: KNOX

Lets start with the service.xml file.  It should probably look like the much simpler version below.  You would only need the more complex forms if you need to apply specific rules to specific parts of requests or responses.  Note that ideally only one route would be required but the `**` in Knox means one or more path levels (not zero or more).  So without the first route Knox wouldn't send requests to the root /Test_Web_App path to the service.

    <service role="TEST_WEB_APP" name="Test_Web_App" version="0.0.1">
        <routes>
            <route path="/Test_Web_App/?**">
            <route path="/Test_Web_App/**?**">
        </routes>
    </service>

If you wanted to be very specific about it this would be the equivalent.  Here the `<rewrite apply="">` identifies a specific named rule in rewrite.xml and `<rewrite to="">` identifies what part of the request and or response the rule should be applied to.

    <service role="TEST_WEB_APP" name="Test_Web_App" version="0.0.1">
        <routes>
            <route path="/Test_Web_App/?**">
              <rewrite apply="TEST_WEB_APP/Test_Web_App/" to="request.url"/>
            </route>
            <route path="/Test_Web_App/**?**">
              <rewrite apply="TEST_WEB_APP/Test_Web_App/query" to="request.url"/>
            </route>
        </routes>
    </service>

Now for the rewrite.xml.  Yours was pretty close.  All I added was a name (i.e. path) resulting in `{path=**}` to both the pattern and template of the second rule.  In the `<rule pattern="">` this is used to give a name to the values that are extracted from the matched pattern.  In `<rewrite template="">` the name is used to populate part of the url being created with named values extracted from the matched pattern.

    <rules>
        <rule dir="IN" name="TEST_WEB_APP/Test_Web_App" pattern="*://*:*/**/Test_Web_App/?{**}">
            <rewrite template="{$serviceUrl[TEST_WEB_APP]}/?{**}"/>
        </rule>

        <rule dir="IN" name="TEST_WEB_APP/Test_Web_App/query" pattern="*://*:*/**/Test_Web_App/{path=**}?{**}">
            <rewrite template="{$serviceUrl[TEST_WEB_APP]/{path=**}?{**}"/>
        </rule>
    </rules>

From: Brijan Elwadhi <br...@RESILINC.COM>>
Date: Tuesday, January 26, 2016 at 1:36 AM
To: Kevin Minder <ke...@hortonworks.com>>
Subject: KNOX

Hi Kevin,

After going through your mail and  blog I came to know that we do not  need to implement contributor if we are using knox 0.6.0 or above, I have
followed the steps and I have added rewrite.xml service.xml in GATEWAY_HOME/data/services/Test_Web_App/0.0.1


rewrite.xml:

<rules>

            <rule dir="IN" name="TEST_WEB_APP/Test_Web_App" pattern="*://*:*/**/Test_Web_App/?{**}">
                <rewrite template="{$serviceUrl[TEST_WEB_APP]}/?{**}"/>
            </rule>

            <rule dir="IN" name="TEST_WEB_APP/Test_Web_App/query" pattern="*://*:*/**/Test_Web_App/{**}?{**}">
                <rewrite template="{$serviceUrl[TEST_WEB_APP]/{**}?{**}"/>
            </rule>
</rules>

Service.xml:

<service role="TEST_WEB_APP" name="Test_Web_App" version="0.0.1">
    <routes>
        <route path="/Test_Web_App/**">
            <rewrite apply="TEST_WEB_APP/Test_Web_App/**" to="response.body" />
        </route>
        <route path="/Test_Web_App/**?**">
           <rewrite apply="TEST_WEB_APP/Test_Web_App/**?**" to="response.body"/>
    </routes>
</service>

and this is what I have added in sandbox.xml (topology )
<service>
        <role>TEST_WEB_APP</role>
        <url>http://localhost:8087</url>
</service>
But it is not working. Can you please tell me what else I need to do? Or if I am making any mistake

Thanks & Regards,
Brijan Elwadhi
Software Engineer
M: +91-7587130309
[cid:image001.jpg@01D01AD9.A3CE5C20]<http://www.resilinc.com/>
[facebook]<https://www.facebook.com/pages/Resilinc/152374944798272>  [twitter] <http://www.twitter.com/resilinc>   [linkedin] <http://www.linkedin.com/company/resilinc-corporation>   [youtube] <https://www.youtube.com/channel/UCbo4dHglF3tdc-h7Db8YaGw>

[cid:A961F978-0020-464D-A5C1-1AD0E6195E54]<https://www.eventbrite.com/e/2016-global-supply-chain-resiliency-council-conference-awards-registration-18740042973>


RE: KNOX

Posted by Brijan Elwadhi <br...@RESILINC.COM>.
Hey Kevin,

Thank  you for your help now I am able to relate rules with route  and now when I update service or rewrite xmls I am able see changes in gateway.xml file but I have some concerns now

1.        you said ** is for one or more occurrence but in your blog(http://kminder.github.io/knox/2015/11/16/adding-a-service-to-knox.html) you said that ** matches zero or more segments of the URl. So I am bit confused.

2.        If I have 2 URL pattern(end points) in my service  like Test_Web_App/xyz and Test_Web_App/abc    then I need to define 2 different rules and routes.
Kevin ,Is there  any way of  faster communication ?


Thanks & Regards,
Brijan Elwadhi
Software Engineer
M: +91-7587130309
[cid:image001.jpg@01D01AD9.A3CE5C20]<http://www.resilinc.com/>
[facebook]<https://www.facebook.com/pages/Resilinc/152374944798272>  [twitter] <http://www.twitter.com/resilinc>   [linkedin] <http://www.linkedin.com/company/resilinc-corporation>   [youtube] <https://www.youtube.com/channel/UCbo4dHglF3tdc-h7Db8YaGw>

[cid:A961F978-0020-464D-A5C1-1AD0E6195E54]<https://www.eventbrite.com/e/2016-global-supply-chain-resiliency-council-conference-awards-registration-18740042973>

From: Kevin Minder [mailto:kevin.minder@hortonworks.com]
Sent: Tuesday, January 26, 2016 8:24 PM
To: dev@knox.apache.org; Brijan Elwadhi
Subject: Re: KNOX

Minor error.  This should have the trailing slash removed because "TEST_WEB_APP/Test_Web_App/“ is not the name of a rule in rewrite.xml.  So this:
              <rewrite apply="TEST_WEB_APP/Test_Web_App/" to="request.url"/>
Should be this:
              <rewrite apply="TEST_WEB_APP/Test_Web_App" to="request.url"/>


From: Kevin Minder <ke...@hortonworks.com>>
Reply-To: "dev@knox.apache.org<ma...@knox.apache.org>" <de...@knox.apache.org>>
Date: Tuesday, January 26, 2016 at 9:45 AM
To: Brijan Elwadhi <br...@RESILINC.COM>>
Cc: "dev@knox.apache.org<ma...@knox.apache.org>" <de...@knox.apache.org>>
Subject: Re: KNOX

Lets start with the service.xml file.  It should probably look like the much simpler version below.  You would only need the more complex forms if you need to apply specific rules to specific parts of requests or responses.  Note that ideally only one route would be required but the `**` in Knox means one or more path levels (not zero or more).  So without the first route Knox wouldn't send requests to the root /Test_Web_App path to the service.

    <service role="TEST_WEB_APP" name="Test_Web_App" version="0.0.1">
        <routes>
            <route path="/Test_Web_App/?**">
            <route path="/Test_Web_App/**?**">
        </routes>
    </service>

If you wanted to be very specific about it this would be the equivalent.  Here the `<rewrite apply="">` identifies a specific named rule in rewrite.xml and `<rewrite to="">` identifies what part of the request and or response the rule should be applied to.

    <service role="TEST_WEB_APP" name="Test_Web_App" version="0.0.1">
        <routes>
            <route path="/Test_Web_App/?**">
              <rewrite apply="TEST_WEB_APP/Test_Web_App/" to="request.url"/>
            </route>
            <route path="/Test_Web_App/**?**">
              <rewrite apply="TEST_WEB_APP/Test_Web_App/query" to="request.url"/>
            </route>
        </routes>
    </service>

Now for the rewrite.xml.  Yours was pretty close.  All I added was a name (i.e. path) resulting in `{path=**}` to both the pattern and template of the second rule.  In the `<rule pattern="">` this is used to give a name to the values that are extracted from the matched pattern.  In `<rewrite template="">` the name is used to populate part of the url being created with named values extracted from the matched pattern.

    <rules>
        <rule dir="IN" name="TEST_WEB_APP/Test_Web_App" pattern="*://*:*/**/Test_Web_App/?{**}">
            <rewrite template="{$serviceUrl[TEST_WEB_APP]}/?{**}"/>
        </rule>

        <rule dir="IN" name="TEST_WEB_APP/Test_Web_App/query" pattern="*://*:*/**/Test_Web_App/{path=**}?{**}">
            <rewrite template="{$serviceUrl[TEST_WEB_APP]/{path=**}?{**}"/>
        </rule>
    </rules>

From: Brijan Elwadhi <br...@RESILINC.COM>>
Date: Tuesday, January 26, 2016 at 1:36 AM
To: Kevin Minder <ke...@hortonworks.com>>
Subject: KNOX

Hi Kevin,

After going through your mail and  blog I came to know that we do not  need to implement contributor if we are using knox 0.6.0 or above, I have
followed the steps and I have added rewrite.xml service.xml in GATEWAY_HOME/data/services/Test_Web_App/0.0.1



rewrite.xml:


<rules>

            <rule dir="IN" name="TEST_WEB_APP/Test_Web_App" pattern="*://*:*/**/Test_Web_App/?{**}">
                <rewrite template="{$serviceUrl[TEST_WEB_APP]}/?{**}"/>
            </rule>

            <rule dir="IN" name="TEST_WEB_APP/Test_Web_App/query" pattern="*://*:*/**/Test_Web_App/{**}?{**}">
                <rewrite template="{$serviceUrl[TEST_WEB_APP]/{**}?{**}"/>
            </rule>
</rules>

Service.xml:

<service role="TEST_WEB_APP" name="Test_Web_App" version="0.0.1">
    <routes>
        <route path="/Test_Web_App/**">
            <rewrite apply="TEST_WEB_APP/Test_Web_App/**" to="response.body" />
        </route>
        <route path="/Test_Web_App/**?**">
           <rewrite apply="TEST_WEB_APP/Test_Web_App/**?**" to="response.body"/>
    </routes>
</service>

and this is what I have added in sandbox.xml (topology )
<service>
        <role>TEST_WEB_APP</role>
        <url>http://localhost:8087</url><http://localhost:8087%3c/url%3e>
</service>
But it is not working. Can you please tell me what else I need to do? Or if I am making any mistake

Thanks & Regards,
Brijan Elwadhi
Software Engineer
M: +91-7587130309
[cid:image001.jpg@01D01AD9.A3CE5C20]<http://www.resilinc.com/>
[facebook]<https://www.facebook.com/pages/Resilinc/152374944798272>  [twitter] <http://www.twitter.com/resilinc>   [linkedin] <http://www.linkedin.com/company/resilinc-corporation>   [youtube] <https://www.youtube.com/channel/UCbo4dHglF3tdc-h7Db8YaGw>

[cid:A961F978-0020-464D-A5C1-1AD0E6195E54]<https://www.eventbrite.com/e/2016-global-supply-chain-resiliency-council-conference-awards-registration-18740042973>


Re: KNOX

Posted by Kevin Minder <ke...@hortonworks.com>.
Minor error.  This should have the trailing slash removed because "TEST_WEB_APP/Test_Web_App/“ is not the name of a rule in rewrite.xml.  So this:
              <rewrite apply="TEST_WEB_APP/Test_Web_App/" to="request.url"/>
Should be this:
              <rewrite apply="TEST_WEB_APP/Test_Web_App" to="request.url"/>


From: Kevin Minder <ke...@hortonworks.com>>
Reply-To: "dev@knox.apache.org<ma...@knox.apache.org>" <de...@knox.apache.org>>
Date: Tuesday, January 26, 2016 at 9:45 AM
To: Brijan Elwadhi <br...@RESILINC.COM>>
Cc: "dev@knox.apache.org<ma...@knox.apache.org>" <de...@knox.apache.org>>
Subject: Re: KNOX

Lets start with the service.xml file.  It should probably look like the much simpler version below.  You would only need the more complex forms if you need to apply specific rules to specific parts of requests or responses.  Note that ideally only one route would be required but the `**` in Knox means one or more path levels (not zero or more).  So without the first route Knox wouldn't send requests to the root /Test_Web_App path to the service.

    <service role="TEST_WEB_APP" name="Test_Web_App" version="0.0.1">
        <routes>
            <route path="/Test_Web_App/?**">
            <route path="/Test_Web_App/**?**">
        </routes>
    </service>

If you wanted to be very specific about it this would be the equivalent.  Here the `<rewrite apply="">` identifies a specific named rule in rewrite.xml and `<rewrite to="">` identifies what part of the request and or response the rule should be applied to.

    <service role="TEST_WEB_APP" name="Test_Web_App" version="0.0.1">
        <routes>
            <route path="/Test_Web_App/?**">
              <rewrite apply="TEST_WEB_APP/Test_Web_App/" to="request.url"/>
            </route>
            <route path="/Test_Web_App/**?**">
              <rewrite apply="TEST_WEB_APP/Test_Web_App/query" to="request.url"/>
            </route>
        </routes>
    </service>

Now for the rewrite.xml.  Yours was pretty close.  All I added was a name (i.e. path) resulting in `{path=**}` to both the pattern and template of the second rule.  In the `<rule pattern="">` this is used to give a name to the values that are extracted from the matched pattern.  In `<rewrite template="">` the name is used to populate part of the url being created with named values extracted from the matched pattern.

    <rules>
        <rule dir="IN" name="TEST_WEB_APP/Test_Web_App" pattern="*://*:*/**/Test_Web_App/?{**}">
            <rewrite template="{$serviceUrl[TEST_WEB_APP]}/?{**}"/>
        </rule>

        <rule dir="IN" name="TEST_WEB_APP/Test_Web_App/query" pattern="*://*:*/**/Test_Web_App/{path=**}?{**}">
            <rewrite template="{$serviceUrl[TEST_WEB_APP]/{path=**}?{**}"/>
        </rule>
    </rules>

From: Brijan Elwadhi <br...@RESILINC.COM>>
Date: Tuesday, January 26, 2016 at 1:36 AM
To: Kevin Minder <ke...@hortonworks.com>>
Subject: KNOX

Hi Kevin,

After going through your mail and  blog I came to know that we do not  need to implement contributor if we are using knox 0.6.0 or above, I have
followed the steps and I have added rewrite.xml service.xml in GATEWAY_HOME/data/services/Test_Web_App/0.0.1


rewrite.xml:

<rules>

            <rule dir="IN" name="TEST_WEB_APP/Test_Web_App" pattern="*://*:*/**/Test_Web_App/?{**}">
                <rewrite template="{$serviceUrl[TEST_WEB_APP]}/?{**}"/>
            </rule>

            <rule dir="IN" name="TEST_WEB_APP/Test_Web_App/query" pattern="*://*:*/**/Test_Web_App/{**}?{**}">
                <rewrite template="{$serviceUrl[TEST_WEB_APP]/{**}?{**}"/>
            </rule>
</rules>

Service.xml:

<service role="TEST_WEB_APP" name="Test_Web_App" version="0.0.1">
    <routes>
        <route path="/Test_Web_App/**">
            <rewrite apply="TEST_WEB_APP/Test_Web_App/**" to="response.body" />
        </route>
        <route path="/Test_Web_App/**?**">
           <rewrite apply="TEST_WEB_APP/Test_Web_App/**?**" to="response.body"/>
    </routes>
</service>

and this is what I have added in sandbox.xml (topology )
<service>
        <role>TEST_WEB_APP</role>
        <url>http://localhost:8087</url>
</service>
But it is not working. Can you please tell me what else I need to do? Or if I am making any mistake

Thanks & Regards,
Brijan Elwadhi
Software Engineer
M: +91-7587130309
[cid:image001.jpg@01D01AD9.A3CE5C20]<http://www.resilinc.com/>
[facebook]<https://www.facebook.com/pages/Resilinc/152374944798272>  [twitter] <http://www.twitter.com/resilinc>   [linkedin] <http://www.linkedin.com/company/resilinc-corporation>   [youtube] <https://www.youtube.com/channel/UCbo4dHglF3tdc-h7Db8YaGw>

[cid:A961F978-0020-464D-A5C1-1AD0E6195E54]<https://www.eventbrite.com/e/2016-global-supply-chain-resiliency-council-conference-awards-registration-18740042973>