paulcwarren/spring-content

POST to content-property without content-type results in NPE / HTTP-500

tgeens opened this issue · 1 comments

Describe the bug

(this is a minor low-priority bug)

User/developer uses Spring Content REST and sends a POST to a content property, but forgets to set Content-Type header.

This results in an HTTP-500 with this stacktrace:

Request processing failed; nested exception is java.lang.NullPointerException: Cannot invoke "org.springframework.http.MediaType.toString()" because "sourceMimeType" is null
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.NullPointerException: Cannot invoke "org.springframework.http.MediaType.toString()" because "sourceMimeType" is null
[...snip...]
Caused by: java.lang.NullPointerException: Cannot invoke "org.springframework.http.MediaType.toString()" because "sourceMimeType" is null
	at internal.org.springframework.content.rest.contentservice.ContentStoreContentService.setContent(ContentStoreContentService.java:155)
	at internal.org.springframework.content.rest.controllers.StoreRestController.handleMultipart(StoreRestController.java:217)
[...snip...]

Expected behavior
HTTP-400

Steps to reproduce

@Test
void postInvoiceContent_missingContentType_http400() throws Exception {
    mockMvc.perform(post("/invoices/{id}/content", invoiceNumber).content("some content"))
        .andExpect(status().isBadRequest());
}

Reproduced with 2.7.0/2.9.0 and from inspection of the source code, this issue is also present in main