Skip to content

Commit

Permalink
DATAREST-686 - Set default encoding for resource description message …
Browse files Browse the repository at this point in the history
…source to UTF-8.
  • Loading branch information
odrotbohm committed Nov 2, 2015
1 parent 1a68c94 commit 9689b67
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ public MessageSourceAccessor resourceDescriptionMessageSourceAccessor() {
ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
messageSource.setBasename("classpath:rest-messages");
messageSource.setCommonMessages(propertiesFactoryBean.getObject());
messageSource.setDefaultEncoding("UTF-8");

return new MessageSourceAccessor(messageSource);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.MessageSourceAccessor;
import org.springframework.core.convert.ConversionService;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort.Direction;
Expand All @@ -53,6 +54,7 @@
import org.springframework.hateoas.mvc.TypeConstrainedMappingJackson2HttpMessageConverter;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.util.MultiValueMap;
import org.springframework.web.util.UriComponentsBuilder;

Expand Down Expand Up @@ -207,6 +209,19 @@ public void hasConvertersForPointAndDistance() {
assertThat(service.canConvert(Distance.class, String.class), is(true));
}

/**
* @see DATAREST-686
*/
@Test
public void defaultsEncodingForMessageSourceToUtfEight() {

MessageSourceAccessor accessor = context.getBean("resourceDescriptionMessageSourceAccessor",
MessageSourceAccessor.class);
Object messageSource = ReflectionTestUtils.getField(accessor, "messageSource");

assertThat((String) ReflectionTestUtils.getField(messageSource, "defaultEncoding"), is("UTF-8"));
}

@Configuration
@Import(RepositoryRestMvcConfiguration.class)
static class ExtendingConfiguration extends RepositoryRestConfigurerAdapter {
Expand Down

0 comments on commit 9689b67

Please sign in to comment.