Skip to main content
Formatted method parameters, removed noisy 'final' declarations
Source Link

You can actually simplify your life here since all you are doing is submitting a form that contains some fields and file. You don't need @RequestBody for what you are trying to do. You can use regular Spring MVC features, so your controller method would look like:

@ResponseBody public WebResponse<Boolean> updateEUSettings(final   Locale locale, @Valid final EUPSettingsWrapperLocale endUserPortalSettingsWrapperlocale,   @Valid EUPSettingsWrapper endUserPortalSettingsWrapper,    @RequestParam(value = "file1", required = true) final MultipartFile logo  ) { } 

The client that submits the request to this controller will need to have a form with enctype="multipart/form-data".

In your Spring MVC test you would write something like this:

getMockMvc().perform(fileUpload(uri).file("file1", "some-content".getBytes()) .param("someEuSettingsProperty", "someValue") .param("someOtherEuSettingsProperty", "someOtherValue") .accept(MediaType.APPLICATION_JSON) .contentType(MediaType.MULTIPART_FORM_DATA)) .andExpect(status().isOk()); 

You can actually simplify your life here since all you are doing is submitting a form that contains some fields and file. You don't need @RequestBody for what you are trying to do. You can use regular Spring MVC features, so your controller method would look like:

@ResponseBody public WebResponse<Boolean> updateEUSettings(final Locale locale, @Valid final EUPSettingsWrapper endUserPortalSettingsWrapper,   @RequestParam(value = "file1", required = true) final MultipartFile logo) { } 

The client that submits the request to this controller will need to have a form with enctype="multipart/form-data".

In your Spring MVC test you would write something like this:

getMockMvc().perform(fileUpload(uri).file("file1", "some-content".getBytes()) .param("someEuSettingsProperty", "someValue") .param("someOtherEuSettingsProperty", "someOtherValue") .accept(MediaType.APPLICATION_JSON) .contentType(MediaType.MULTIPART_FORM_DATA)) .andExpect(status().isOk()); 

You can actually simplify your life here since all you are doing is submitting a form that contains some fields and file. You don't need @RequestBody for what you are trying to do. You can use regular Spring MVC features, so your controller method would look like:

@ResponseBody public WebResponse<Boolean> updateEUSettings(   Locale locale, @Valid EUPSettingsWrapper endUserPortalSettingsWrapper,    @RequestParam(value = "file1", required = true) MultipartFile logo  ) { } 

The client that submits the request to this controller will need to have a form with enctype="multipart/form-data".

In your Spring MVC test you would write something like this:

getMockMvc().perform(fileUpload(uri).file("file1", "some-content".getBytes()) .param("someEuSettingsProperty", "someValue") .param("someOtherEuSettingsProperty", "someOtherValue") .accept(MediaType.APPLICATION_JSON) .contentType(MediaType.MULTIPART_FORM_DATA)) .andExpect(status().isOk()); 
Source Link
geoand
  • 64.8k
  • 24
  • 185
  • 201

You can actually simplify your life here since all you are doing is submitting a form that contains some fields and file. You don't need @RequestBody for what you are trying to do. You can use regular Spring MVC features, so your controller method would look like:

@ResponseBody public WebResponse<Boolean> updateEUSettings(final Locale locale, @Valid final EUPSettingsWrapper endUserPortalSettingsWrapper, @RequestParam(value = "file1", required = true) final MultipartFile logo) { } 

The client that submits the request to this controller will need to have a form with enctype="multipart/form-data".

In your Spring MVC test you would write something like this:

getMockMvc().perform(fileUpload(uri).file("file1", "some-content".getBytes()) .param("someEuSettingsProperty", "someValue") .param("someOtherEuSettingsProperty", "someOtherValue") .accept(MediaType.APPLICATION_JSON) .contentType(MediaType.MULTIPART_FORM_DATA)) .andExpect(status().isOk());