开发者

Programmatic configuration of Struts in Jetty

I'm trying to configure struts2 within Jetty programmatically, but am having a lot of trouble doing so.

As these are for 'unit' tests, I don't wish to use spring or any other 'DI Framework'.

here is what i have - (this is using my wrapper around jetty, so the method calls don't quite match up to Jetty's, but you can easily get the idea)

JspServlet servlet = new JspServlet();

server.mount("*.jsp", servlet)
    .withInitParameter("trimSpaces", "true")
    .withInitParameter("mappedFile", "true")
    .withInitParameter("classdebuginfo", "true")
    .withInitParameter("keepGenerated", "true")
    .withInitParameter("development", "true")
    .withInitParameter("scratchDir", "./target/scratch");

    server.getContextHandler().setResourceBase("some-place/WebContent");

    server.filter("/*", new FilterDispatcher())

    server.start();

That will fail, complaining that spring isn't set up. I've experimented with fiddling with subclasses of FilterDispatcher, returning a MockConfigur开发者_高级运维ation, and other things, but I'm not really making much progress...

 private static class MyFilterDispatcher extends FilterDispatcher {
    private MyFilterDispatcher(ActionMapper mapper) {
        setActionMapper(mapper);
    }

    @Override
    protected Dispatcher createDispatcher(FilterConfig filterConfig) {
        Dispatcher dispatcher = super.createDispatcher(filterConfig);
        ConfigurationManager configurationManager = new ConfigurationManager("filterdispatcher");
        configurationManager.setConfiguration(new MockConfiguration());
        dispatcher.setConfigurationManager(configurationManager);
        return dispatcher;
    }
}

So then you have to implement an ActionMapper, which if you do, then you get an UOE from your MockConfiguration for getRuntimeConfiguration - so I think that's probably the wrong path...

If anybody has done this, would very much appreciate any leads.

Thanks!!

James

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