Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-users] Using WebAppContext at contextPath / but also serving images, sounds folders

I'm not sure what you are wanting to do?  Do you want to keep your 2 static content ContextHandlers (at context paths "/images" and "/sounds") and your var/www/myservlet-3.0.war but move it to context path "/"?  Or are you asking can you combine all 3 into a single webapp?

Jan

On Mon, 9 Aug 2021 at 21:21, Alexander Farber <alexander.farber@xxxxxxxxx> wrote:
Hello dear Jetty users and developers,

I am using 9.4.43.v20210629 for two things:

1) serve Websockets and GET, POST requests
2) serve files located in "images" and "sounds" folders

My config for 1 is currently using contextPath "/ws":

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN"
<Configure class="org.eclipse.jetty.webapp.WebAppContext">

    <Set name="contextPath">/ws</Set>
    <Set name="war">/var/www/myservlet-3.0.war</Set>

</Configure>

And the two configs for 2 are (only the "resourceBase" differs):

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN"
<Configure class="org.eclipse.jetty.server.handler.ContextHandler">
    <Set name="contextPath">/images</Set>
    <Set name="handler">
        <New class="org.eclipse.jetty.server.handler.ResourceHandler">
             <Set name="resourceBase">/var/www/html/mydomain.com/images</Set>
            <Set name="directoriesListed">true</Set>
        </New>
    </Set>
</Configure>

It works well for several years already (and behind HAProxy 1.8.27), but I am not happy with having  contextPath "/ws" as a prefix to my servlet.

I would like to change it to "/" aka root, but wonder how to keep "/images" and "/sounds" also servable by Jetty.

Would org.eclipse.jetty.fcgi.server.proxy.TryFilesFilter help me in this situation?

If a file (a sound or image file) is found, it should be served. Otherwise the Websockets, GET or POST request should be forwarded to my servlet.

In the Jetty doc for FastCGI there is an example:

    <Call name="addFilter">
        <Arg>org.eclipse.jetty.fcgi.server.proxy.TryFilesFilter</Arg>
        <Arg>/*</Arg>
        <Arg>
            <Call name="of" class="java.util.EnumSet">
                <Arg><Get name="REQUEST" class="javax.servlet.DispatcherType" /></Arg>
            </Call>
        </Arg>
        <Call name="setInitParameter">
            <Arg>files</Arg>
            <Arg>$path /index.php?p=$path</Arg>
        </Call>
    </Call>

but I am not sure how to apply it to my situation, how to replace the "index.php" by my servlet there?

Best regards
Alex

_______________________________________________
jetty-users mailing list
jetty-users@xxxxxxxxxxx
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/jetty-users


--
Jan Bartel <janb@xxxxxxxxxxx>
www.webtide.com
Expert assistance from the creators of Jetty and CometD


Back to the top