Java Code Examples for org.springframework.http.converter.StringHttpMessageConverter#setWriteAcceptCharset()

The following examples show how to use org.springframework.http.converter.StringHttpMessageConverter#setWriteAcceptCharset() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WebConfiguration.java    From java-platform with Apache License 2.0 6 votes vote down vote up
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
	StringHttpMessageConverter stringConverter = new StringHttpMessageConverter(Charset.forName("UTF-8"));
	stringConverter.setWriteAcceptCharset(false);

	converters.add(new ByteArrayHttpMessageConverter());
	converters.add(stringConverter);
	converters.add(new ResourceHttpMessageConverter());
	converters.add(new SourceHttpMessageConverter<Source>());
	converters.add(new AllEncompassingFormHttpMessageConverter());
}
 
Example 2
Source File: RequestMappingHandlerAdapter.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
public RequestMappingHandlerAdapter() {
	StringHttpMessageConverter stringHttpMessageConverter = new StringHttpMessageConverter();
	stringHttpMessageConverter.setWriteAcceptCharset(false);  // see SPR-7316

	this.messageConverters = new ArrayList<HttpMessageConverter<?>>(4);
	this.messageConverters.add(new ByteArrayHttpMessageConverter());
	this.messageConverters.add(stringHttpMessageConverter);
	this.messageConverters.add(new SourceHttpMessageConverter<Source>());
	this.messageConverters.add(new AllEncompassingFormHttpMessageConverter());
}
 
Example 3
Source File: OneClickImporterControllerTest.java    From molgenis with GNU Lesser General Public License v3.0 5 votes vote down vote up
@BeforeEach
void before() {
  OneClickImporterController oneClickImporterController =
      new OneClickImporterController(
          menuReaderService, fileStore, oneClickImportJobExecutionFactory, jobExecutor);

  when(menuReaderService.findMenuItemPath(OneClickImporterController.ONE_CLICK_IMPORTER))
      .thenReturn("/test-path");
  when(localeResolver.resolveLocale(any())).thenReturn(new Locale("nl"));
  when(appSettings.getLanguageCode()).thenReturn("en");
  User user = mock(User.class);
  when(user.isSuperuser()).thenReturn(false);
  when(userAccountService.getCurrentUser()).thenReturn(user);

  OneClickImportJobExecution jobExecution = mock(OneClickImportJobExecution.class);
  when(oneClickImportJobExecutionFactory.create()).thenReturn(jobExecution);

  EntityType oneClickImportJobExecutionEntityType = mock(EntityType.class);
  when(jobExecution.getEntityType()).thenReturn(oneClickImportJobExecutionEntityType);
  when(jobExecution.getIdValue()).thenReturn("id_1");
  when(oneClickImportJobExecutionEntityType.getId()).thenReturn("jobExecutionId");

  StringHttpMessageConverter stringConverter = new StringHttpMessageConverter();
  stringConverter.setWriteAcceptCharset(false);

  mockMvc =
      MockMvcBuilders.standaloneSetup(oneClickImporterController)
          .setLocaleResolver(localeResolver)
          .setMessageConverters(gsonHttpMessageConverter, stringConverter)
          .build();
}
 
Example 4
Source File: RestUtil.java    From XPagesExtensionLibrary with Apache License 2.0 5 votes vote down vote up
private List<HttpMessageConverter<?>> getFormPartsMessageConverters() {
	List<HttpMessageConverter<?>> partConverters = new ArrayList<HttpMessageConverter<?>>();
	StringHttpMessageConverter stringConverter = new StringHttpMessageConverter();
	stringConverter.setSupportedMediaTypes(Collections.singletonList(JsonUtil.JSON_MEDIA_TYPE));
	stringConverter.setWriteAcceptCharset(false);
	partConverters.add(stringConverter);
	partConverters.add(new ResourceHttpMessageConverter());
	partConverters.add(new UploadApplicationPayloadHttpMessageConverter());
	return partConverters;
}
 
