Quantcast

How can I serve static content from file system in Karaf?

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

How can I serve static content from file system in Karaf?

Alexey Romanov
I need to serve static content from outside a bundle in Karaf. Since it already has Pax Web and Jetty built in, I've thought it wouldn't be a problem, but no success so far :(

I have `jetty`, `http`, `http-whiteboard` and `war` features installed. Following http://team.ops4j.org/wiki/display/paxweb/Advanced+Jetty+Configuration, I've added this to `etc/jetty.xml`:

        <Get name="handler">
                <Call name="addHandler">
                        <Arg>
                                <New class="org.eclipse.jetty.servlet.ServletContextHandler">
                                        <Set name="contextPath">/app</Set>
                                        <Set name="resourceBase">/home/aromanov/workspaces/odp-server/ru.focusmedia.odp.server.poim.resources-rodniki/
                                        </Set>
                                        <Call name="addServlet">
                                                <Arg>org.eclipse.jetty.servlet.DefaultServlet</Arg>
                                                <Arg>/</Arg>
                                        </Call>
                                </New>
                        </Arg>
                </Call>
        </Get>

The complete file is:

    <?xml version="1.0"?>
    <!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//
    DTD Configure//EN" "http://jetty.mortbay.org/configure.dtd">
   
    <Configure class="org.eclipse.jetty.server.Server">
   
   
   
   
   
   
   
   
    <Call name="addConnector">
    <Arg>
    <New class="org.eclipse.jetty.server.nio.SelectChannelConnector">
    <Set name="host">
    <Property name="jetty.host" default="0.0.0.0" />
    </Set>
    <Set name="port">
    <Property name="jetty.port" default="8282" />
    </Set>
    <Set name="maxIdleTime">300000</Set>
    <Set name="Acceptors">2</Set>
    <Set name="statsOn">false</Set>
    <Set name="confidentialPort">8443</Set>
    <Set name="lowResourcesConnections">20000</Set>
    <Set name="lowResourcesMaxIdleTime">5000</Set>
    </New>
    </Arg>
    </Call>
   
   
   
   
   
   
   
   
    <Call name="addBean">
    <Arg>
    <New class="org.eclipse.jetty.plus.jaas.JAASLoginService">
    <Set name="name">karaf</Set>
    <Set name="loginModuleName">karaf</Set>
    <Set name="roleClassNames">
    <Array type="java.lang.String">
    <Item>org.apache.karaf.jaas.modules.RolePrincipal</Item>
    </Array>
    </Set>
    </New>
    </Arg>
    </Call>
    <Call name="addBean">
    <Arg>
    <New class="org.eclipse.jetty.plus.jaas.JAASLoginService">
    <Set name="name">default</Set>
    <Set name="loginModuleName">karaf</Set>
    <Set name="roleClassNames">
    <Array type="java.lang.String">
    <Item>org.apache.karaf.jaas.modules.RolePrincipal</Item>
    </Array>
    </Set>
    </New>
    </Arg>
    </Call>
   
   
    <Get name="handler">
    <Call name="addHandler">
    <Arg>
    <New class="org.eclipse.jetty.servlet.ServletContextHandler">
    <Set name="contextPath">/app</Set>
    <Set name="resourceBase">/home/aromanov/workspaces/odp-server/ru.focusmedia.odp.server.poim.resources-rodniki
    </Set>
    <Call name="addServlet">
    <Arg>org.eclipse.jetty.servlet.DefaultServlet</Arg>
    <Arg>/</Arg>
    </Call>
    </New>
    </Arg>
    </Call>
    </Get>
   
    </Configure>

And created the file `org.ops4j.pax.web.cfg` with this content:

    org.ops4j.pax.web.config.file=/home/aromanov/workspaces/odp-server/ru.focusmedia.odp.server.karaf.launcher/etc/jetty.xml

In the log I see

    2012-06-02 12:03:52,800 | INFO  | g.ops4j.pax.web) | Server                           |  -  -  | jetty-7.5.4.v20111024
    2012-06-02 12:03:52,848 | INFO  | g.ops4j.pax.web) | ContextHandler                   |  -  -  | started o.e.j.s.ServletContextHandler{/app,file:/home/aromanov/workspaces/odp-server/ru.focusmedia.odp.server.poim.resources-rodniki/}
    2012-06-02 12:03:52,907 | INFO  | g.ops4j.pax.web) | AbstractConnector                |  -  -  | Started SelectChannelConnector@0.0.0.0:8282 STARTING
    2012-06-02 12:03:52,914 | INFO  | g.ops4j.pax.web) | JettyServerImpl                  | 124 - org.ops4j.pax.web.pax-web-jetty - 1.0.9 | Pax Web available at [0.0.0.0]:[8080]
    2012-06-02 12:03:52,927 | INFO  | g.ops4j.pax.web) | AbstractConnector                |  -  -  | Started NIOSocketConnectorWrapper@0.0.0.0:8080 STARTING

But the files aren't visible. E.g., I have a file `/home/aromanov/workspaces/odp-server/ru.focusmedia.odp.server.poim.resources-rodniki/.style`, but going to either `http://192.168.1.9:8080/app/.style` or `http://192.168.1.9:8282/app/.style` gives 404 error.
Loading...