如何将 Hessian 与 Guice 集成?

发布于 2024-09-17 08:09:59 字数 571 浏览 5 评论 0原文

我们正在为一个即将到来的项目寻找技术,我真的想使用 Guice 作为我们的依赖注入框架,我也想使用 Hessian 进行客户端/服务器通信,但它似乎与 Guice 不兼容。

public class WebMobule extends ServletModule {

@Override
protected void configureServlets() {

    serve("/fileupload").with(FileUploadServlet.class);

    // this doesn't work! AuthenticationServlet extends HessianServlet
    // HessianServlet extends GenericServlet - Guice wants something that extends
    // HttpServlet
    serve("/authentication").with(AuthenticationServlet.class); 

}

有没有人设法解决这个问题 - 如果是的话你是怎么做到的?

欢呼

菲尔

We're looking at technologies for an up and coming project here and I really want to use Guice as our dependency injection framework, I also want to use Hessian for client/server comms, but it doesn't seem to be compatible with Guice.

public class WebMobule extends ServletModule {

@Override
protected void configureServlets() {

    serve("/fileupload").with(FileUploadServlet.class);

    // this doesn't work! AuthenticationServlet extends HessianServlet
    // HessianServlet extends GenericServlet - Guice wants something that extends
    // HttpServlet
    serve("/authentication").with(AuthenticationServlet.class); 

}

Has anyone managed to solve this problem - if so how did you do it?

cheers

Phil

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

孤檠 2024-09-24 08:09:59

我将编写一个自定义 HessianHttpServlet,它扩展 HttpServlet 并将方法调用委托给封装的 HessianServlet。通过这种方式,Guice 服务调用将得到满足,并且您将使用 HessianServlet 行为。

I would write a custom HessianHttpServlet which extends HttpServlet and delegates method calls to a encapsulated HessianServlet. In this way the Guice serve call will be satiated and you will be using HessianServlet behavior.

醉酒的小男人 2024-09-24 08:09:59

它需要一些工作,但从根本上我解决了这个问题(感谢语法!):

@Singleton
public class AuthenticationWrapperServlet extends HttpServlet {

    private static final Logger LOG = Logger.getLogger(HessianDelegateServlet.class);

    // this is the HessianServlet
    private AuthenticationServlet authenticationServlet;

    @Override
    public void init(ServletConfig config) throws ServletException {
        LOG.trace("init() in");
        try {
            if (authenticationServlet == null) {
                authenticationServlet = new AuthenticationServlet();
            }
            authenticationServlet.init(config);
        } catch (Throwable t) {
            LOG.error("Error initialising hessian servlet", t);
            throw new ServletException(t);
        }
        LOG.trace("init() out");
    }

    @Override
    public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException {

        try {
            authenticationServlet.service(request, response);
        } catch (Throwable t) {
            LOG.error("Error calling service()", t);
            throw new ServletException(t);
        }

    }
}

It needs some work, but fundamentally I solved the problem with this (thanks Syntax!):

@Singleton
public class AuthenticationWrapperServlet extends HttpServlet {

    private static final Logger LOG = Logger.getLogger(HessianDelegateServlet.class);

    // this is the HessianServlet
    private AuthenticationServlet authenticationServlet;

    @Override
    public void init(ServletConfig config) throws ServletException {
        LOG.trace("init() in");
        try {
            if (authenticationServlet == null) {
                authenticationServlet = new AuthenticationServlet();
            }
            authenticationServlet.init(config);
        } catch (Throwable t) {
            LOG.error("Error initialising hessian servlet", t);
            throw new ServletException(t);
        }
        LOG.trace("init() out");
    }

    @Override
    public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException {

        try {
            authenticationServlet.service(request, response);
        } catch (Throwable t) {
            LOG.error("Error calling service()", t);
            throw new ServletException(t);
        }

    }
}
此生挚爱伱 2024-09-24 08:09:59

我创建了一个小型开源项目,可以轻松集成 hessian 和 guice。您可以使用基于注释的配置,如下所示:
WebService:

@HessianWebService
public class UserServiceImpl implements UserService {
    ...
}

Guice 配置:

public class WebServiceGuiceServletContextListener extends GuiceServletContextListener {
    @Override
    protected Injector getInjector() {
        return Guice.createInjector(
                /* your guice modules */
                new HessianWebServicesModule("your web service implementations package")
        );
    }
}

或使用 EDSL 的手动方式:

public class WebServiceGuiceServletContextListener extends GuiceServletContextListener {
    @Override
    protected Injector getInjector() {
        return Guice.createInjector(
                /* your guice modules */
                new HessianWebServicesModule(){
                    @Override
                    protected void configureHessianWebServices() {
                        serveHessianWebService(UserService.class).usingUrl("/Users");
                    }
                }
        );
    }
}

此处提供更多信息、配置选项和完整示例:https://bitbucket.org/richard_hauswald/hessian-guice/

I created a little open source project which enables easy integration of hessian and guice. You can use annotation based configuration like this:
WebService:

@HessianWebService
public class UserServiceImpl implements UserService {
    ...
}

Guice configuration:

public class WebServiceGuiceServletContextListener extends GuiceServletContextListener {
    @Override
    protected Injector getInjector() {
        return Guice.createInjector(
                /* your guice modules */
                new HessianWebServicesModule("your web service implementations package")
        );
    }
}

or the manual way using the EDSL:

public class WebServiceGuiceServletContextListener extends GuiceServletContextListener {
    @Override
    protected Injector getInjector() {
        return Guice.createInjector(
                /* your guice modules */
                new HessianWebServicesModule(){
                    @Override
                    protected void configureHessianWebServices() {
                        serveHessianWebService(UserService.class).usingUrl("/Users");
                    }
                }
        );
    }
}

More information, configuration options and complete examples are available here: https://bitbucket.org/richard_hauswald/hessian-guice/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文