303 (see other) redirects

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

303 (see other) redirects

Ethan Gruber
Hi all,

I've been looking around the documentation for information about redirects.  The HTTP serializer allows you to set the status code (I want to use 303 to redirect to another URI), but not the redirect location.  I think I can use the header in oxf:http-serializer to do this:

<header>
   <name>Location</name>
  <value>URI</value>
</header>

But I can't really test it because I'm getting other errors.  What I would like to do in the page-flow is redirect the page "id/(.*)" to "id/$1.html" via a semantic 303 redirect.  So I want to generate a small HTML doc that will be returned by curl, but if you visit "id/(.*) in a browser, the browser will automatically redirect.  So there's some XSLT that must occur with, I think, the HTTP serializer on top of it to control the status code and header.  But I'm getting the following error:

Root element must contain an xsi:type attribute

Here is my XPL:

<p:pipeline xmlns:p="http://www.orbeon.com/oxf/pipeline" xmlns:oxf="http://www.orbeon.com/oxf/processors">

    <p:param type="input" name="data"/>
    <p:param type="output" name="data"/>

    <p:processor name="oxf:request">
        <p:input name="config">
            <config>
                <include>/request</include>
            </config>
        </p:input>
        <p:output name="data" id="request"/>
    </p:processor>

    <!-- generate HTML fragment to be returned -->
    <p:processor name="oxf:unsafe-xslt">
        <p:input name="request" href="#request"/>
        <p:input name="data" href="../config.xml"/>
        <p:input name="config">
            <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
                <xsl:output indent="yes"/>
                <xsl:template match="/">
                    <xsl:variable name="path" select="substring-after(doc('input:request')/request/request-url, 'id/')"/>
                    <html>
                        <head>
                            <title>303 See Other</title>
                        </head>
                        <body>
                            <h1>See Other</h1>
                            <p>The answer to your request is located <a href="{/config/url}id/{$path}.html">here</a>.</p>
                        </body>
                    </html>
                </xsl:template>
            </xsl:stylesheet>
        </p:input>
        <p:output name="data" id="converted"/>
        <p:output name="data" ref="data"/>
    </p:processor>

    <!-- generate config for http-serializer -->
    <p:processor name="oxf:unsafe-xslt">
        <p:input name="request" href="#request"/>
        <p:input name="data" href="../config.xml"/>
        <p:input name="config">
            <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
                <xsl:output indent="yes"/>
                <xsl:template match="/">
                    <xsl:variable name="path" select="substring-after(doc('input:request')/request/request-url, 'id/')"/>
                    <config>
                        <status-code>303</status-code>
                        <content-type>text/plain</content-type>
                        <header>
                            <name>Location</name>
                            <value>
                                <xsl:value-of select="concat(/config/url, 'id/', $path, '.html')"/>
                            </value>
                        </header>
                    </config>
                </xsl:template>
            </xsl:stylesheet>
        </p:input>
        <p:output name="data" id="config"/>
    </p:processor>

    <p:processor name="oxf:http-serializer">
        <p:input name="data" href="#converted"/>
        <p:input name="config" href="#config"/>
    </p:processor>
</p:pipeline>


This should be theoretically possible to achieve through XPL, but I don't find any other examples.  Is it obvious what I'm doing wrong?  I've been banging my head against this for the last hour or two.

Thanks,
Ethan

--
You received this message because you are subscribed to the Google Groups "Orbeon Forms" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Reply | Threaded
Open this post in threaded view
|

Re: 303 (see other) redirects

