Try using a regex to match the given path e.g. "\/production\/datapoints"
Remove the double quotes. Try using different forms of regex if possible. Good luck Sandeep On Fri, May 3, 2019 at 11:15 AM Odon Copon <[email protected]> wrote: > > Hi Sandeep, > There is a "$.get('/production/datapoints')" in a jxs file, that performs the > API calls and renders the datapoints. > > I already tested with the following code but no luck: > > <filter name="FERRERORUI/ferrerorui/outbound/requests/filter"> > <content type="text/javascript"> > <apply path="production/datapoints" > rule="FERRERORUI/ferrerorui/outbound/requests"/> > </content> > </filter> > > On Fri, 3 May 2019 at 15:59, Sandeep Moré <[email protected]> wrote: >> >> Ah, I see. >> Your filter is for content type JSON, you need one for javascript, >> something like >> >> <filter name="FERRERORUI/ferrerorui/outbound/requests/filter"> >> <content type="text/javascript"> >> <apply path="production/datapoints" >> rule="FERRERORUI/ferrerorui/outbound/requests"/> >> </content> >> </filter> >> >> Few things to note: >> 1. Since I haven't seen the JS file I going by the assumption that >> there is a JS file with "production/datapoints" that needs to be >> rewritten >> 2. You will have to double check the exact content type you are >> getting i.e. application/x-javascript, text/javascript etc. >> >> Best, >> Sandeep >> >> >> On Fri, May 3, 2019 at 7:50 AM Odon Copon <[email protected]> wrote: >> > >> > Hi, >> > Thanks Sandeep for your help. >> > When I meant by JSON I was referring to the response from the API, but I >> > don't need to fix that. Is the call to retrieve the JSON what's wrong here. >> > The UI is a React application, and one of the React components, when it's >> > rendered, is triggering the API call. But, in the end, is a javascript >> > file. >> > >> > >> > This the following: >> > >> > <filter name="FERRERORUI/ferrerorui/outbound/requests/filter"> >> > <content type="application/json"> >> > <apply path="production/datapoints" >> > rule="FERRERORUI/ferrerorui/outbound/requests"/> >> > </content> >> > </filter> >> > >> > >> > <rule dir="OUT" name="FERRERORUI/ferrerorui/outbound/requests" > >> > <rewrite template="{$serviceUrl[FERRERORUI]}/production/datapoints"/> >> > </rule> >> > >> > And was expecting that any javascript containing "production/datapoints" >> > would match the filter and rewrite the url for >> > "{$serviceUrl[FERRERORUI]}/production/datapoints", but that doesn't seem >> > to work. >> > Thanks. >> > >> > On Thu, 2 May 2019 at 14:18, Sandeep Moré <[email protected]> wrote: >> >> >> >> Hello Odon, >> >> So, do you get a JSON response that has '/production/datapoints' path >> >> or is this an HTML ? >> >> We need to zero on what the file is that has those links (I don't have >> >> much experience with React so don't know how the UI is rendered). >> >> >> >> One thing you can do is try to use CURL commands and see which urls >> >> are not getting rewritten properly. >> >> >> >> About the "path" attribute in the filter/apply element, that is used >> >> for pattern matching and depending on the content-type you will need >> >> to choose the regex >> >> For parsing JSON documents Knox uses JSONPATH [1] >> >> see [2] for more details on rewriting >> >> >> >> [1] http://goessner.net/articles/JsonPath/ >> >> [2] >> >> https://cwiki.apache.org/confluence/display/KNOX/2017/08/14/Understanding+Rewrite+Rules+for+Apache+Knox#UnderstandingRewriteRulesforApacheKnox-JSONParsing >> >> >> >> On Thu, May 2, 2019 at 6:56 AM Odon Copon <[email protected]> wrote: >> >> > >> >> > Any input on this? >> >> > Thanks >> >> > >> >> > On Tue, 30 Apr 2019, 11:39 Odon Copon, <[email protected]> wrote: >> >> >> >> >> >> Hi Sandeep, >> >> >> The response from the UI for everything looks good, except for the >> >> >> information rendered from those graphs. >> >> >> The requests to generate those graphs, from what I see on the errors, >> >> >> are GET petitions to that API I mentioned before that get back a JSON. >> >> >> Those petitions have the following information: >> >> >> >> >> >> GET /production/datapoints HTTP/1.1 >> >> >> Host: knox:12002 >> >> >> Connection: keep-alive >> >> >> Accept: */* >> >> >> X-Requested-With: XMLHttpRequest >> >> >> User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_0) >> >> >> AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 >> >> >> Safari/537.36 >> >> >> Referer: http://knox:12002/gateway/test/ferrerorui/site/ >> >> >> Accept-Encoding: gzip, deflate >> >> >> Accept-Language: en-GB,en-US;q=0.9,en;q=0.8 >> >> >> >> >> >> And, obviously, I'm getting a 404 back from Knox, because >> >> >> knox:12002/production/datapoints is not there, it should be >> >> >> knox:12002/gateway/test/ferrerorapi/production/datapoints. >> >> >> But I don't really know how to make that with filters. Would it >> >> >> require something like the following? >> >> >> >> >> >> <filter name="FERRERORUI/ferrerorui/outbound/requests/filter"> >> >> >> <content type="application/json"> >> >> >> <apply path="???" >> >> >> rule="FERRERORUI/ferrerorui/outbound/requests"/> >> >> >> </content> >> >> >> </filter> >> >> >> >> >> >> What does the path mean on a filter? Isn't this "apply" already >> >> >> pointing to a rule that contains a "path" and a "rewrite"? >> >> >> >> >> >> Thanks. >> >> >> >> >> >> On Tue, 30 Apr 2019 at 03:36, Sandeep Moré <[email protected]> >> >> >> wrote: >> >> >>> >> >> >>> Hello Odon, >> >> >>> >> >> >>> What does the response from the the ferrero UI look like? for the >> >> >>> last rewrite rule, looks like you are having issues rewriting >> >> >>> outbound requests, what response are you dealing with, JSON, HTML, >> >> >>> plain text ? depending on that you probably need to add a filter for >> >> >>> that specific content type. I think you are very close ! >> >> >>> >> >> >>> Best, >> >> >>> Sandeep >> >> >>> >> >> >>> >> >> >>> On Mon, Apr 29, 2019 at 1:47 PM Odon Copon <[email protected]> >> >> >>> wrote: >> >> >>>> >> >> >>>> Hi, >> >> >>>> I have been following the steps from >> >> >>>> https://cwiki.apache.org/confluence/display/KNOX/Proxying+a+UI+using+Knox >> >> >>>> but I'm having some issue making something work, so would double >> >> >>>> check with you to understand if I'm making wrong assumptions. >> >> >>>> I have a UI made with React which URL is ferrerorui:8080/site/ that >> >> >>>> contains some graphs generated by some requests to >> >> >>>> ferrerorapi/production/datapoints. When I put Knox in place, I can >> >> >>>> access the UI by accessing knox:12002/gateway/test/ferrerorui/site/ >> >> >>>> and also I can send requests to the API by doing >> >> >>>> knox:12002/gateway/test/ferrerorapi/production/datapoints. >> >> >>>> >> >> >>>> >> >> >>>> This is the service defined (ferrerorapi, the API the UI consumes): >> >> >>>> >> >> >>>> service.xml >> >> >>>> >> >> >>>> <service role="FERRERORAPI" name="ferrerorapi" version="0.0.1"> >> >> >>>> <routes> >> >> >>>> <route path="/ferrerorapi/**"/> >> >> >>>> </routes> >> >> >>>> </service> >> >> >>>> >> >> >>>> rewrite.xml >> >> >>>> >> >> >>>> <rules> >> >> >>>> <rule dir="IN" name="FERREORAPI/ferrerorapi/inbound" >> >> >>>> pattern="*://*:*/**/ferrerorapi/{path=**}?{**}"> >> >> >>>> <rewrite template="{$serviceUrl[FERRERORAPI]}/{path=**}?{**}"/> >> >> >>>> </rule> >> >> >>>> </rules> >> >> >>>> >> >> >>>> >> >> >>>> Obviously, the API requests that generate the graphs are all failing >> >> >>>> with 404 when I access the UI, because they are hitting >> >> >>>> knox:12002/production/datapoints instead of >> >> >>>> knox:12002/gateway/test/ferrerorapi/production/datapoints >> >> >>>> >> >> >>>> >> >> >>>> This is the UI service: >> >> >>>> >> >> >>>> service.xml >> >> >>>> >> >> >>>> <service role="FERREORUI" name="ferrerorui" version="0.0.1"> >> >> >>>> <routes> >> >> >>>> <route path="/ferrerorui"/> >> >> >>>> <route path="/ferrerorui/**"/> >> >> >>>> <rewrite apply="FERRERORUI/ferrerorui/outbound/requests" >> >> >>>> to="response.body"/> >> >> >>>> </routes> >> >> >>>> </service> >> >> >>>> >> >> >>>> rewrite.xml >> >> >>>> >> >> >>>> <rules> >> >> >>>> <rule dir="IN" name="FERRERORUI/ferrerorui/inbound/root" >> >> >>>> pattern="*://*:*/**/ferrerorui/"> >> >> >>>> <rewrite template="{$serviceUrl[FERRERORUI]}/"/> >> >> >>>> </rule> >> >> >>>> <rule dir="IN" name="FERRERORUI/ferrerorui/inbound/path" >> >> >>>> pattern="*://*:*/**/ferrerorui/{path=**}?{**}"> >> >> >>>> <rewrite template="{$serviceUrl[FERRERORUI]}/{path=**}?{**}"/> >> >> >>>> </rule> >> >> >>>> <rule dir="OUT" name="FERRERORUI/ferrerorui/outbound/requests" >> >> >>>> pattern="*://*:*/**/production/{path=**}?{**}"> >> >> >>>> <rewrite template="{$serviceUrl[FERRERORUI]}/{path=**}?{**}"/> >> >> >>>> </rule> >> >> >>>> </rules> >> >> >>>> >> >> >>>> >> >> >>>> Tried with this last rewrite to convert on the UI, everything that >> >> >>>> had production as part of the path (api call) to be rewritten, but >> >> >>>> doesn't seem to work. The API call from the UI still don't contain >> >> >>>> the missing "gateway/test/ferrerorapi/". >> >> >>>> >> >> >>>> Is there anything that you spot that I'm not doing correctly? >> >> >>>> Thanks.
