csf*_*csf 3 wicket web.xml wicket-6 spring-restcontroller spring-rest
我有可以正常工作的 Apache Wiket + Spring Web 应用程序。目前 Spring 使用 DI 框架并过滤 Mobile 访问。我们计划在我们的应用程序中使用 Spring Rest,你能告诉我如何在我们现有的 web xml 中做到这一点。
最初,现有的 Web 会话将使用 Rest Api 来访问数据(使用 ajax 调用的 ui 页面),因此我希望 Rest 控制器能够访问现有的 Wicket http 会话(如果使用登录)。例如:来自现有http 会话的rest 调用应该能够访问现有http 会话。任何的想法 ?感谢并感谢您的时间。
我的想法是使用org.springframework.web.servlet.DispatcherServlet带有标签的' ',但是我怀疑我是否希望以这种方式共享同一个会话?
我现有的web.xml(工作)
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:myapp-spring-config.xml
</param-value>
</context-param>
<filter>
<filter-name>myapp</filter-name>
<filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class>
<init-param>
<param-name>applicationFactoryClassName</param-name>
<param-value>org.apache.wicket.spring.SpringWebApplicationFactory</param-value>
</init-param>
</filter>
<filter>
<filter-name>myappMobileRequestFilter</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>myappMobileRequestFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>ERROR</dispatcher>
</filter-mapping>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<listener>
<listener-class>
org.springframework.web.context.request.RequestContextListener
</listener-class>
Run Code Online (Sandbox Code Playgroud)
为我解决了!感谢 martin-g 将我引导至WicketSessionFilter. 我在这里发布答案以供将来任何人参考或建议(如果需要)。
我/我们web.xml对上面发布的“ ”添加所做的更改web.xml。
<filter>
<filter-name>SessionFilter</filter-name>
<filter-class>org.apache.wicket.protocol.http.servlet.WicketSessionFilter</filter-class>
<init-param>
<param-name>filterName</param-name>
<param-value>myapp</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>SessionFilter</filter-name>
<url-pattern>/rest/*</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>mvc-dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>mvc-dispatcher</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
Run Code Online (Sandbox Code Playgroud)
如您所见,我添加了一个WicketSessionFilterto 来过滤/rest/*由 spring 消耗的请求DispatcherServlet。
如果你想在 Spring rest 控制器中访问 spring 会话,你所要做的就是如下:
@RestController
@RequestMapping("/service")
public class TestServiceController {
@RequestMapping(value = "/getValue/{name}", method = RequestMethod.GET)
@SuppressWarnings("unused")
public String getValue(@PathVariable String name,HttpServletRequest request, HttpServletResponse response) {
HttpSession session = request.getSession(false);
WebSession wicketSession = session.getAttribute("wicket:wicket.myapp:session");
//rest of the code here ........
return result;
}
Run Code Online (Sandbox Code Playgroud)
Spring-rest & Wicket 从此过上了幸福的生活......
| 归档时间: |
|
| 查看次数: |
1806 次 |
| 最近记录: |