I am trying to execute a POST request at a URL outside the current context, and it seems like Spring cannot understand it.
Test code:
String content = mvc
.perform(post("http://some-external-url.com:8080/somepath)
.header("Authorization", authorization)
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
.param("username", username)
.param("password", password)
.andExpect(status().isOk())
.andReturn().getResponse().getContentAsString();
Works like a charm in the current context. But the remote service cannot be reached at all. It seems that the http://some-external-url.com:8080 "part is being ignored.
Mock Creation Code:
mvc = MockMvcBuilders.webAppContextSetup(context).build();
Is there any way to make it work? Because using the standard Java class HttpUrlConnection is a huge pain.
source
share