DWR - download function

Hi,

Recently did an upgrade to DWR version 3.0.2. However, got an error 500 when trying to download a file.
After investigations, it turns out that the ~ character in the download URL link is a bad url for the single sign on.
Would like to check if the ID generated by DWR can be changed to be without the ~ character. Or is there a way to amend the download URL link?

Thanks.

Almost everything in DWR is pluggable through init-params, see:
http://directwebremoting.org/dwr/documentation/server/configuration/servlet/plugin.html

You could choose to either plug in your own DownloadManager or IdGenerator to customize the id string. I would suggest the following:

  • class MyDownloadManager extends InMemoryDownloadManager … (this is the default manager)
  • let the setIdGenerator method wrap the supplied IdGenerator with an instance of your making that performs your replacements on the id string
  • configure MyDownloadManager as DownloadManager

Best regards
Mike Wilson

Hi Mike,
Thank you for your reply. However, i do not understand the second point. Do I overwrite the setIdGenerator method with my own id?

I hacked up the below code to better illustrate what I mean. Note that this is just a sketch that I haven’t tested but the major parts should be ok.

public class MyDownloadManager extends InMemoryDownloadManager {
	@Override
	public void setIdGenerator(IdGenerator globalIdGenerator) {
        // Install IdGenerator changes only for downloads by wrapping the global instance
        super.setIdGenerator(new MyIdGeneratorWrapper(globalIdGenerator));
	}
}

public class MyIdGeneratorWrapper implements IdGenerator {
    private IdGenerator realIdGenerator;
    public MyIdGeneratorWrapper(IdGenerator realIdGenerator) {
        this.realIdGenerator = realIdGenerator;
    }
    @Override
    public String generate() {
        return realIdGenerator.generate().replaceAll("~", "_");
    }
}