我对activiti比较陌生。我们有一个使用旧版本的 activiti 和 spring boot 的项目。我们已经升级,但我看到了问题。
测试代码:
@Value("${activiti.sys_username}")
private String username;
@Value("${activiti.password}")
private String password;
@Test
public void givenAuthenticated_whenRejectingLevel1_then() throws Exception {
mvc.perform(post("/runtime/process-instances")
.header(HttpHeaders.AUTHORIZATION, Base64.getEncoder().encodeToString(String.format("BASIC %s:%s", username, password).getBytes()))
.contentType(MediaType.APPLICATION_JSON)
.content("""
{
"processDefinitionId" : "isae3402"
}
"""))
.andExpect(status().isOk());
}
但是在日志中我收到了 404:
MockHttpServletRequest:
HTTP Method = POST
Request URI = /runtime/process-instances
Parameters = {}
Headers = [Content-Type:"application/json;charset=UTF-8", Authorization:"QkFTSUMgYWN0aXZpdGk6SDRja3Rpdml0aSE=", Content-Length:"42"]
Body = {
"processDefinitionId" : "isae3402"
}
Session Attrs = {org.springframework.security.web.csrf.HttpSessionCsrfTokenRepository.CSRF_TOKEN=org.springframework.security.web.csrf.DefaultCsrfToken@51d26fed}
Handler:
Type = null
Async:
Async started = false
Async result = null
Resolved Exception:
Type = null
ModelAndView:
View name = null
View = null
Model = null
FlashMap:
Attributes = null
MockHttpServletResponse:
Status = 403
Error message = Forbidden
Headers = [Vary:"Origin", "Access-Control-Request-Method", "Access-Control-Request-Headers", X-Content-Type-Options:"nosniff", X-XSS-Protection:"1; mode=block", Cache-Control:"no-cache, no-store, max-age=0, must-revalidate", Pragma:"no-cache", Expires:"0", X-Frame-Options:"DENY"]
Content type = null
Body =
Forwarded URL = null
Redirected URL = null
Cookies = []
我看到在旧版本的 activiti 中有一个 starter rest artifact 但在我使用的 activiti 版本中不可用。
有什么我想念的吗?我看过 github 上的示例项目,但没有一个有测试:-/
我期待在调用端点时返回 200:
/runtime/process-instances
编辑 1:尝试更改 URL,因为我在网上看到了一些示例,但仍然收到 404
2023-04-05 11:16:54.165 DEBUG 19532 --- [ main] org.springframework.test.context.cache : Spring test ApplicationContext cache statistics: [DefaultContextCache@1fd77205 size = 1, maxSize = 32, parentContextCount = 0, hitCount = 15, missCount = 1]
2023-04-05 11:16:54.193 DEBUG 19532 --- [ main] o.s.security.web.FilterChainProxy : Securing POST /activiti-rest/service/runtime/process-instances
2023-04-05 11:16:54.202 DEBUG 19532 --- [ main] s.s.w.c.SecurityContextPersistenceFilter : Set SecurityContextHolder to empty SecurityContext
2023-04-05 11:16:54.207 DEBUG 19532 --- [ main] o.s.s.w.a.AnonymousAuthenticationFilter : Set SecurityContextHolder to anonymous SecurityContext
2023-04-05 11:16:54.224 DEBUG 19532 --- [ main] o.s.s.w.a.i.FilterSecurityInterceptor : Authorized filter invocation [POST /activiti-rest/service/runtime/process-instances] with attributes [permitAll]
2023-04-05 11:16:54.225 DEBUG 19532 --- [ main] o.s.security.web.FilterChainProxy : Secured POST /activiti-rest/service/runtime/process-instances
2023-04-05 11:16:54.228 DEBUG 19532 --- [ main] o.s.t.web.servlet.TestDispatcherServlet : POST "/activiti-rest/service/runtime/process-instances", parameters={}
2023-04-05 11:16:54.243 DEBUG 19532 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped to ResourceHttpRequestHandler [classpath [META-INF/resources/], classpath [resources/], classpath [static/], classpath [public/], ServletContext [/]]
2023-04-05 11:16:54.249 DEBUG 19532 --- [ main] o.s.w.s.r.ResourceHttpRequestHandler : Resource not found
2023-04-05 11:16:54.253 DEBUG 19532 --- [ main] w.c.HttpSessionSecurityContextRepository : Did not store anonymous SecurityContext
2023-04-05 11:16:54.254 DEBUG 19532 --- [ main] o.s.t.web.servlet.TestDispatcherServlet : Completed 404 NOT_FOUND
2023-04-05 11:16:54.255 DEBUG 19532 --- [ main] w.c.HttpSessionSecurityContextRepository : Did not store anonymous SecurityContext
2023-04-05 11:16:54.255 DEBUG 19532 --- [ main] s.s.w.c.SecurityContextPersistenceFilter : Cleared SecurityContextHolder to complete request