编程语言
首页 > 编程语言> > java-dropwizard 0.7 @Session注释

java-dropwizard 0.7 @Session注释

作者:互联网

我正在尝试让Dropwizard与会议合作.
我读过0.7版,Dropwizard添加了会话支持.
从发行说明中:
“增加了对HTTP会话的支持.将带注释的参数添加到资源方法:@Session HttpSession会话中,以注入会话上下文.”

我有一个示例资源类,它从http get请求获取用户/密码,并且我想在会话中保存用户名:

@GET
public Response auth(@QueryParam("user") String user, @QueryParam("password") String password,         @Session HttpSession session) throws URISyntaxException {
    URI rootUri = getApplicationRootUri();
    if(!user.equals(config.getUser()) || !password.equals(config.getPassword())) {

        return Response.temporaryRedirect(rootUri).build();
    }
    session.setAttribute("user", user);
    return Response.temporaryRedirect( new URI("/../index.html")).build();
}

尝试从我的应用程序登录时,我得到:

ERROR [2014-05-17 10:33:45,244] com.sun.jersey.spi.container.ContainerRequest: A message body reader for Java class javax.servlet.http.HttpSession, and Java type interface javax.servlet.http.HttpSession, and MIME media type application/octet-stream was not found.

我尝试从github上的dropwizard源中查找一些测试,似乎@Session注释的使用方式与我的代码相同.

有任何想法吗?

谢谢!

解决方法:

在应用程序类中,我要做的是(dropwizard 0.7):

    environment.jersey().register(HttpSessionProvider.class);
    environment.servlets().setSessionHandler(new SessionHandler());

标签:dropwizard,session,java
来源: https://codeday.me/bug/20191029/1960806.html