Jalin Gladis
Jalin Gladis

Reputation: 113

Setting dirAllowed to false in Jetty 8.1.12

I was using Jetty 6.x where we created a spring based Jetty server with dirAllowed set to false. The config is as follows.

<bean id="Server" class="org.mortbay.jetty.Server" init-method="start" destroy-method="stop">
    <property name="connectors">
        <list>
            <bean id="Connector" class="org.mortbay.jetty.nio.SelectChannelConnector">
                <property name="port" value="${tnplportal.jettyServer.httpPort}" />
                <property name="headerBufferSize" value="${tnplportal.jettyServer.headerBufferSize}" />
            </bean>
        </list>
    </property>

    <property name="handler">
        <bean id="handlers" class="org.mortbay.jetty.handler.HandlerCollection">
            <property name="handlers">
                <list>
                    <bean id="contexts" class="org.mortbay.jetty.handler.ContextHandlerCollection">
                        <property name="handlers">
                            <list>
                                <bean class="org.mortbay.jetty.webapp.WebAppContext">
                                        <property name="contextPath" value="/fileServer" />
                                        <property name="resourceBase" value="ResourcePath" />
                                        <property name="initParams">
                                            <map> 
                                               <entry key="org.mortbay.jetty.servlet.Default.dirAllowed" value="false" />
                                            </map>
                                        </property>
                                </bean>

                            </list>
                        </property>
                    </bean>
                </list>
            </property>
        </bean>
    </property>
</bean>

Now I am upgrading to Jetty 8.1.12 and found that initParams is not available for org.eclipse.jetty.webapp.WebAppContext.Now present config is below (with dirAllowed commented out)

    <bean id="Server" class="org.eclipse.jetty.server.Server" init-method="start" destroy-method="stop">
    <property name="connectors">
        <list>
            <bean id="Connector" class="org.eclipse.jetty.server.nio.SelectChannelConnector">
                <property name="port" value="${tnplportal.jettyServer.httpPort}" />
            </bean>
        </list>
    </property>

    <property name="handler">
        <bean id="handlers" class="org.eclipse.jetty.server.handler.HandlerCollection">
            <property name="handlers">
                <list>
                    <bean id="contexts" class="org.eclipse.jetty.server.handler.ContextHandlerCollection">
                        <property name="handlers">
                            <list>
                                <bean class="org.eclipse.jetty.webapp.WebAppContext">
                                    <property name="contextPath" value="/fileServer" />
                                    <property name="resourceBase" value="resourcePath" />
                                    <!-- <property name="initParams">
                                           <map>               
                                            <entry key="org.mortbay.jetty.servlet.Default.dirAllowed" value="false" />
                                           </map>
                                        </property> -->
                                </bean>

                            </list>
                        </property>
                    </bean>
                </list>
            </property>
        </bean>
    </property>
</bean>

Can someone tell me how to set dirAllowed property for Jetty 8.1.12

I saw few posts for code based servers like this

But my server is spring based. How do I set with spring based configuration.

Upvotes: 1

Views: 1077

Answers (2)

wodong
wodong

Reputation: 307

An temp workaround should be create a custom WebAppContext, it's not grace but works.

public class CustomWebAppContext  extends org.eclipse.jetty.webapp.WebAppContext{
  public void setInitParams(Map<String, String> values){
    Map<String, String> currectParams= getInitParams();
    if(currectParams==null){
        currectParams= new HashMap<String, String>();
    }
    for(Map.Entry<String,String> entry : values.entrySet()){
        currectParams.put(entry.getKey(), entry.getValue());
    }
}}

Then in xml :

      <bean class="CustomWebAppContext">
                                    <property name="contextPath" value="/fileServer" />
                                    <property name="resourceBase" value="ResourcePath" />
                                    <property name="initParams">
                                        <map> 
                                           <entry key="org.mortbay.jetty.servlet.Default.dirAllowed" value="false" />
                                        </map>
                                    </property>
                            </bean>

Upvotes: 0

Joakim Erdfelt
Joakim Erdfelt

Reputation: 49515

The upgrade from Jetty 6 to Jetty 8 requires you to update your Jetty references.

To start with, you'll need to update all of your named classes. The project moved to the Eclipse Foundation 6 years ago, this resulted in a mandatory package name change from org.mortbay.jetty to org.eclipse.jetty

Then you'll want to update the various setters to be relevant to what you are attempting to do.

Would recommend that you grab a copy of the Jetty Distribution tarball (or zip) and check out the Jetty XML files that it comes with for some inspiration, while also referencing the Jetty 8 Javadocs for some details.

Note: Jetty 6 was EOL'd in 2010. Jetty 8 is EOL at the end of 2014, there will be no more updates to Jetty 8 after this year. Would highly encourage that you upgrade all the way to Jetty 9 now.

Upvotes: 1

Related Questions