Rewriting paths with undertow-handlers.conf doesn't work as expected











up vote
0
down vote

favorite












I've inherited a JBoss 7.1.3 EAP back-end with an Angular 7 UI. I am a JBoss neophyte.



Background



I need to make JBoss aware of the UI's routes, but rewrite them all to the UI's index page for routing by Angular.



The project is structured thus:



webapp/
WEB-INF/
undertow-handlers.conf
web.xml
...etc
login/
background.jpg
login.jsp
index.jsp

assets/*
...html
...js
...css


index.jsp simply response.sendRedirect("index.html")s, where index.html is part of the assets produced by the Angular CLI. JavaScript and HTML is served from webapp/, images from webapp/assets/.



Configuration



From standalone-full.xml



<subsystem xmlns="urn:jboss:domain:undertow:4.0">
<buffer-cache name="default"/>
<server name="default-server">
<http-listener name="http" socket-binding="http" redirect-socket="https"/>
<host name="default-host" alias="localhost,workstation">
<location name="/" handler="welcome-content"/>
<filter-ref name="request-dumper"/>
</host>
</server>
<servlet-container name="default">
<jsp-config x-powered-by="false"/>
<websockets/>
</servlet-container>
<handlers>
<file name="welcome-content" path="${jboss.home.dir}/welcome-content"/>
</handlers>
<filters>
<filter name="request-dumper" module="io.undertow.core" class-name="io.undertow.server.handlers.RequestDumpingHandler"/>
</filters>
</subsystem>


and



<subsystem xmlns="urn:jboss:domain:web:2.2" default-virtual-server="default-host" native="false">
<connector name="http" protocol="HTTP/1.1" scheme="http" socket-binding="http"/>
<virtual-server name="default-host">
<alias name="localhost"/>
<alias name="workstation"/>
</virtual-server>
</subsystem>


With the above configuration, I see the expected server log:



[org.wildfly.extension.undertow] (ServerService Thread Pool -- 84) WFLYUT0021: Registered web context: '/' for server 'default-server'


And I can access the site's login page, and the URI / serves the main angular index page and assets as expected.



Problem



What I need is for paths in this context (like /base or /shop/60) to be handled by Angular, so redirected to index.



As a simple test based on this answer, I have tried this single rule in WEB-INF/undertow-handlers.conf:



exists(%{RELATIVE_PATH}) -> done
path-prefix('/') -> rewrite('/');


but it seems to do nothing at all as I get a 404.



I've tried -> rewrite('/index.html') and -> rewrite('/index.jsp') to no avail.



The file is clearly being read, though, because if I put garbage into the file it throws an exception in the server log.



UT000045: Error parsing predicated handler string Invalid expression:
# path('/base') -> rewrite('/')


What have I missed?



I'm quite a neophyte to JBoss and the whole Undertow ecosystem; please let me know what other details I should add to this question.



Curiosity



With request dumper activated, I see a single initial request to / made by JBoss (User-Agent=Java/1.8.0_181) immediately after booting, but when I navigate to / from a browser, I don't see that request in the dump. But I do see the failed request for /base. Why is that?










share|improve this question




























    up vote
    0
    down vote

    favorite












    I've inherited a JBoss 7.1.3 EAP back-end with an Angular 7 UI. I am a JBoss neophyte.



    Background



    I need to make JBoss aware of the UI's routes, but rewrite them all to the UI's index page for routing by Angular.



    The project is structured thus:



    webapp/
    WEB-INF/
    undertow-handlers.conf
    web.xml
    ...etc
    login/
    background.jpg
    login.jsp
    index.jsp

    assets/*
    ...html
    ...js
    ...css


    index.jsp simply response.sendRedirect("index.html")s, where index.html is part of the assets produced by the Angular CLI. JavaScript and HTML is served from webapp/, images from webapp/assets/.



    Configuration



    From standalone-full.xml



    <subsystem xmlns="urn:jboss:domain:undertow:4.0">
    <buffer-cache name="default"/>
    <server name="default-server">
    <http-listener name="http" socket-binding="http" redirect-socket="https"/>
    <host name="default-host" alias="localhost,workstation">
    <location name="/" handler="welcome-content"/>
    <filter-ref name="request-dumper"/>
    </host>
    </server>
    <servlet-container name="default">
    <jsp-config x-powered-by="false"/>
    <websockets/>
    </servlet-container>
    <handlers>
    <file name="welcome-content" path="${jboss.home.dir}/welcome-content"/>
    </handlers>
    <filters>
    <filter name="request-dumper" module="io.undertow.core" class-name="io.undertow.server.handlers.RequestDumpingHandler"/>
    </filters>
    </subsystem>


    and



    <subsystem xmlns="urn:jboss:domain:web:2.2" default-virtual-server="default-host" native="false">
    <connector name="http" protocol="HTTP/1.1" scheme="http" socket-binding="http"/>
    <virtual-server name="default-host">
    <alias name="localhost"/>
    <alias name="workstation"/>
    </virtual-server>
    </subsystem>


    With the above configuration, I see the expected server log:



    [org.wildfly.extension.undertow] (ServerService Thread Pool -- 84) WFLYUT0021: Registered web context: '/' for server 'default-server'


    And I can access the site's login page, and the URI / serves the main angular index page and assets as expected.



    Problem



    What I need is for paths in this context (like /base or /shop/60) to be handled by Angular, so redirected to index.



    As a simple test based on this answer, I have tried this single rule in WEB-INF/undertow-handlers.conf:



    exists(%{RELATIVE_PATH}) -> done
    path-prefix('/') -> rewrite('/');


    but it seems to do nothing at all as I get a 404.



    I've tried -> rewrite('/index.html') and -> rewrite('/index.jsp') to no avail.



    The file is clearly being read, though, because if I put garbage into the file it throws an exception in the server log.



    UT000045: Error parsing predicated handler string Invalid expression:
    # path('/base') -> rewrite('/')


    What have I missed?



    I'm quite a neophyte to JBoss and the whole Undertow ecosystem; please let me know what other details I should add to this question.



    Curiosity



    With request dumper activated, I see a single initial request to / made by JBoss (User-Agent=Java/1.8.0_181) immediately after booting, but when I navigate to / from a browser, I don't see that request in the dump. But I do see the failed request for /base. Why is that?










    share|improve this question


























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I've inherited a JBoss 7.1.3 EAP back-end with an Angular 7 UI. I am a JBoss neophyte.



      Background



      I need to make JBoss aware of the UI's routes, but rewrite them all to the UI's index page for routing by Angular.



      The project is structured thus:



      webapp/
      WEB-INF/
      undertow-handlers.conf
      web.xml
      ...etc
      login/
      background.jpg
      login.jsp
      index.jsp

      assets/*
      ...html
      ...js
      ...css


      index.jsp simply response.sendRedirect("index.html")s, where index.html is part of the assets produced by the Angular CLI. JavaScript and HTML is served from webapp/, images from webapp/assets/.



      Configuration



      From standalone-full.xml



      <subsystem xmlns="urn:jboss:domain:undertow:4.0">
      <buffer-cache name="default"/>
      <server name="default-server">
      <http-listener name="http" socket-binding="http" redirect-socket="https"/>
      <host name="default-host" alias="localhost,workstation">
      <location name="/" handler="welcome-content"/>
      <filter-ref name="request-dumper"/>
      </host>
      </server>
      <servlet-container name="default">
      <jsp-config x-powered-by="false"/>
      <websockets/>
      </servlet-container>
      <handlers>
      <file name="welcome-content" path="${jboss.home.dir}/welcome-content"/>
      </handlers>
      <filters>
      <filter name="request-dumper" module="io.undertow.core" class-name="io.undertow.server.handlers.RequestDumpingHandler"/>
      </filters>
      </subsystem>


      and



      <subsystem xmlns="urn:jboss:domain:web:2.2" default-virtual-server="default-host" native="false">
      <connector name="http" protocol="HTTP/1.1" scheme="http" socket-binding="http"/>
      <virtual-server name="default-host">
      <alias name="localhost"/>
      <alias name="workstation"/>
      </virtual-server>
      </subsystem>


      With the above configuration, I see the expected server log:



      [org.wildfly.extension.undertow] (ServerService Thread Pool -- 84) WFLYUT0021: Registered web context: '/' for server 'default-server'


      And I can access the site's login page, and the URI / serves the main angular index page and assets as expected.



      Problem



      What I need is for paths in this context (like /base or /shop/60) to be handled by Angular, so redirected to index.



      As a simple test based on this answer, I have tried this single rule in WEB-INF/undertow-handlers.conf:



      exists(%{RELATIVE_PATH}) -> done
      path-prefix('/') -> rewrite('/');


      but it seems to do nothing at all as I get a 404.



      I've tried -> rewrite('/index.html') and -> rewrite('/index.jsp') to no avail.



      The file is clearly being read, though, because if I put garbage into the file it throws an exception in the server log.



      UT000045: Error parsing predicated handler string Invalid expression:
      # path('/base') -> rewrite('/')


      What have I missed?



      I'm quite a neophyte to JBoss and the whole Undertow ecosystem; please let me know what other details I should add to this question.



      Curiosity



      With request dumper activated, I see a single initial request to / made by JBoss (User-Agent=Java/1.8.0_181) immediately after booting, but when I navigate to / from a browser, I don't see that request in the dump. But I do see the failed request for /base. Why is that?










      share|improve this question















      I've inherited a JBoss 7.1.3 EAP back-end with an Angular 7 UI. I am a JBoss neophyte.



      Background



      I need to make JBoss aware of the UI's routes, but rewrite them all to the UI's index page for routing by Angular.



      The project is structured thus:



      webapp/
      WEB-INF/
      undertow-handlers.conf
      web.xml
      ...etc
      login/
      background.jpg
      login.jsp
      index.jsp

      assets/*
      ...html
      ...js
      ...css


      index.jsp simply response.sendRedirect("index.html")s, where index.html is part of the assets produced by the Angular CLI. JavaScript and HTML is served from webapp/, images from webapp/assets/.



      Configuration



      From standalone-full.xml



      <subsystem xmlns="urn:jboss:domain:undertow:4.0">
      <buffer-cache name="default"/>
      <server name="default-server">
      <http-listener name="http" socket-binding="http" redirect-socket="https"/>
      <host name="default-host" alias="localhost,workstation">
      <location name="/" handler="welcome-content"/>
      <filter-ref name="request-dumper"/>
      </host>
      </server>
      <servlet-container name="default">
      <jsp-config x-powered-by="false"/>
      <websockets/>
      </servlet-container>
      <handlers>
      <file name="welcome-content" path="${jboss.home.dir}/welcome-content"/>
      </handlers>
      <filters>
      <filter name="request-dumper" module="io.undertow.core" class-name="io.undertow.server.handlers.RequestDumpingHandler"/>
      </filters>
      </subsystem>


      and



      <subsystem xmlns="urn:jboss:domain:web:2.2" default-virtual-server="default-host" native="false">
      <connector name="http" protocol="HTTP/1.1" scheme="http" socket-binding="http"/>
      <virtual-server name="default-host">
      <alias name="localhost"/>
      <alias name="workstation"/>
      </virtual-server>
      </subsystem>


      With the above configuration, I see the expected server log:



      [org.wildfly.extension.undertow] (ServerService Thread Pool -- 84) WFLYUT0021: Registered web context: '/' for server 'default-server'


      And I can access the site's login page, and the URI / serves the main angular index page and assets as expected.



      Problem



      What I need is for paths in this context (like /base or /shop/60) to be handled by Angular, so redirected to index.



      As a simple test based on this answer, I have tried this single rule in WEB-INF/undertow-handlers.conf:



      exists(%{RELATIVE_PATH}) -> done
      path-prefix('/') -> rewrite('/');


      but it seems to do nothing at all as I get a 404.



      I've tried -> rewrite('/index.html') and -> rewrite('/index.jsp') to no avail.



      The file is clearly being read, though, because if I put garbage into the file it throws an exception in the server log.



      UT000045: Error parsing predicated handler string Invalid expression:
      # path('/base') -> rewrite('/')


      What have I missed?



      I'm quite a neophyte to JBoss and the whole Undertow ecosystem; please let me know what other details I should add to this question.



      Curiosity



      With request dumper activated, I see a single initial request to / made by JBoss (User-Agent=Java/1.8.0_181) immediately after booting, but when I navigate to / from a browser, I don't see that request in the dump. But I do see the failed request for /base. Why is that?







      jboss7.x angular-router undertow






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 4 hours ago

























      asked 4 hours ago









      msanford

      6,42864365




      6,42864365
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          I had two problems:



          I was missing rules, and I has misunderstood the function of path-prefix (which matches on complete and non-terminal path segments, rather than acting like a regex ^(group)).



          My final, working undertow-handlers.conf looks like this:



          regex('/login(.*)') -> done;

          path-prefix('/assets') -> done;

          regex('(.*).js') -> done;
          regex('(.*).map') -> done;

          regex('(.*).svg') -> done;
          regex('(.*).png') -> done;

          regex('(.*).eot') -> done;
          regex('(.*).woff2') -> done;

          regex('(.*).html') -> done;

          path('/') -> rewrite('/index.html');

          path('/base') -> rewrite('index.html');
          path-prefix('/shop') -> rewrite('index.html');

          ...and all my other angular routes


          Note that /base is a terminal path segment, and matches with path, whereas /shop/60 takes an additional path parameter, so requires path-prefex.



          For whatever reason, the solution proposed in the linked question above, simply capturing it all with path-prefix('/') didn't work in my case.



          Possibly-heplful side-note: we have a REST server that serves from /RestService/ in another servlet context, so no rules were needed to allow that to continue to work.



          I'm happy for improvements on this: please don't hesitate to comment or add another answer.






          share|improve this answer





















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














             

            draft saved


            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53343749%2frewriting-paths-with-undertow-handlers-conf-doesnt-work-as-expected%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            0
            down vote













            I had two problems:



            I was missing rules, and I has misunderstood the function of path-prefix (which matches on complete and non-terminal path segments, rather than acting like a regex ^(group)).



            My final, working undertow-handlers.conf looks like this:



            regex('/login(.*)') -> done;

            path-prefix('/assets') -> done;

            regex('(.*).js') -> done;
            regex('(.*).map') -> done;

            regex('(.*).svg') -> done;
            regex('(.*).png') -> done;

            regex('(.*).eot') -> done;
            regex('(.*).woff2') -> done;

            regex('(.*).html') -> done;

            path('/') -> rewrite('/index.html');

            path('/base') -> rewrite('index.html');
            path-prefix('/shop') -> rewrite('index.html');

            ...and all my other angular routes


            Note that /base is a terminal path segment, and matches with path, whereas /shop/60 takes an additional path parameter, so requires path-prefex.



            For whatever reason, the solution proposed in the linked question above, simply capturing it all with path-prefix('/') didn't work in my case.



            Possibly-heplful side-note: we have a REST server that serves from /RestService/ in another servlet context, so no rules were needed to allow that to continue to work.



            I'm happy for improvements on this: please don't hesitate to comment or add another answer.






            share|improve this answer

























              up vote
              0
              down vote













              I had two problems:



              I was missing rules, and I has misunderstood the function of path-prefix (which matches on complete and non-terminal path segments, rather than acting like a regex ^(group)).



              My final, working undertow-handlers.conf looks like this:



              regex('/login(.*)') -> done;

              path-prefix('/assets') -> done;

              regex('(.*).js') -> done;
              regex('(.*).map') -> done;

              regex('(.*).svg') -> done;
              regex('(.*).png') -> done;

              regex('(.*).eot') -> done;
              regex('(.*).woff2') -> done;

              regex('(.*).html') -> done;

              path('/') -> rewrite('/index.html');

              path('/base') -> rewrite('index.html');
              path-prefix('/shop') -> rewrite('index.html');

              ...and all my other angular routes


              Note that /base is a terminal path segment, and matches with path, whereas /shop/60 takes an additional path parameter, so requires path-prefex.



              For whatever reason, the solution proposed in the linked question above, simply capturing it all with path-prefix('/') didn't work in my case.



              Possibly-heplful side-note: we have a REST server that serves from /RestService/ in another servlet context, so no rules were needed to allow that to continue to work.



              I'm happy for improvements on this: please don't hesitate to comment or add another answer.






              share|improve this answer























                up vote
                0
                down vote










                up vote
                0
                down vote









                I had two problems:



                I was missing rules, and I has misunderstood the function of path-prefix (which matches on complete and non-terminal path segments, rather than acting like a regex ^(group)).



                My final, working undertow-handlers.conf looks like this:



                regex('/login(.*)') -> done;

                path-prefix('/assets') -> done;

                regex('(.*).js') -> done;
                regex('(.*).map') -> done;

                regex('(.*).svg') -> done;
                regex('(.*).png') -> done;

                regex('(.*).eot') -> done;
                regex('(.*).woff2') -> done;

                regex('(.*).html') -> done;

                path('/') -> rewrite('/index.html');

                path('/base') -> rewrite('index.html');
                path-prefix('/shop') -> rewrite('index.html');

                ...and all my other angular routes


                Note that /base is a terminal path segment, and matches with path, whereas /shop/60 takes an additional path parameter, so requires path-prefex.



                For whatever reason, the solution proposed in the linked question above, simply capturing it all with path-prefix('/') didn't work in my case.



                Possibly-heplful side-note: we have a REST server that serves from /RestService/ in another servlet context, so no rules were needed to allow that to continue to work.



                I'm happy for improvements on this: please don't hesitate to comment or add another answer.






                share|improve this answer












                I had two problems:



                I was missing rules, and I has misunderstood the function of path-prefix (which matches on complete and non-terminal path segments, rather than acting like a regex ^(group)).



                My final, working undertow-handlers.conf looks like this:



                regex('/login(.*)') -> done;

                path-prefix('/assets') -> done;

                regex('(.*).js') -> done;
                regex('(.*).map') -> done;

                regex('(.*).svg') -> done;
                regex('(.*).png') -> done;

                regex('(.*).eot') -> done;
                regex('(.*).woff2') -> done;

                regex('(.*).html') -> done;

                path('/') -> rewrite('/index.html');

                path('/base') -> rewrite('index.html');
                path-prefix('/shop') -> rewrite('index.html');

                ...and all my other angular routes


                Note that /base is a terminal path segment, and matches with path, whereas /shop/60 takes an additional path parameter, so requires path-prefex.



                For whatever reason, the solution proposed in the linked question above, simply capturing it all with path-prefix('/') didn't work in my case.



                Possibly-heplful side-note: we have a REST server that serves from /RestService/ in another servlet context, so no rules were needed to allow that to continue to work.



                I'm happy for improvements on this: please don't hesitate to comment or add another answer.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered 1 hour ago









                msanford

                6,42864365




                6,42864365






























                     

                    draft saved


                    draft discarded



















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53343749%2frewriting-paths-with-undertow-handlers-conf-doesnt-work-as-expected%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    If I really need a card on my start hand, how many mulligans make sense? [duplicate]

                    Alcedinidae

                    Can an atomic nucleus contain both particles and antiparticles? [duplicate]