Here are the examples of the java api org.springframework.http.MediaType.APPLICATION_XML taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
122 Examples
19
Source : RequestMappingInfoHandlerMappingTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
@Test
public void getHandlerProducibleMediaTypesAttribute() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/content");
request.addHeader("Accept", "application/xml");
this.handlerMapping.getHandler(request);
String name = HandlerMapping.PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE;
replacedertEquals(Collections.singleton(MediaType.APPLICATION_XML), request.getAttribute(name));
request = new MockHttpServletRequest("GET", "/content");
request.addHeader("Accept", "application/json");
this.handlerMapping.getHandler(request);
replacedertNull("Negated expression shouldn't be listed as producible type", request.getAttribute(name));
}
19
Source : RequestMappingHandlerMappingTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
// SPR-14988
@Test
public void getMappingOverridesConsumesFromTypeLevelAnnotation() throws Exception {
RequestMappingInfo requestMappingInfo = replacedertComposedAnnotationMapping(RequestMethod.POST);
ConsumesRequestCondition condition = requestMappingInfo.getConsumesCondition();
replacedertEquals(Collections.singleton(MediaType.APPLICATION_XML), condition.getConsumableMediaTypes());
}
19
Source : WebMvcConfigurationSupport.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
protected Map<String, MediaType> getDefaultMediaTypes() {
Map<String, MediaType> map = new HashMap<>(4);
if (romePresent) {
map.put("atom", MediaType.APPLICATION_ATOM_XML);
map.put("rss", MediaType.APPLICATION_RSS_XML);
}
if (jaxb2Present || jackson2XmlPresent) {
map.put("xml", MediaType.APPLICATION_XML);
}
if (jackson2Present || gsonPresent || jsonbPresent) {
map.put("json", MediaType.APPLICATION_JSON);
}
if (jackson2SmilePresent) {
map.put("smile", MediaType.valueOf("application/x-jackson-smile"));
}
if (jackson2CborPresent) {
map.put("cbor", MediaType.valueOf("application/cbor"));
}
return map;
}
19
Source : RequestMappingInfoHandlerMappingTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
// SPR-9603
@Test
public void getHandlerRequestMethodMatchFalsePositive() {
ServerWebExchange exchange = MockServerWebExchange.from(get("/users").accept(MediaType.APPLICATION_XML));
this.handlerMapping.registerHandler(new UserController());
Mono<Object> mono = this.handlerMapping.getHandler(exchange);
StepVerifier.create(mono).expectError(NotAcceptableStatusException.clreplaced).verify();
}
19
Source : RequestMappingInfoHandlerMappingTests.java
with Apache License 2.0
from SourceHot
with Apache License 2.0
from SourceHot
private void testHttpMediaTypeNotSupportedException(String url) throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest("PUT", url);
request.setContentType("application/json");
replacedertThatExceptionOfType(HttpMediaTypeNotSupportedException.clreplaced).isThrownBy(() -> this.handlerMapping.getHandler(request)).satisfies(ex -> replacedertThat(ex.getSupportedMediaTypes()).containsExactly(MediaType.APPLICATION_XML));
}
19
Source : WebMvcConfigurationSupport.java
with Apache License 2.0
from SourceHot
with Apache License 2.0
from SourceHot
protected Map<String, MediaType> getDefaultMediaTypes() {
Map<String, MediaType> map = new HashMap<>(4);
if (romePresent) {
map.put("atom", MediaType.APPLICATION_ATOM_XML);
map.put("rss", MediaType.APPLICATION_RSS_XML);
}
if (jaxb2Present || jackson2XmlPresent) {
map.put("xml", MediaType.APPLICATION_XML);
}
if (jackson2Present || gsonPresent || jsonbPresent) {
map.put("json", MediaType.APPLICATION_JSON);
}
if (jackson2SmilePresent) {
map.put("smile", MediaType.valueOf("application/x-jackson-smile"));
}
if (jackson2CborPresent) {
map.put("cbor", MediaType.APPLICATION_CBOR);
}
return map;
}
19
Source : AbstractHttpAccessLoggingFilter.java
with Apache License 2.0
from penggle
with Apache License 2.0
from penggle
/**
* 从HttpServletRequest中提取请求参数(包括请求体中的参数)
* @param request
* @param context
* @return
* @throws Exception
*/
protected HttpRequestParameter extractRequestParameter(HttpServletRequest request, HttpAccessLogContext context) throws IOException {
HttpRequestParameter parameter = new HttpRequestParameter();
Map<String, String[]> originalParamMap = request.getParameterMap();
Map<String, String> paramMap = new HashMap<String, String>();
if (originalParamMap != null && !originalParamMap.isEmpty()) {
for (Map.Entry<String, String[]> entry : originalParamMap.entrySet()) {
paramMap.put(entry.getKey(), getStringParameterValue(entry.getValue()));
}
}
parameter.setParameter(paramMap);
MediaType contentType = context.getHttpAccessLog().getRequestContentType();
if (contentType != null) {
ContentCachingRequestWrapper requestToUse = ServletWebUtils.getContentCachingRequestWrapper(request);
if (requestToUse != null) {
if (contentType.includes(MediaType.APPLICATION_JSON)) {
// JSON类型的报文
String charset = ServletWebUtils.getCharacterEncoding(request, GlobalConstants.DEFAULT_CHARSET);
byte[] bytes = requestToUse.getContentAsByteArray();
if (!ArrayUtils.isEmpty(bytes)) {
String bodyStr = new String(bytes, charset);
Object bodyObj = bodyStr;
if (JsonUtils.isJsonArray(bodyStr)) {
// JSON Array String -> List<Map<String,Object>>
bodyObj = JsonUtils.json2Object(bodyStr, new TypeReference<List<Map<String, Object>>>() {
});
} else if (JsonUtils.isJsonObject(bodyStr)) {
// JSON Object String -> Map<String,Object>
bodyObj = JsonUtils.json2Object(bodyStr, new TypeReference<Map<String, Object>>() {
});
}
parameter.setBody(bodyObj);
}
} else if (contentType.includes(MediaType.APPLICATION_XML)) {
// XML类型的报文
String charset = ServletWebUtils.getCharacterEncoding(request, GlobalConstants.DEFAULT_CHARSET);
byte[] bytes = requestToUse.getContentAsByteArray();
if (!ArrayUtils.isEmpty(bytes)) {
String bodyStr = new String(bytes, charset);
parameter.setBody(bodyStr);
}
} else {
LOGGER.warn(">>> Found unsupported Content-Type({}) request and ignored!", contentType);
}
}
}
return excludeRequestParameter(parameter, context);
}
19
Source : RequestMappingInfoHandlerMappingTests.java
with Apache License 2.0
from langtianya
with Apache License 2.0
from langtianya
@Test
public void producibleMediaTypesAttribute() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/content");
request.addHeader("Accept", "application/xml");
this.handlerMapping.getHandler(request);
replacedertEquals(Collections.singleton(MediaType.APPLICATION_XML), request.getAttribute(HandlerMapping.PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE));
request = new MockHttpServletRequest("GET", "/content");
request.addHeader("Accept", "application/json");
this.handlerMapping.getHandler(request);
replacedertNull("Negated expression should not be listed as a producible type", request.getAttribute(HandlerMapping.PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE));
}
19
Source : WebMvcConfigurationSupport.java
with Apache License 2.0
from langtianya
with Apache License 2.0
from langtianya
protected Map<String, MediaType> getDefaultMediaTypes() {
Map<String, MediaType> map = new HashMap<String, MediaType>();
if (romePresent) {
map.put("atom", MediaType.APPLICATION_ATOM_XML);
map.put("rss", MediaType.valueOf("application/rss+xml"));
}
if (jaxb2Present || jackson2XmlPresent) {
map.put("xml", MediaType.APPLICATION_XML);
}
if (jackson2Present || gsonPresent) {
map.put("json", MediaType.APPLICATION_JSON);
}
return map;
}
19
Source : SerializationHelper.java
with Apache License 2.0
from ch4mpy
with Apache License 2.0
from ch4mpy
public <T> String asXmlnString(final T payload) throws Exception {
return replacedtring(payload, MediaType.APPLICATION_XML);
}
19
Source : GetCustomPaymentStatusIT.java
with Apache License 2.0
from adorsys
with Apache License 2.0
from adorsys
// Bulk
@Test
void bulk_Xml() throws Exception {
getPaymentStatus(PaymentType.BULK, MediaType.APPLICATION_XML);
}
19
Source : GetCustomPaymentStatusIT.java
with Apache License 2.0
from adorsys
with Apache License 2.0
from adorsys
// Periodic
@Test
void periodic_Xml() throws Exception {
getPaymentStatus(PaymentType.PERIODIC, MediaType.APPLICATION_XML);
}
19
Source : GetCustomPaymentStatusIT.java
with Apache License 2.0
from adorsys
with Apache License 2.0
from adorsys
// Single
@Test
void single_Xml() throws Exception {
getPaymentStatus(PaymentType.SINGLE, MediaType.APPLICATION_XML);
}
19
Source : GetCustomPaymentIT.java
with Apache License 2.0
from adorsys
with Apache License 2.0
from adorsys
// Periodic
@Test
void periodic_Xml() throws Exception {
getPayment(PaymentType.PERIODIC, PERIODIC_PAYMENT_CUSTOM_REQUEST_XML_PATH, MediaType.APPLICATION_XML);
}
19
Source : GetCustomPaymentIT.java
with Apache License 2.0
from adorsys
with Apache License 2.0
from adorsys
// Bulk
@Test
void bulk_Xml() throws Exception {
getPayment(PaymentType.BULK, BULK_PAYMENT_CUSTOM_REQUEST_XML_PATH, MediaType.APPLICATION_XML);
}
19
Source : GetCustomPaymentIT.java
with Apache License 2.0
from adorsys
with Apache License 2.0
from adorsys
// Single
@Test
void single_Xml() throws Exception {
getPayment(PaymentType.SINGLE, SINGLE_PAYMENT_CUSTOM_REQUEST_XML_PATH, MediaType.APPLICATION_XML);
}
18
Source : WeiXinPayTestController.java
with Apache License 2.0
from zhuoqianmingyue
with Apache License 2.0
from zhuoqianmingyue
/**
* 正式支付
* @return
*/
@RequestMapping("/nativePay")
public String nativePay() {
/*配置微信支付基础信息参数*/
Map<String, String> requestData = new HashMap<String, String>();
// 公众账号ID
requestData.put("appid", weiXinPayProperties.getAppid());
// 商户号
requestData.put("mch_id", weiXinPayProperties.getMchId());
// 随机字符串 32位以内
requestData.put("nonce_str", RandomUtil.randomString(15));
// APP和网页支付提交用户端ip,Native支付填调用微信支付API的机器IP。
requestData.put("spbill_create_ip", "15.23.160.111");
// 交易类型 扫码支付
requestData.put("trade_type", "NATIVE");
/*配置微信支付自定义支付信息参数*/
requestData.put("attach", "附加数据远洋返回");
// 商品简单描述
requestData.put("body", "订单号 BW_000001");
// 商户订单号
requestData.put("out_trade_no", "BW_000001");
// 标价金额 按照分进行计算
requestData.put("total_fee", WeiXinUtil.getMoney("0.01"));
// 通知地址 异步接收微信支付结果通知的回调地址必须外网访问 不能携带参数
requestData.put("notify_url", "www.beiwaiclreplaced.com");
/*配置微信支付sign信息参数*/
String sign = null;
String payUrl = null;
if (Boolean.valueOf(weiXinPayProperties.getUseSandbox())) {
// 生成签名
sign = WeiXinUtil.generateSign(requestData, weiXinPayProperties.getKey());
payUrl = UNIFIEDORDERURL;
} else {
// 生成签名
sign = WeiXinUtil.generateSign(requestData, weiXinPayProperties.getSandboxKey());
payUrl = SANDBOXUNIFIEDORDERURL;
}
requestData.put("sign", sign);
/*将map信息转换成String*/
String mapToXmlStr = XmlUtil.mapToXmlStr(requestData, "xml");
/*调用微信统一下单Api将mapToXmlStr作为参数*/
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_XML);
HttpEnreplacedy<String> formEnreplacedy = new HttpEnreplacedy<>(mapToXmlStr, headers);
ResponseEnreplacedy<String> postForEnreplacedy = restTemplate.postForEnreplacedy(payUrl, formEnreplacedy, String.clreplaced);
// 获取微信返回的信息
String returnXmlString = postForEnreplacedy.getBody();
Map<String, Object> xmlToMap = XmlUtil.xmlToMap(returnXmlString);
String returnCode = (String) xmlToMap.get("return_code");
if ("SUCCESS".equals(returnCode)) {
String codeUrl = (String) xmlToMap.get("code_url");
return codeUrl;
}
return "";
}
18
Source : ResponseEntityExceptionHandlerTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
@Test
public void handleHttpMediaTypeNotSupported() {
List<MediaType> acceptable = Arrays.asList(MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_XML);
Exception ex = new HttpMediaTypeNotSupportedException(MediaType.APPLICATION_JSON, acceptable);
ResponseEnreplacedy<Object> responseEnreplacedy = testException(ex);
replacedertEquals(acceptable, responseEnreplacedy.getHeaders().getAccept());
}
18
Source : RequestMappingInfoHandlerMappingTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
@Test
public void getHandlerProducibleMediaTypesAttribute() {
ServerWebExchange exchange = MockServerWebExchange.from(get("/content").accept(MediaType.APPLICATION_XML));
this.handlerMapping.getHandler(exchange).block();
String name = HandlerMapping.PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE;
replacedertEquals(Collections.singleton(MediaType.APPLICATION_XML), exchange.getAttributes().get(name));
exchange = MockServerWebExchange.from(get("/content").accept(MediaType.APPLICATION_JSON));
this.handlerMapping.getHandler(exchange).block();
replacedertNull("Negated expression shouldn't be listed as producible type", exchange.getAttributes().get(name));
}
18
Source : RequestMappingMessageConversionIntegrationTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
// SPR-16759
@Test
public void personTransformWithMonoAndXml() throws Exception {
replacedertEquals(new Person("ROBERT"), performPost("/person-transform/mono", MediaType.APPLICATION_XML, new Person("Robert"), MediaType.APPLICATION_XML, Person.clreplaced).getBody());
}
18
Source : MockHttpServletRequestBuilderTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
@Test
public void acceptHeader() {
this.builder.accept(MediaType.TEXT_HTML, MediaType.APPLICATION_XML);
MockHttpServletRequest request = this.builder.buildRequest(this.servletContext);
List<String> accept = Collections.list(request.getHeaders("Accept"));
List<MediaType> result = MediaType.parseMediaTypes(accept.get(0));
replacedertEquals(1, accept.size());
replacedertEquals("text/html", result.get(0).toString());
replacedertEquals("application/xml", result.get(1).toString());
}
18
Source : XmlContentTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
@Test
public void xpathIsEqualTo() {
this.client.get().uri("/persons").accept(MediaType.APPLICATION_XML).exchange().expectStatus().isOk().expectBody().xpath("/").exists().xpath("/persons").exists().xpath("/persons/person").exists().xpath("/persons/person").nodeCount(3).xpath("/persons/person[1]/name").isEqualTo("Jane").xpath("/persons/person[2]/name").isEqualTo("Jason").xpath("/persons/person[3]/name").isEqualTo("John");
}
18
Source : XmlContentTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
@Test
public void xpathMatches() {
this.client.get().uri("/persons").accept(MediaType.APPLICATION_XML).exchange().expectStatus().isOk().expectBody().xpath("//person/name").string(startsWith("J"));
}
18
Source : XmlContentTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
@Test
public void xmlContent() {
this.client.get().uri("/persons").accept(MediaType.APPLICATION_XML).exchange().expectStatus().isOk().expectBody().xml(persons_XML);
}
18
Source : XmlContentTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
@Test
public void xpathContainsSubstringViaRegex() {
this.client.get().uri("/persons/John").accept(MediaType.APPLICATION_XML).exchange().expectStatus().isOk().expectBody().xpath("//name[contains(text(), 'oh')]").exists();
}
18
Source : HeaderAssertionTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
@Test
public void contentTypeCompatibleWith() {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_XML);
Headerreplacedertions replacedertions = headerreplacedertions(headers);
// Success
replacedertions.contentTypeCompatibleWith(MediaType.parseMediaType("application/*"));
try {
replacedertions.contentTypeCompatibleWith(MediaType.TEXT_XML);
fail("MediaTypes not compatible expected");
} catch (replacedertionError error) {
Throwable cause = error.getCause();
replacedertNotNull(cause);
replacedertEquals("Response header 'Content-Type'=[application/xml] " + "is not compatible with [text/xml]", cause.getMessage());
}
}
18
Source : EmployeeFunctionalConfig.java
with Apache License 2.0
from springdoc
with Apache License 2.0
from springdoc
@Bean
RouterFunction<ServerResponse> updateEmployeeRoute() {
return route(POST("/employees/update").and(accept(MediaType.APPLICATION_XML)), req -> req.body(BodyExtractors.toMono(Employee.clreplaced)).doOnNext(employeeRepository()::updateEmployee).then(ok().build())).withAttribute(OPERATION_ATTRIBUTE, operationBuilder().beanClreplaced(EmployeeRepository.clreplaced).beanMethod("updateEmployee"));
}
18
Source : RequestMappingInfoHandlerMappingTests.java
with Apache License 2.0
from SourceHot
with Apache License 2.0
from SourceHot
private void testHttpMediaTypeNotAcceptableException(String url) throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest("GET", url);
request.addHeader("Accept", "application/json");
replacedertThatExceptionOfType(HttpMediaTypeNotAcceptableException.clreplaced).isThrownBy(() -> this.handlerMapping.getHandler(request)).satisfies(ex -> replacedertThat(ex.getSupportedMediaTypes()).containsExactly(MediaType.APPLICATION_XML));
}
18
Source : ResponseEntityExceptionHandlerTests.java
with Apache License 2.0
from SourceHot
with Apache License 2.0
from SourceHot
@Test
public void handleHttpMediaTypeNotSupported() {
List<MediaType> acceptable = Arrays.asList(MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_XML);
Exception ex = new HttpMediaTypeNotSupportedException(MediaType.APPLICATION_JSON, acceptable);
ResponseEnreplacedy<Object> responseEnreplacedy = testException(ex);
replacedertThat(responseEnreplacedy.getHeaders().getAccept()).isEqualTo(acceptable);
}
18
Source : RequestMappingHandlerMappingTests.java
with Apache License 2.0
from SourceHot
with Apache License 2.0
from SourceHot
// SPR-14988
@Test
public void getMappingOverridesConsumesFromTypeLevelAnnotation() throws Exception {
RequestMappingInfo requestMappingInfo = replacedertComposedAnnotationMapping(RequestMethod.POST);
ConsumesRequestCondition condition = requestMappingInfo.getConsumesCondition();
replacedertThat(condition.getConsumableMediaTypes()).isEqualTo(Collections.singleton(MediaType.APPLICATION_XML));
}
18
Source : HttpEntityMethodProcessorMockTests.java
with Apache License 2.0
from SourceHot
with Apache License 2.0
from SourceHot
// gh-23287
@Test
public void shouldFailWithServerErrorIfContentTypeFromProducibleAttribute() {
Set<MediaType> mediaTypes = Collections.singleton(MediaType.APPLICATION_XML);
servletRequest.setAttribute(PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE, mediaTypes);
ResponseEnreplacedy<String> returnValue = ResponseEnreplacedy.ok().body("<foo/>");
given(stringHttpMessageConverter.canWrite(String.clreplaced, TEXT_PLAIN)).willReturn(true);
given(stringHttpMessageConverter.getSupportedMediaTypes()).willReturn(Collections.singletonList(TEXT_PLAIN));
replacedertThatThrownBy(() -> processor.handleReturnValue(returnValue, returnTypeResponseEnreplacedy, mavContainer, webRequest)).isInstanceOf(HttpMessageNotWritableException.clreplaced).hasMessageContaining("with preset Content-Type");
}
18
Source : HttpEntityMethodProcessorMockTests.java
with Apache License 2.0
from SourceHot
with Apache License 2.0
from SourceHot
// gh-23205
@Test
public void shouldFailWithServerErrorIfContentTypeFromResponseEnreplacedy() {
ResponseEnreplacedy<String> returnValue = ResponseEnreplacedy.ok().contentType(MediaType.APPLICATION_XML).body("<foo/>");
given(stringHttpMessageConverter.canWrite(String.clreplaced, TEXT_PLAIN)).willReturn(true);
given(stringHttpMessageConverter.getSupportedMediaTypes()).willReturn(Collections.singletonList(TEXT_PLAIN));
replacedertThatThrownBy(() -> processor.handleReturnValue(returnValue, returnTypeResponseEnreplacedy, mavContainer, webRequest)).isInstanceOf(HttpMessageNotWritableException.clreplaced).hasMessageContaining("with preset Content-Type");
}
18
Source : RequestMappingInfoHandlerMappingTests.java
with Apache License 2.0
from SourceHot
with Apache License 2.0
from SourceHot
@Test
public void getHandlerProducibleMediaTypesAttribute() {
ServerWebExchange exchange = MockServerWebExchange.from(get("/content").accept(MediaType.APPLICATION_XML));
this.handlerMapping.getHandler(exchange).block();
String name = HandlerMapping.PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE;
replacedertThat(exchange.getAttributes().get(name)).isEqualTo(Collections.singleton(MediaType.APPLICATION_XML));
exchange = MockServerWebExchange.from(get("/content").accept(MediaType.APPLICATION_JSON));
this.handlerMapping.getHandler(exchange).block();
replacedertThat(exchange.getAttributes().get(name)).as("Negated expression shouldn't be listed as producible type").isNull();
}
18
Source : ResponseEntityResultHandlerTests.java
with Apache License 2.0
from SourceHot
with Apache License 2.0
from SourceHot
// gh-23205
@Test
public void handleWithPresetContentTypeShouldFailWithServerError() {
ResponseEnreplacedy<String> value = ResponseEnreplacedy.ok().contentType(MediaType.APPLICATION_XML).body("<foo/>");
MethodParameter returnType = on(TestController.clreplaced).resolveReturnType(enreplacedy(String.clreplaced));
HandlerResult result = handlerResult(value, returnType);
MockServerWebExchange exchange = MockServerWebExchange.from(get("/path"));
ResponseEnreplacedyResultHandler resultHandler = new ResponseEnreplacedyResultHandler(Collections.singletonList(new EncoderHttpMessageWriter<>(CharSequenceEncoder.textPlainOnly())), new RequestedContentTypeResolverBuilder().build());
StepVerifier.create(resultHandler.handleResult(exchange, result)).consumeErrorWith(ex -> replacedertThat(ex).isInstanceOf(HttpMessageNotWritableException.clreplaced).hasMessageContaining("with preset Content-Type")).verify();
}
18
Source : ResponseEntityResultHandlerTests.java
with Apache License 2.0
from SourceHot
with Apache License 2.0
from SourceHot
// gh-23287
@Test
public void handleWithProducibleContentTypeShouldFailWithServerError() {
ResponseEnreplacedy<String> value = ResponseEnreplacedy.ok().body("<foo/>");
MethodParameter returnType = on(TestController.clreplaced).resolveReturnType(enreplacedy(String.clreplaced));
HandlerResult result = handlerResult(value, returnType);
MockServerWebExchange exchange = MockServerWebExchange.from(get("/path"));
Set<MediaType> mediaTypes = Collections.singleton(MediaType.APPLICATION_XML);
exchange.getAttributes().put(PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE, mediaTypes);
ResponseEnreplacedyResultHandler resultHandler = new ResponseEnreplacedyResultHandler(Collections.singletonList(new EncoderHttpMessageWriter<>(CharSequenceEncoder.textPlainOnly())), new RequestedContentTypeResolverBuilder().build());
StepVerifier.create(resultHandler.handleResult(exchange, result)).consumeErrorWith(ex -> replacedertThat(ex).isInstanceOf(HttpMessageNotWritableException.clreplaced).hasMessageContaining("with preset Content-Type")).verify();
}
18
Source : RequestMappingMessageConversionIntegrationTests.java
with Apache License 2.0
from SourceHot
with Apache License 2.0
from SourceHot
// SPR-16759
@ParameterizedHttpServerTest
public void personTransformWithMonoAndXml(HttpServer httpServer) throws Exception {
startServer(httpServer);
replacedertThat(performPost("/person-transform/mono", MediaType.APPLICATION_XML, new Person("Robert"), MediaType.APPLICATION_XML, Person.clreplaced).getBody()).isEqualTo(new Person("ROBERT"));
}
18
Source : MockHttpServletRequestBuilderTests.java
with Apache License 2.0
from SourceHot
with Apache License 2.0
from SourceHot
@Test
public void acceptHeader() {
this.builder.accept(MediaType.TEXT_HTML, MediaType.APPLICATION_XML);
MockHttpServletRequest request = this.builder.buildRequest(this.servletContext);
List<String> accept = Collections.list(request.getHeaders("Accept"));
List<MediaType> result = MediaType.parseMediaTypes(accept.get(0));
replacedertThat(accept.size()).isEqualTo(1);
replacedertThat(result.get(0).toString()).isEqualTo("text/html");
replacedertThat(result.get(1).toString()).isEqualTo("application/xml");
}
18
Source : HeaderAssertionTests.java
with Apache License 2.0
from SourceHot
with Apache License 2.0
from SourceHot
@Test
public void contentTypeCompatibleWith() {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_XML);
Headerreplacedertions replacedertions = headerreplacedertions(headers);
// Success
replacedertions.contentTypeCompatibleWith(MediaType.parseMediaType("application/*"));
// MediaTypes not compatible
replacedertThatExceptionOfType(replacedertionError.clreplaced).isThrownBy(() -> replacedertions.contentTypeCompatibleWith(MediaType.TEXT_XML)).satisfies(ex -> replacedertThat(ex.getCause()).hasMessage("Response header " + "'Content-Type'=[application/xml] is not compatible with [text/xml]"));
}
18
Source : ConfigurationFileController.java
with GNU Lesser General Public License v3.0
from schic
with GNU Lesser General Public License v3.0
from schic
@RolesAllowed(SecurityRoles.CONFIGURATION_EDITOR)
@RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_XML_VALUE)
@ResponseBody
public HttpEnreplacedy<byte[]> downloadConfigurationFile(@PathVariable("tenant") final String tenant) {
final TenantContext context = _contextFactory.getContext(tenant);
final RepositoryFile configurationFile = context.getConfigurationFile();
if (configurationFile == null) {
throw new IllegalStateException("Configuration file not found!");
}
final byte[] doreplacedentBody = configurationFile.readFile(new Function<InputStream, byte[]>() {
@Override
public byte[] apply(InputStream in) {
return FileHelper.readAsBytes(in);
}
});
final HttpHeaders header = new HttpHeaders();
header.setContentType(MediaType.APPLICATION_XML);
header.setContentLength(doreplacedentBody.length);
return new HttpEnreplacedy<byte[]>(doreplacedentBody, header);
}
18
Source : GoogleSearchProviderImpl.java
with Apache License 2.0
from NBANDROIDTEAM
with Apache License 2.0
from NBANDROIDTEAM
private GoogleMasterIndex readGoogleMasterIndex(int connectTimeout, int readTimeout) {
try {
RestTemplate restTemplate = new RestTemplate();
HttpHeaders requestHeaders = new HttpHeaders();
requestHeaders.setAccept(Collections.singletonList(MediaType.APPLICATION_XML));
setTimeout(restTemplate, connectTimeout, readTimeout);
ObjectMapper mapper = Jackson2ObjectMapperBuilder.xml().build();
mapper = mapper.addHandler(new DeserializationProblemHandler() {
@Override
public boolean handleUnknownProperty(DeserializationContext ctxt, JsonParser p, JsonDeserializer<?> deserializer, Object beanOrClreplaced, String propertyName) throws IOException {
if (beanOrClreplaced instanceof GoogleMasterIndex) {
((GoogleMasterIndex) beanOrClreplaced).getGroups().put(propertyName, BASE_URL + propertyName.replace(".", "/") + "/" + GROUP_INDEX);
return true;
}
return false;
}
});
restTemplate.getMessageConverters().clear();
restTemplate.getMessageConverters().add(new MappingJackson2XmlHttpMessageConverter(mapper));
ResponseEnreplacedy<GoogleMasterIndex> response = restTemplate.exchange(BASE_URL + MASTER_INDEX, HttpMethod.GET, new HttpEnreplacedy<>(requestHeaders), GoogleMasterIndex.clreplaced);
return response.getBody();
} catch (Exception exception) {
Exceptions.printStackTrace(exception);
}
return null;
}
18
Source : GoogleSearchProviderImpl.java
with Apache License 2.0
from NBANDROIDTEAM
with Apache License 2.0
from NBANDROIDTEAM
private GoogleGroupIndex readGoogleGroupIndex(final String group, final String url, int connectTimeout, int readTimeout) {
try {
RestTemplate restTemplate = new RestTemplate();
HttpHeaders requestHeaders = new HttpHeaders();
requestHeaders.setAccept(Collections.singletonList(MediaType.APPLICATION_XML));
setTimeout(restTemplate, connectTimeout, readTimeout);
ObjectMapper mapper = Jackson2ObjectMapperBuilder.xml().build();
mapper = mapper.addHandler(new DeserializationProblemHandler() {
@Override
public boolean handleUnknownProperty(DeserializationContext ctxt, JsonParser p, JsonDeserializer<?> deserializer, Object beanOrClreplaced, String propertyName) throws IOException {
if (beanOrClreplaced instanceof GoogleGroupIndex) {
if ("versions".equals(propertyName)) {
if (((GoogleGroupIndex) beanOrClreplaced).lastArtifactId != null) {
((GoogleGroupIndex) beanOrClreplaced).downloaded.put(((GoogleGroupIndex) beanOrClreplaced).lastArtifactId, p.getText());
((GoogleGroupIndex) beanOrClreplaced).lastArtifactId = null;
}
} else {
((GoogleGroupIndex) beanOrClreplaced).lastArtifactId = propertyName;
}
return true;
}
return false;
}
});
restTemplate.getMessageConverters().clear();
restTemplate.getMessageConverters().add(new MappingJackson2XmlHttpMessageConverter(mapper));
ResponseEnreplacedy<GoogleGroupIndex> response = restTemplate.exchange(url, HttpMethod.GET, new HttpEnreplacedy<>(requestHeaders), GoogleGroupIndex.clreplaced);
GoogleGroupIndex groupIndex = response.getBody();
groupIndex.group = group;
groupIndex.url = url;
return groupIndex.build();
} catch (Exception exception) {
Exceptions.printStackTrace(exception);
}
return null;
}
18
Source : WebMvcConfigurationSupportExtensionTests.java
with Apache License 2.0
from langtianya
with Apache License 2.0
from langtianya
@Test
public void contentNegotiation() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo.json");
NativeWebRequest webRequest = new ServletWebRequest(request);
ContentNegotiationManager manager = this.config.requestMappingHandlerMapping().getContentNegotiationManager();
replacedertEquals(Arrays.asList(MediaType.APPLICATION_JSON), manager.resolveMediaTypes(webRequest));
request.setRequestURI("/foo.xml");
replacedertEquals(Arrays.asList(MediaType.APPLICATION_XML), manager.resolveMediaTypes(webRequest));
request.setRequestURI("/foo.rss");
replacedertEquals(Arrays.asList(MediaType.valueOf("application/rss+xml")), manager.resolveMediaTypes(webRequest));
request.setRequestURI("/foo.atom");
replacedertEquals(Arrays.asList(MediaType.APPLICATION_ATOM_XML), manager.resolveMediaTypes(webRequest));
request.setRequestURI("/foo");
request.setParameter("f", "json");
replacedertEquals(Arrays.asList(MediaType.APPLICATION_JSON), manager.resolveMediaTypes(webRequest));
}
18
Source : SearchController.java
with Apache License 2.0
from Erudika
with Apache License 2.0
from Erudika
@ResponseBody
@GetMapping("/opensearch.xml")
public ResponseEnreplacedy<String> openSearch() {
String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n" + "<OpenSearchDescription xmlns=\"http://a9.com/-/spec/opensearch/1.1/\" " + " xmlns:moz=\"http://www.mozilla.org/2006/browser/search/\">\n" + " <ShortName>" + Config.APP_NAME + "</ShortName>\n" + " <Description>Search for questions and answers</Description>\n" + " <InputEncoding>UTF-8</InputEncoding>\n" + " <Image width=\"16\" height=\"16\" type=\"image/x-icon\">https://scoold.com/favicon.ico</Image>\n" + " <Url type=\"text/html\" method=\"get\" template=\"" + ScooldServer.getServerURL() + CONTEXT_PATH + "/search?q={searchTerms}\"></Url>\n" + "</OpenSearchDescription>";
return ResponseEnreplacedy.ok().contentType(MediaType.APPLICATION_XML).cacheControl(CacheControl.maxAge(1, TimeUnit.HOURS)).eTag(Utils.md5(xml)).body(xml);
}
18
Source : CpcFileControllerV1.java
with Creative Commons Zero v1.0 Universal
from CMSgov
with Creative Commons Zero v1.0 Universal
from CMSgov
/**
* Retrieve a stored S3 submission object.
*
* @param fileId id for the stored object
* @return object json or xml content
* @throws IOException if S3Object content stream is invalid
*/
@GetMapping(value = "/file/{fileId}", headers = { "Accept=" + Constants.V1_API_ACCEPT })
public ResponseEnreplacedy<InputStreamResource> getFileById(@PathVariable("fileId") String fileId) throws IOException {
API_LOG.info("CPC+ file retrieval request received for fileId {}", fileId);
if (blockCpcPlusApi()) {
API_LOG.info(BLOCKED_BY_FEATURE_FLAG);
return new ResponseEnreplacedy<>(null, null, HttpStatus.FORBIDDEN);
}
InputStreamResource content = cpcFileService.getFileById(fileId);
API_LOG.info("CPC+ file retrieval request succeeded");
return ResponseEnreplacedy.ok().contentType(MediaType.APPLICATION_XML).body(content);
}
18
Source : ProcessDefinitionControllerImplIT.java
with Apache License 2.0
from Activiti
with Apache License 2.0
from Activiti
@Test
public void shouldGetXMLProcessModel() throws Exception {
String processDefinitionId = UUID.randomUUID().toString();
given(processRuntime.processDefinition(processDefinitionId)).willReturn(mock(ProcessDefinition.clreplaced));
InputStream xml = new ByteArrayInputStream("activiti".getBytes());
when(repositoryService.getProcessModel(processDefinitionId)).thenReturn(xml);
mockMvc.perform(get("/v1/process-definitions/{id}/model", processDefinitionId).accept(MediaType.APPLICATION_XML)).andExpect(status().isOk()).andDo(doreplacedent(DOreplacedENTATION_IDENTIFIER + "/model/get", processDefinitionIdParameter()));
}
18
Source : ProcessDefinitionControllerImplIT.java
with Apache License 2.0
from Activiti
with Apache License 2.0
from Activiti
@Test
public void shouldGetXMLProcessModel() throws Exception {
String processDefinitionId = UUID.randomUUID().toString();
given(processRuntime.processDefinition(processDefinitionId)).willReturn(mock(ProcessDefinition.clreplaced));
InputStream xml = new ByteArrayInputStream("activiti".getBytes());
when(repositoryService.getProcessModel(processDefinitionId)).thenReturn(xml);
mockMvc.perform(get("/v1/process-definitions/{id}/model", processDefinitionId).accept(MediaType.APPLICATION_XML)).andExpect(status().isOk());
}
17
Source : XmlContentTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
@Test
public void postXmlContent() {
String content = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + "<person><name>John</name></person>";
this.client.post().uri("/persons").contentType(MediaType.APPLICATION_XML).syncBody(content).exchange().expectStatus().isCreated().expectHeader().valueEquals(HttpHeaders.LOCATION, "/persons/John").expectBody().isEmpty();
}
17
Source : BookRouter.java
with Apache License 2.0
from springdoc
with Apache License 2.0
from springdoc
@Bean
@RouterOperations({ @RouterOperation(path = "/greeter/books", produces = { MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE }, beanClreplaced = BookRepository.clreplaced, beanMethod = "findAll"), @RouterOperation(path = "/greeter/books", produces = { MediaType.TEXT_PLAIN_VALUE, MediaType.APPLICATION_XML_VALUE }, beanClreplaced = BookRepository.clreplaced, beanMethod = "findAll"), @RouterOperation(path = "/greeter/books/{author}", beanClreplaced = BookRepository.clreplaced, beanMethod = "findByAuthor", operation = @Operation(operationId = "findByAuthor", parameters = { @Parameter(in = ParameterIn.PATH, name = "author") })), @RouterOperation(path = "/greeter2/books", produces = { MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE }, beanClreplaced = BookRepository.clreplaced, beanMethod = "findAll"), @RouterOperation(path = "/greeter2/books", produces = { MediaType.TEXT_PLAIN_VALUE, MediaType.APPLICATION_XML_VALUE }, beanClreplaced = BookRepository.clreplaced, beanMethod = "findAll"), @RouterOperation(path = "/greeter2/books/{author}", beanClreplaced = BookRepository.clreplaced, beanMethod = "findByAuthor", operation = @Operation(operationId = "findByAuthor", parameters = { @Parameter(in = ParameterIn.PATH, name = "author") })) })
RouterFunction<?> routes3(BookRepository br) {
return nest(RequestPredicates.path("/greeter").or(RequestPredicates.path("/greeter2")), route(RequestPredicates.GET("/books").and(RequestPredicates.accept(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML)), req -> ok().body(br.findAll())).and(route(RequestPredicates.GET("/books").and(RequestPredicates.accept(MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN)), req -> ok().body(br.findAll()))).andRoute(RequestPredicates.GET("/books/{author}"), req -> ok().body(br.findByAuthor(req.pathVariable("author")))));
}
17
Source : BookRouter.java
with Apache License 2.0
from springdoc
with Apache License 2.0
from springdoc
@Bean
RouterFunction<?> routes1(BookRepository br) {
return nest(accept(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML), route(GET("/books"), req -> ok().body(br.findAll(), Book.clreplaced)).withAttribute(OPERATION_ATTRIBUTE, getFindAll()).and(route(GET("/books/{author}"), req -> ok().body(br.findByAuthor(req.pathVariable("author")), Book.clreplaced)).withAttribute(OPERATION_ATTRIBUTE, getRouterAttribute())));
}
17
Source : EmployeeFunctionalConfig.java
with Apache License 2.0
from springdoc
with Apache License 2.0
from springdoc
@Bean
@RouterOperation(beanClreplaced = EmployeeRepository.clreplaced, beanMethod = "updateEmployee")
RouterFunction<ServerResponse> updateEmployeeRoute() {
return route(POST("/employees/update").and(accept(MediaType.APPLICATION_XML)), req -> req.body(BodyExtractors.toMono(Employee.clreplaced)).doOnNext(employeeRepository()::updateEmployee).then(ok().build()));
}
See More Examples