Alessandro  Vernet
Administrator
If you are fine with 302 (http://en.wikipedia.org/wiki/HTTP_302) instead of a 303, which assumes the browser does a GET, then you should be able to redirect from "id/(.*)" to "id/$1.html" just with the page flow. The section below illustrates how the page flow is not only able to extract parameters from URL to populate an XML document, but also to do the opposite, which is interesting when you want to redirect users between pages. Would something like that work for you?

http://wiki.orbeon.com/forms/doc/developer-guide/page-flow-controller#TOC-Navigating-to-pages-that-use-matchers

Otherwise, I imagine you should indeed be able to do this by hand with the HTTP serializer. You should be pointing to the XPL with the model attribute (not view), and it should have no data output. If it doesn't work, you can maybe start by making everything static, just always issuing the same redirect, to check that part is working.

Alex
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet
Reply | Threaded
Open this post in threaded view
|

Re: 303 (see other) redirects

Ethan Gruber
In reply to this post by Ethan Gruber
Hi Alex,

I got it working.  Thanks!  I'm working on a linked data application, so I needed to use 303 for its semantic meaning.  I'm not very pedantic about HTTP, but others are, so I decided to play it by the book.  I called the XPL in the model instead of view in the page-flow and removed the data outputs.

Ethan

On Friday, January 24, 2014 10:18:31 AM UTC-5, ewg4xuva wrote:
Hi all,

I've been looking around the documentation for information about redirects.  The HTTP serializer allows you to set the status code (I want to use 303 to redirect to another URI), but not the redirect location.  I think I can use the header in oxf:http-serializer to do this:

<header>
   <name>Location</name>
  <value>URI</value>
</header>

But I can't really test it because I'm getting other errors.  What I would like to do in the page-flow is redirect the page "id/(.*)" to "id/$1.html" via a semantic 303 redirect.  So I want to generate a small HTML doc that will be returned by curl, but if you visit "id/(.*) in a browser, the browser will automatically redirect.  So there's some XSLT that must occur with, I think, the HTTP serializer on top of it to control the status code and header.  But I'm getting the following error:

Root element must contain an xsi:type attribute

Here is my XPL:

<p:pipeline xmlns:p="<a href="http://www.orbeon.com/oxf/pipeline" target="_blank" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Fwww.orbeon.com%2Foxf%2Fpipeline\46sa\75D\46sntz\0751\46usg\75AFQjCNHMmFPHk1jISsHDz5rHZ5nGOdzsFQ';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Fwww.orbeon.com%2Foxf%2Fpipeline\46sa\75D\46sntz\0751\46usg\75AFQjCNHMmFPHk1jISsHDz5rHZ5nGOdzsFQ';return true;">http://www.orbeon.com/oxf/pipeline" xmlns:oxf="<a href="http://www.orbeon.com/oxf/processors" target="_blank" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Fwww.orbeon.com%2Foxf%2Fprocessors\46sa\75D\46sntz\0751\46usg\75AFQjCNHUiiFySGwdM1bIDS_mg6f5SnUe1Q';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Fwww.orbeon.com%2Foxf%2Fprocessors\46sa\75D\46sntz\0751\46usg\75AFQjCNHUiiFySGwdM1bIDS_mg6f5SnUe1Q';return true;">http://www.orbeon.com/oxf/processors">

    <p:param type="input" name="data"/>
    <p:param type="output" name="data"/>

    <p:processor name="oxf:request">
        <p:input name="config">
            <config>
                <include>/request</include>
            </config>
        </p:input>
        <p:output name="data" id="request"/>
    </p:processor>

    <!-- generate HTML fragment to be returned -->
    <p:processor name="oxf:unsafe-xslt">
        <p:input name="request" href="#request"/>
        <p:input name="data" href="../config.xml"/>
        <p:input name="config">
            <xsl:stylesheet version="2.0" xmlns:xsl="<a href="http://www.w3.org/1999/XSL/Transform" target="_blank" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Fwww.w3.org%2F1999%2FXSL%2FTransform\46sa\75D\46sntz\0751\46usg\75AFQjCNGlnJQfHfrx1POko4fKQj_0jkFwbA';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Fwww.w3.org%2F1999%2FXSL%2FTransform\46sa\75D\46sntz\0751\46usg\75AFQjCNGlnJQfHfrx1POko4fKQj_0jkFwbA';return true;">http://www.w3.org/1999/XSL/Transform">
                <xsl:output indent="yes"/>
                <xsl:template match="/">
                    <xsl:variable name="path" select="substring-after(doc('input:request')/request/request-url, 'id/')"/>
                    <html>
                        <head>
                            <title>303 See Other</title>
                        </head>
                        <body>
                            <h1>See Other</h1>
                            <p>The answer to your request is located <a href="{/config/url}id/{$path}.html">here</a>.</p>
                        </body>
                    </html>
                </xsl:template>
            </xsl:stylesheet>
        </p:input>
        <p:output name="data" id="converted"/>
        <p:output name="data" ref="data"/>
    </p:processor>

    <!-- generate config for http-serializer -->
    <p:processor name="oxf:unsafe-xslt">
        <p:input name="request" href="#request"/>
        <p:input name="data" href="../config.xml"/>
        <p:input name="config">
            <xsl:stylesheet version="2.0" xmlns:xsl="<a href="http://www.w3.org/1999/XSL/Transform" target="_blank" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Fwww.w3.org%2F1999%2FXSL%2FTransform\46sa\75D\46sntz\0751\46usg\75AFQjCNGlnJQfHfrx1POko4fKQj_0jkFwbA';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Fwww.w3.org%2F1999%2FXSL%2FTransform\46sa\75D\46sntz\0751\46usg\75AFQjCNGlnJQfHfrx1POko4fKQj_0jkFwbA';return true;">http://www.w3.org/1999/XSL/Transform">
                <xsl:output indent="yes"/>
                <xsl:template match="/">
                    <xsl:variable name="path" select="substring-after(doc('input:request')/request/request-url, 'id/')"/>
                    <config>
                        <status-code>303</status-code>
                        <content-type>text/plain</content-type>
                        <header>
                            <name>Location</name>
                            <value>
                                <xsl:value-of select="concat(/config/url, 'id/', $path, '.html')"/>
                            </value>
                        </header>
                    </config>
                </xsl:template>
            </xsl:stylesheet>
        </p:input>
        <p:output name="data" id="config"/>
    </p:processor>

    <p:processor name="oxf:http-serializer">
        <p:input name="data" href="#converted"/>
        <p:input name="config" href="#config"/>
    </p:processor>
</p:pipeline>


This should be theoretically possible to achieve through XPL, but I don't find any other examples.  Is it obvious what I'm doing wrong?  I've been banging my head against this for the last hour or two.

Thanks,
Ethan

--
You received this message because you are subscribed to the Google Groups "Orbeon Forms" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].