下面列出了org.springframework.http.MediaType#APPLICATION_XML 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Construct a new instance with an {@link ExtensionRegistryInitializer}
* that allows the registration of message extensions.
*/
public ProtobufHttpMessageConverter(ExtensionRegistryInitializer registryInitializer) {
super(PROTOBUF, MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML);
if (registryInitializer != null) {
registryInitializer.initializeExtensionRegistry(this.extensionRegistry);
}
}
/**
* Construct a new instance with an {@link ExtensionRegistryInitializer}
* that allows the registration of message extensions.
*/
public ProtobufHttpMessageConverter(ExtensionRegistryInitializer registryInitializer) {
super(PROTOBUF, MediaType.TEXT_PLAIN, MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON);
if (registryInitializer != null) {
registryInitializer.initializeExtensionRegistry(this.extensionRegistry);
}
}
@Test
void shouldHandleRequest() {
final XMLErrorMessageRenderer messageRenderer = new XMLErrorMessageRenderer(MediaType.APPLICATION_XML);
assertThat(messageRenderer.getContentType()).isEqualTo(MediaType.APPLICATION_XML);
assertThat(messageRenderer.getFormattedMessage("You are not authorized to access this URL. Some<xml>!")).isEqualTo("<access-denied>\n" +
" <message>You are not authorized to access this URL. Some<xml>!</message>\n" +
"</access-denied>\n");
}
@Override
protected MediaType handleNoMatch(NativeWebRequest request, String mappingKey) {
return "xml".equals(mappingKey) ? MediaType.APPLICATION_XML : null;
}
@Override
protected MediaType handleNoMatch(NativeWebRequest request, String mappingKey) {
return "xml".equals(mappingKey) ? MediaType.APPLICATION_XML : null;
}
@Test
public void testNotEquals() {
MethodParameterDetails methodParameterDetails1 = new MethodParameterDetails(methodParameter, MediaType.APPLICATION_JSON, new FilterFields());
MethodParameterDetails methodParameterDetails2 = new MethodParameterDetails(methodParameter, MediaType.APPLICATION_XML, null);
assertNotEquals(methodParameterDetails1, methodParameterDetails2);
}
@Test
public void testNotEqualsMediaType() {
MethodParameterDetails methodParameterDetails1 = new MethodParameterDetails(methodParameter, MediaType.APPLICATION_JSON, null);
MethodParameterDetails methodParameterDetails2 = new MethodParameterDetails(methodParameter, MediaType.APPLICATION_XML, null);
assertNotEquals(methodParameterDetails1, methodParameterDetails2);
}
@GetMapping("/re/void/xml")
public void voidWithResponseEntityExceptionAsXml() {
throw new HandledResponseEntityException("bad state", MediaType.APPLICATION_XML);
}
@Override
protected MediaType handleNoMatch(NativeWebRequest request, String mappingKey) {
return "xml".equals(mappingKey) ? MediaType.APPLICATION_XML : null;
}
/**
* Protected constructor that sets the {@link #setSupportedMediaTypes(java.util.List) supportedMediaTypes}
* to {@code text/xml} and {@code application/xml}, and {@code application/*-xml}.
*/
protected AbstractXmlHttpMessageConverter() {
super(MediaType.APPLICATION_XML, MediaType.TEXT_XML, new MediaType("application", "*+xml"));
}
/**
* Sets the {@link #setSupportedMediaTypes(java.util.List) supportedMediaTypes}
* to {@code text/xml} and {@code application/xml}, and {@code application/*-xml}.
*/
public SourceHttpMessageConverter() {
super(MediaType.APPLICATION_XML, MediaType.TEXT_XML, new MediaType("application", "*+xml"));
}
/**
* Protected constructor that sets the {@link #setSupportedMediaTypes(java.util.List) supportedMediaTypes}
* to {@code text/xml} and {@code application/xml}, and {@code application/*-xml}.
*/
protected AbstractXmlHttpMessageConverter() {
super(MediaType.APPLICATION_XML, MediaType.TEXT_XML, new MediaType("application", "*+xml"));
}
/**
* Sets the {@link #setSupportedMediaTypes(java.util.List) supportedMediaTypes}
* to {@code text/xml} and {@code application/xml}, and {@code application/*-xml}.
*/
public SourceHttpMessageConverter() {
super(MediaType.APPLICATION_XML, MediaType.TEXT_XML, new MediaType("application", "*+xml"));
}
/**
* Protected constructor that sets the {@link #setSupportedMediaTypes(java.util.List) supportedMediaTypes}
* to {@code text/xml} and {@code application/xml}, and {@code application/*-xml}.
*/
protected AbstractXmlHttpMessageConverter() {
super(MediaType.APPLICATION_XML, MediaType.TEXT_XML, new MediaType("application", "*+xml"));
}
/**
* Sets the {@link #setSupportedMediaTypes(java.util.List) supportedMediaTypes}
* to {@code text/xml} and {@code application/xml}, and {@code application/*-xml}.
*/
public SourceHttpMessageConverter() {
super(MediaType.APPLICATION_XML, MediaType.TEXT_XML, new MediaType("application", "*+xml"));
}
/**
* Protected constructor that sets the {@link #setSupportedMediaTypes(java.util.List) supportedMediaTypes}
* to {@code text/xml} and {@code application/xml}, and {@code application/*-xml}.
*/
protected AbstractXmlHttpMessageConverter() {
super(MediaType.APPLICATION_XML, MediaType.TEXT_XML, new MediaType("application", "*+xml"));
}
/**
* Sets the {@link #setSupportedMediaTypes(java.util.List) supportedMediaTypes}
* to {@code text/xml} and {@code application/xml}, and {@code application/*-xml}.
*/
public SourceHttpMessageConverter() {
super(MediaType.APPLICATION_XML, MediaType.TEXT_XML, new MediaType("application", "*+xml"));
}
/**
* ContentTypeがapplication/xmlのヘッダとリクエストデータを設定します。
* @param entity リクエストデータ
* @param <T> リクエストデータの型
* @return このユーティリティを返します。
*/
public static <T> Entity<T> xml(final T entity) {
return new Entity<T>(entity, MediaType.APPLICATION_XML);
}