Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 招摇过市:如何记录HTTP头参数,该参数仅由拦截器/过滤器使用,并且不出现在方法签名中_Java_Jersey_Jax Rs_Swagger_Swagger Ui - Fatal编程技术网

Java 招摇过市:如何记录HTTP头参数,该参数仅由拦截器/过滤器使用,并且不出现在方法签名中

Java 招摇过市:如何记录HTTP头参数,该参数仅由拦截器/过滤器使用,并且不出现在方法签名中,java,jersey,jax-rs,swagger,swagger-ui,Java,Jersey,Jax Rs,Swagger,Swagger Ui,我有一个Jersey REST方法和一个自定义过滤器,它作为REST方法的注释应用: @Priority(FilterPriorities.USER_ID_VALIDATOR) @Provider @UserIdCheck public class UserIdValidatorFilter implements ContainerRequestFilter { @Override public void filter(final ContainerRequestContext

我有一个Jersey REST方法和一个自定义过滤器,它作为REST方法的注释应用:

@Priority(FilterPriorities.USER_ID_VALIDATOR)
@Provider
@UserIdCheck
public class UserIdValidatorFilter implements ContainerRequestFilter {

    @Override
    public void filter(final ContainerRequestContext requestContext) throws IOException {
        // checks presence of user-id
        ...

        // checks presence of sso-token
        String ssoToken = requestContext.getHeaderString(CustomHttpHeader.SSO_TOKEN);
        ...

        // validates SSO token against used ID
        ...
    }
}
这是我的休息方法:

@POST
@Path("/upload")
@Consumes(ExtendedMediaType.MULTIPART_FORM_DATA)
@ApiOperation(
        value = "Saves the uploaded image",
        notes = "Returns the unique id of the image.",
        response = String.class)
@ApiResponses(value = {
        @ApiResponse(code = 200, message = "The uploaded image has been saved.", response = String.class),
        @ApiResponse(code = FileTooLargeException.HTTP_STATUS, message = FileTooLargeException.SWAGGER_API_RESPONSE_MESSAGE, response = ErrorInfo.class),
        @ApiResponse(code = InvalidMediaTypeError.HTTP_STATUS, message = InvalidMediaTypeError.SWAGGER_API_RESPONSE_MESSAGE, response = ErrorInfo.class),
        @ApiResponse(code = MissingHttpHeaderException.HTTP_STATUS, message = MissingHttpHeaderException.SWAGGER_API_RESPONSE_MESSAGE, response = ErrorInfo.class),
        @ApiResponse(code = UnauthorizedRequestException.HTTP_STATUS, message = UnauthorizedRequestException.SWAGGER_API_RESPONSE_MESSAGE, response = ErrorInfo.class)})
@UserIdCheck
@Override
public String uploadImage(
        @ApiParam(value = "id of the authenticated user", required = true) @HeaderParam(CustomHttpHeader.USER_ID) final Long userId,
        @ApiParam(value = "file to upload", required = true) @FormDataParam("file") final InputStream inputStream,
        @ApiParam(value = "details of the uploaded file", required = true) @FormDataParam("file") final FormDataContentDisposition fileDetail) {

        // do something here...
    }
}
我的自定义注释(
@UserIdCheck
)检查HTTP头上是否显示sso令牌,以及该令牌是否有效

我的问题是REST方法不使用此SSO令牌,因此它不会出现在方法签名上,但它需要出现在HTTP头上,否则HTTP请求会被筛选器阻止

我无法通过swagger UI发出有效的测试请求,因为SSO_令牌字段未出现在swagger测试页面上。当然,这一重要领域在招摇过市的文档中缺失了

我不想将此变量添加到方法签名中,因为它仅由筛选器使用,并且在方法体中不需要此值


处理此用例的正确方法是什么?

您是否找到了解决方案?如果是,请将其作为答案共享好吗?我在方法签名中添加了必填字段:(