[
https://issues.apache.org/jira/browse/KNOX-1295?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16465621#comment-16465621
]
Attila Csoma edited comment on KNOX-1295 at 5/7/18 8:43 AM:
------------------------------------------------------------
Hi [~mgaido]
You can attach a static string to the end of the {{X-Forwarded-Context}} header
by defining a rewrite rule for it.
Uploaded a patch to add {{sparkhistoryui}} to the end of {{X-Forwarded-Cache}}
in sparkhistoryui service by default.
If you want to do this on your deployed environment please add the following:
in {{data/services/sparkhistoryui/1.4.0/service.xml}}
{code:java}
<route path="/sparkhistory">
<rewrite apply="SPARKHISTORYUI/sparkhistory/outbound/rqheaders"
to="request.headers"/>
</route>
<route path="/sparkhistory/**">
<rewrite apply="SPARKHISTORYUI/sparkhistory/outbound/rqheaders"
to="request.headers"/>
</route>
{code}
in {{data/services/sparkhistoryui/1.4.0/rewrite.xml}}
{code:java}
<rule dir="IN" name="SPARKHISTORYUI/sparkhistory/outbound/rqheaders/xfc">
<match pattern="{**}"/>
<rewrite template="{**}/sparkhistoryui" />
</rule>
<filter name="SPARKHISTORYUI/sparkhistory/outbound/rqheaders">
<content type="application/x-http-headers">
<apply path="X-Forwarded-Context"
rule="SPARKHISTORYUI/sparkhistory/outbound/rqheaders/xfc"/>
</content>
</filter>
{code}
Clear your {{data/deployments/}} cache and restart your knox.
If you need to change the attached {{sparkhistoryui}} text just change it in
{{SPARKHISTORYUI/sparkhistory/outbound/rqheaders/xfc}}
EDIT:
Please note that {{X-Forwarded-Context}} currently created in from the string
returned by {{HttpServletRequest.getContextPath()}} without any modification.
Nevertheless I think adding a static string to {{X-Forwarded-Context}} can
solve the issue you mentioned namely to determine the proxy base URL on a
service side. Probably a more generic solution would be to create a
{{UrlRewriteResolver}} to determine base urls dynamically.
was (Author: csomaati):
Hi [~mgaido]
You can attach a static string to the end of the {{X-Forwarded-Context}} header
by defining a rewrite rule for it.
Uploaded a patch to add {{sparkhistoryui}} to the end of {{X-Forwarded-Cache}}
in sparkhistoryui service by default.
If you want to do this on your deployed environment please add the following:
in {{data/services/sparkhistoryui/1.4.0/service.xml}}
{code:java}
<route path="/sparkhistory">
<rewrite apply="SPARKHISTORYUI/sparkhistory/outbound/rqheaders"
to="request.headers"/>
</route>
<route path="/sparkhistory/**">
<rewrite apply="SPARKHISTORYUI/sparkhistory/outbound/rqheaders"
to="request.headers"/>
</route>
{code}
in {{data/services/sparkhistoryui/1.4.0/rewrite.xml}}
{code:java}
<rule dir="IN" name="SPARKHISTORYUI/sparkhistory/outbound/rqheaders/xfc">
<match pattern="{**}"/>
<rewrite template="{**}/sparkhistoryui" />
</rule>
<filter name="SPARKHISTORYUI/sparkhistory/outbound/rqheaders">
<content type="application/x-http-headers">
<apply path="X-Forwarded-Context"
rule="SPARKHISTORYUI/sparkhistory/outbound/rqheaders/xfc"/>
</content>
</filter>
{code}
Clear your {{data/deployments/}} cache and restart your knox.
If you need to change the attached {{sparkhistoryui}} text just change it in
{{SPARKHISTORYUI/sparkhistory/outbound/rqheaders/xfc}}
> X-Forwarded-Context contains not the full base path in SHS request
> ------------------------------------------------------------------
>
> Key: KNOX-1295
> URL: https://issues.apache.org/jira/browse/KNOX-1295
> Project: Apache Knox
> Issue Type: Improvement
> Affects Versions: 0.14.0
> Reporter: Marco Gaido
> Assignee: Attila Csoma
> Priority: Major
> Fix For: 1.1.0
>
> Attachments: KNOX-1295.patch
>
>
> Knox can send the base path which may be useful for the proxied application
> in order to determine the proxy base URL and build the URLs accordingly. This
> may be useful in Spark History Server which may use this to determine the
> proxy base URL, instead of relying on an internal config (which prevents SHS
> to be consumed through direct URL anymore).
> The problem is that Knox currently in the {{X-Forwarded-Context}} doesn't
> send the full base path, but only the first part of it, eg. it sends
> {{X-Forwarded-Context: gateway/default}} instead of {{X-Forwarded-Context:
> gateway/default/sparkhistoryui}}.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)