问题描述
我在 kotlin 网络应用程序中配置了一个独立的 yahoo elide 实例。
我想为每个请求添加一个过滤器。我想扩展 JsonApiEndpoint
类并调整 uriInfo
属性,但此时我唯一可以采取行动来做到这一点的是 requestUri
,但那是哈克。
@Singleton
@Produces(Elide.JSONAPI_CONTENT_TYPE)
@Path("/")
class YetAnotherjsonApiEndpoint
@Inject constructor(elide: Elide) : JsonApiEndpoint(elide) {
@GET
@Path("{path:.*}")
override fun get(
@PathParam("path") path: String,@Context uriInfo: UriInfo,@Context headers: HttpHeaders,@Context securityContext: SecurityContext
): Response {
val newUriInfo = UriRoutingContext(
ContainerRequest(
uriInfo.baseUri,uriInfo.requestUri,// hack here with something like "&filter[foo]=bar" ?
"GET",securityContext,null,null
)
)
return super.get(path,newUriInfo,headers,securityContext)
}
}
所以我根本不喜欢这种方式,无论如何,即使我在 serlvet 的 init-param
中定义了这个包,我也从来没有设法让它注册,这意味着常规的 JsonApiEndpoint
结束了每次都直接调用。
class ApiElideServlet : ServletContainer() {
override fun init() {
val threadPoolSize = 6
servletContext.setAttribute("asyncExecutor",Executors.newFixedThreadPool(threadPoolSize))
servletContext.setAttribute("asyncUpdater",Executors.newFixedThreadPool(threadPoolSize))
servletContext.setAttribute("elideStandalonesettings",Settings())
super.init()
}
}
web.xml
<servlet>
<servlet-name>ElideServlet</servlet-name>
<servlet-class>my.package.ApiElideServlet</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>my.package.resources</param-value>
</init-param>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>com.yahoo.elide.standalone.config.ElideResourceConfig</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
我肯定在文档中遗漏了一些明显的东西......是否有一种干净的方法?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)