Example 5
Source File: WebConfig.java    From nakadi with MIT License 5 votes vote down vote up
@Override
protected void configureMessageConverters(final List<HttpMessageConverter<?>> converters) {
    final StringHttpMessageConverter stringConverter = new StringHttpMessageConverter();
    stringConverter.setWriteAcceptCharset(false);

    converters.add(new ByteArrayHttpMessageConverter());
    converters.add(stringConverter);
    converters.add(new ResourceHttpMessageConverter());
    converters.add(new SourceHttpMessageConverter<>());

    converters.add(mappingJackson2HttpMessageConverter());
    super.configureMessageConverters(converters);
}
 
Example 6
Source File: RESTFacade.java    From zstack with Apache License 2.0 5 votes vote down vote up
static TimeoutRestTemplate createRestTemplate(int readTimeout, int connectTimeout) {
    HttpComponentsClientHttpRequestFactory factory = new TimeoutHttpComponentsClientHttpRequestFactory();
    factory.setReadTimeout(readTimeout);
    factory.setConnectTimeout(connectTimeout);

    SSLContext sslContext = DefaultSSLVerifier.getSSLContext(DefaultSSLVerifier.trustAllCerts);

    if (sslContext != null) {
        factory.setHttpClient(HttpClients.custom()
                .setSSLHostnameVerifier(new NoopHostnameVerifier())
                .setSSLContext(sslContext)
                .build());
    }

    TimeoutRestTemplate template = new TimeoutRestTemplate(factory);

    StringHttpMessageConverter stringHttpMessageConverter = new StringHttpMessageConverter(StandardCharsets.UTF_8);
    stringHttpMessageConverter.setWriteAcceptCharset(true);
    for (int i = 0; i < template.getMessageConverters().size(); i++) {
        if (template.getMessageConverters().get(i) instanceof StringHttpMessageConverter) {
            template.getMessageConverters().remove(i);
            template.getMessageConverters().add(i, stringHttpMessageConverter);
            break;
        }
    }

    return template;
}
 
Example 7
Source File: FormHttpMessageConverter.java    From onetwo with Apache License 2.0 5 votes vote down vote up
public FormHttpMessageConverter() {
	this.supportedMediaTypes.add(MediaType.APPLICATION_FORM_URLENCODED);
	this.supportedMediaTypes.add(MediaType.MULTIPART_FORM_DATA);

	StringHttpMessageConverter stringHttpMessageConverter = new StringHttpMessageConverter();
	stringHttpMessageConverter.setWriteAcceptCharset(false);  // see SPR-7316

	this.partConverters.add(new ByteArrayHttpMessageConverter());
	this.partConverters.add(stringHttpMessageConverter);
	this.partConverters.add(new ResourceHttpMessageConverter());

	applyDefaultCharset();
}
 
Example 8
Source File: ManualConfiguration.java    From riptide with MIT License 5 votes vote down vote up
@Bean
public ClientHttpMessageConverters exampleHttpMessageConverters(final ObjectMapper mapper) {
    final StringHttpMessageConverter textConverter = new StringHttpMessageConverter();
    textConverter.setWriteAcceptCharset(false);

    return new ClientHttpMessageConverters(Arrays.asList(
            new MappingJackson2HttpMessageConverter(mapper),
            Streams.streamConverter(mapper),
            new SOAPHttpMessageConverter(),
            new SOAPFaultHttpMessageConverter(),
            textConverter
    ));
}
 
