- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
简而言之,我在 jar 中有一个 Jersey REST 服务,我需要使用与服务注释中定义的映射不同的映射将其部署在我的 web 应用程序中。在服务中,我有@ApplicationPath("/rest")
和 @Path("/foo")
.但是,传入的请求将采用以下形式:http://example.com/delegate/rest/foo
(注意,delegate 不是上下文路径,而是映射到 ROOT webapp 中的 servlet,它加载 session 信息并将请求代理到我的 webapp,这意味着我不能像通常那样用 @ApplicationPath
覆盖 servlet-mapping
案件)。所以,我想做的是:
@PreMatching
@Priority( 500 )
public class DelegateRemappingFilter implements ContainerRequestFilter {
private static final Logger LOGGER = LoggerFactory.getLogger( DelegateRemappingFilter.class );
@Override
public void filter( ContainerRequestContext requestContext ) throws IOException {
UriInfo uriInfo = requestContext.getUriInfo();
// convert baseUri to http://example.com/delegate/rest
URI baseUri = uriInfo.getBaseUriBuilder()
.path( uriInfo.getPathSegments().get( 0 ).getPath() ).build();
URI requestUri = uriInfo.getRequestUri();
// As expected, this will print out
// setRequestUri("http://example.com/delegate/rest","http://example.com/delegate/rest/foo")
LOGGER.debug( "setRequestUri(\"{}\",\"{}\")", baseUri, requestUri );
requestContext.setRequestUri( baseUri, requestUri );
}
}
@PreMatching
中 URI 的路径部分?筛选?我认为这就是这种类型的过滤器的用途......
最佳答案
我讨厌在发布后几分钟找到自己的答案...无论如何,baseUri
必须以 /
结尾.所以改变这个:
URI baseUri = uriInfo.getBaseUriBuilder()
.path( uriInfo.getPathSegments().get( 0 ).getPath() ).build();
URI baseUri = uriInfo.getBaseUriBuilder()
.path( uriInfo.getPathSegments().get( 0 ).getPath() + "/" ).build();
关于rest - 使用 PreMatching 过滤器更改 uri 路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34090950/
简而言之,我在 jar 中有一个 Jersey REST 服务,我需要使用与服务注释中定义的映射不同的映射将其部署在我的 web 应用程序中。在服务中,我有@ApplicationPath("/res
有没有办法从 pcrecpp 获得 Perl 的 PREMATCH ($`) 和 POSTMATCH ($') 的 C++ 等价物?我会对指向此处的字符串、char * 或成对的 indices/st
我需要实现一个 Jersey 过滤器 (ContainerRequestFilter),它需要在 pre-matching 阶段调用,但只适用于某些资源。 预匹配部分可以通过使用@PreMatchin
我如何判断我的 perl 进程是否使用了正则表达式变量 $PREMATCH/$MATCH/$POSTMATCH(或简短的等效项$`/$'/$&)? 我的 perl webapp 大量使用了 Data:
我是一名优秀的程序员,十分优秀!