lazydaemon
lazydaemon

Reputation: 2509

Wicket on Jetty: Cannot save page with id

I deployed my Apache Wicket App on a Jetty Server and everytime i open a Wicket-Page, i can see the following error on my jetty log:

WARN  - DiskDataStore              - Cannot save page with id '2' because the data file    cannot be opened.
ERROR - DiskDataStore              - /tmp/jetty-0.0.0.0-80-tourney.war-_tourney-any- /wicket.Tourneys-filestore/2gs9iqj4zdjtkerejipyu0co/data (No such file or directory)
java.io.FileNotFoundException: /tmp/jetty-0.0.0.0-80-tourney.war-_tourney-any-/wicket.Tourneys-filestore/2gs9iqj4zdjtkerejipyu0co/data (No such file or directory)
at java.io.RandomAccessFile.open(Native Method)
at java.io.RandomAccessFile.<init>(RandomAccessFile.java:233)
at org.apache.wicket.pageStore.DiskDataStore$SessionEntry.getFileChannel(DiskDataStore.java:410)
at org.apache.wicket.pageStore.DiskDataStore$SessionEntry.savePage(DiskDataStore.java:328)
at org.apache.wicket.pageStore.DiskDataStore.storeData(DiskDataStore.java:176)
at org.apache.wicket.pageStore.AsynchronousDataStore$PageSavingRunnable.run(AsynchronousDataStore.java:348)
at java.lang.Thread.run(Thread.java:636)

Any idea what went wrong? Unix rights are set correctly. I even tried with 777 but no success :(

Upvotes: 1

Views: 1567

Answers (4)

Mikk
Mikk

Reputation: 571

This also happens when you delete the datastore directory while Jetty is running. It still complains even if Jetty is allowed to create a new one.

For me the fix to that problem was to restart Jetty.

Upvotes: 1

spaaarky21
spaaarky21

Reputation: 6858

I figured I would elaborate on Martin's answer since it wasn't immediately obvious to me how to access IStoreSettings. You can update the data store directory using Wicket's API like this:

public class MyApplication extends WebApplication {
    protected void init() {
        super.init();

        getStoreSettings().setFileStoreFolder(new File("/path/to/directory/"));
    }
}

Although, I wouldn't consider that to be a very good idea. Since it sounds like Wicket defaults to the value of javax.servlet.context.tempdir, it would be far better to set that property than to hardcode a value in Java. That way Windows developers can set their own value like C:\Users\lazydaemon\temp, Linux developers can set a value like /home/lazydaemon/tmp/ and server admins can pick something like /var/cache/tomcat-VERSION/Catalina/whatever without any need for code changes or fragile if(configuration==RuntimeConfigurationType.DEVELOPMENT) logic.

So you could either set the property as an argument for when your server starts:

-Djavax.servlet.context.tempdir=/path/to/directory/

Or, if you are starting a Jetty server in code that doesn't get packaged and deployed in your war file, you could set the property in the code that configures and starts Jetty:

System.setProperty("javax.servlet.context.tempdir", "/path/to/directory/");

Upvotes: 0

martin-g
martin-g

Reputation: 17533

Here is the Wicket API way: org.apache.wicket.settings.IStoreSettings#setFileStoreFolder()

Upvotes: 0

polypiel
polypiel

Reputation: 2341

To change the DiskDataStore directory you can use a ServletContextListener:

public class InitListener implements ServletContextListener {
  @Override
  public void contextInitialized(ServletContextEvent sce) {
    final String workDir = sce.getServletContext().getInitParameter("workDirectory"); // Context param with the temp dir path
    sce.getServletContext().setAttribute("javax.servlet.context.tempdir", file); // sets the temp dir (Wicket will read it from here)
  }

  @Override
  public void contextDestroyed(ServletContextEvent sce) {}
}

And this is the neccesary web.xml entries:

<context-param>
  <param-name>workDirectory</param-name>
  <param-value>E:\wicket</param-value>
</context-param>
<listener>
  <listener-class>es.cyum.cruekti.wicket.InitListener</listener-class>
</listener>

Upvotes: 0

Related Questions