Example 9
Source File: WebMvcConfiguration.java    From bonita-ui-designer with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Spring MVC use a default objectMapper. Objects passed to and returned from the controllers are converted to and from HTTP messages by HttpMessageConverter
 * instances. We must use our {{@link #objectMapper}} because of the subtypes.... So we declare two message converters
 * <ul>
 * <li>StringHttpMessageConverter to format the String sent by HTTP like a JSON object representation</li>
 * <li>MappingJackson2HttpMessageConverter to use our {{@link #objectMapper}}</li>
 * </ul>To declare a JacksonHttpMessageConvet
 */
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
    //Add a converter for the String sent via HTTP
    StringHttpMessageConverter stringConverter = new StringHttpMessageConverter(Charset.forName("UTF-8"));
    stringConverter.setWriteAcceptCharset(false);  // see SPR-7316
    converters.add(stringConverter);

    //Use our custom Jackson serializer
    MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter = new MappingJackson2HttpMessageConverter(objectMapper);
    mappingJackson2HttpMessageConverter.setSupportedMediaTypes(supportedMediaTypes());
    converters.add(mappingJackson2HttpMessageConverter);

}
 
Example 10
Source File: SpringParameterProvider.java    From katharsis-framework with Apache License 2.0 5 votes vote down vote up
private List<HttpMessageConverter<?>> getHttpMessageConverters() {
    StringHttpMessageConverter stringHttpMessageConverter = new StringHttpMessageConverter();
    stringHttpMessageConverter.setWriteAcceptCharset(false);  // see SPR-7316

    List<HttpMessageConverter<?>> converters = new ArrayList<>(4);
    converters.add(new ByteArrayHttpMessageConverter());
    converters.add(stringHttpMessageConverter);
    converters.add(new SourceHttpMessageConverter<>());
    converters.add(new AllEncompassingFormHttpMessageConverter());

    return converters;
}
 
Example 11
Source File: ExceptionHandlerExceptionResolver.java    From java-technology-stack with MIT License 5 votes vote down vote up
public ExceptionHandlerExceptionResolver() {
	StringHttpMessageConverter stringHttpMessageConverter = new StringHttpMessageConverter();
	stringHttpMessageConverter.setWriteAcceptCharset(false);  // see SPR-7316

	this.messageConverters = new ArrayList<>();
	this.messageConverters.add(new ByteArrayHttpMessageConverter());
	this.messageConverters.add(stringHttpMessageConverter);
	try {
		this.messageConverters.add(new SourceHttpMessageConverter<>());
	}
	catch (Error err) {
		// Ignore when no TransformerFactory implementation is available
	}
	this.messageConverters.add(new AllEncompassingFormHttpMessageConverter());
}
 
Example 12
Source File: ExceptionHandlerExceptionResolver.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
public ExceptionHandlerExceptionResolver() {
	StringHttpMessageConverter stringHttpMessageConverter = new StringHttpMessageConverter();
	stringHttpMessageConverter.setWriteAcceptCharset(false); // See SPR-7316

	this.messageConverters = new ArrayList<HttpMessageConverter<?>>();
	this.messageConverters.add(new ByteArrayHttpMessageConverter());
	this.messageConverters.add(stringHttpMessageConverter);
	this.messageConverters.add(new SourceHttpMessageConverter<Source>());
	this.messageConverters.add(new AllEncompassingFormHttpMessageConverter());
}
 
Example 13
Source File: AnnotationMethodHandlerAdapter.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
public AnnotationMethodHandlerAdapter() {
	// no restriction of HTTP methods by default
	super(false);

	// See SPR-7316
	StringHttpMessageConverter stringHttpMessageConverter = new StringHttpMessageConverter();
	stringHttpMessageConverter.setWriteAcceptCharset(false);
	this.messageConverters = new HttpMessageConverter<?>[] {
		new ByteArrayHttpMessageConverter(), stringHttpMessageConverter,
		new SourceHttpMessageConverter<Source>(),
		new org.springframework.http.converter.xml.XmlAwareFormHttpMessageConverter() };
}
 
Example 14
Source File: RequestMappingHandlerAdapter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public RequestMappingHandlerAdapter() {
	StringHttpMessageConverter stringHttpMessageConverter = new StringHttpMessageConverter();
	stringHttpMessageConverter.setWriteAcceptCharset(false);  // see SPR-7316

	this.messageConverters = new ArrayList<HttpMessageConverter<?>>(4);
	this.messageConverters.add(new ByteArrayHttpMessageConverter());
	this.messageConverters.add(stringHttpMessageConverter);
	this.messageConverters.add(new SourceHttpMessageConverter<Source>());
	this.messageConverters.add(new AllEncompassingFormHttpMessageConverter());
}
 
Example 15
Source File: ExceptionHandlerExceptionResolver.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public ExceptionHandlerExceptionResolver() {
	StringHttpMessageConverter stringHttpMessageConverter = new StringHttpMessageConverter();
	stringHttpMessageConverter.setWriteAcceptCharset(false);  // see SPR-7316

	this.messageConverters = new ArrayList<HttpMessageConverter<?>>();
	this.messageConverters.add(new ByteArrayHttpMessageConverter());
	this.messageConverters.add(stringHttpMessageConverter);
	this.messageConverters.add(new SourceHttpMessageConverter<Source>());
	this.messageConverters.add(new AllEncompassingFormHttpMessageConverter());
}
 
Example 16
Source File: AnnotationMethodHandlerAdapter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public AnnotationMethodHandlerAdapter() {
	// no restriction of HTTP methods by default
	super(false);

	// See SPR-7316
	StringHttpMessageConverter stringHttpMessageConverter = new StringHttpMessageConverter();
	stringHttpMessageConverter.setWriteAcceptCharset(false);
	this.messageConverters = new HttpMessageConverter<?>[] {
		new ByteArrayHttpMessageConverter(), stringHttpMessageConverter,
		new SourceHttpMessageConverter<Source>(),
		new org.springframework.http.converter.xml.XmlAwareFormHttpMessageConverter() };
}
 
Example 17
Source File: RequestMappingHandlerAdapter.java    From java-technology-stack with MIT License 5 votes vote down vote up
public RequestMappingHandlerAdapter() {
	StringHttpMessageConverter stringHttpMessageConverter = new StringHttpMessageConverter();
	stringHttpMessageConverter.setWriteAcceptCharset(false);  // see SPR-7316

	this.messageConverters = new ArrayList<>(4);
	this.messageConverters.add(new ByteArrayHttpMessageConverter());
	this.messageConverters.add(stringHttpMessageConverter);
	try {
		this.messageConverters.add(new SourceHttpMessageConverter<>());
	}
	catch (Error err) {
		// Ignore when no TransformerFactory implementation is available
	}
	this.messageConverters.add(new AllEncompassingFormHttpMessageConverter());
}
 
Example 18
Source File: WebMvcConfigurationSupport.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Adds a set of default HttpMessageConverter instances to the given list.
 * Subclasses can call this method from {@link #configureMessageConverters(List)}.
 * @param messageConverters the list to add the default message converters to
 */
protected final void addDefaultHttpMessageConverters(List<HttpMessageConverter<?>> messageConverters) {
	StringHttpMessageConverter stringConverter = new StringHttpMessageConverter();
	stringConverter.setWriteAcceptCharset(false);

	messageConverters.add(new ByteArrayHttpMessageConverter());
	messageConverters.add(stringConverter);
	messageConverters.add(new ResourceHttpMessageConverter());
	messageConverters.add(new SourceHttpMessageConverter<Source>());
	messageConverters.add(new AllEncompassingFormHttpMessageConverter());

	if (romePresent) {
		messageConverters.add(new AtomFeedHttpMessageConverter());
		messageConverters.add(new RssChannelHttpMessageConverter());
	}

	if (jackson2XmlPresent) {
		messageConverters.add(new MappingJackson2XmlHttpMessageConverter(
				Jackson2ObjectMapperBuilder.xml().applicationContext(this.applicationContext).build()));
	}
	else if (jaxb2Present) {
		messageConverters.add(new Jaxb2RootElementHttpMessageConverter());
	}

	if (jackson2Present) {
		messageConverters.add(new MappingJackson2HttpMessageConverter(
				Jackson2ObjectMapperBuilder.json().applicationContext(this.applicationContext).build()));
	}
	else if (gsonPresent) {
		messageConverters.add(new GsonHttpMessageConverter());
	}
}
 
Example 19
Source File: CustomMVCConfiguration.java    From spring-boot-starter-netty with GNU General Public License v3.0 4 votes vote down vote up
@Bean
public HttpMessageConverter<String> responseBodyConverter() {
    StringHttpMessageConverter conv = new StringHttpMessageConverter(Charset.forName("UTF-8"));
    conv.setWriteAcceptCharset(false);
    return conv;
}