List of usage examples for org.springframework.http MediaType ALL
MediaType ALL
To view the source code for org.springframework.http MediaType ALL.
Click Source Link
From source file:de.qucosa.webapi.v1.RelationResourceTest.java
@Test public void returns401WhenNotAuthorized() throws Exception { when(fedoraRepository.getPIDByIdentifier(anyString())) .thenThrow(new FedoraClientException(401, "UNAUTHORIZED")); mockMvc.perform(get("/relation/urn/urn:no-auth").accept(MediaType.ALL)) .andExpect(status().isUnauthorized()); }
From source file:com.test.RestApplicationTests.java
@Test public void sentencesAcceptAny() throws Exception { assertThat(//from w w w. ja v a 2 s . c o m rest.exchange(RequestEntity.get(new URI("/sentences")).accept(MediaType.ALL).build(), String.class) .getBody()).isEqualTo("[[\"go\",\"home\"],[\"come\",\"back\"]]"); }
From source file:ch.ralscha.extdirectspring.controller.RouterControllerFormPostTest.java
@Test public void testCallExistsFormPostMethod() throws Exception { MockHttpServletRequestBuilder request = post("/router").accept(MediaType.ALL) .contentType(MediaType.APPLICATION_JSON).characterEncoding("UTF-8"); request.param("extTID", "12"); request.param("extAction", "formInfoController"); request.param("extMethod", "updateInfo"); request.param("extType", "rpc"); request.param("name", "Ralph"); request.param("age", "20"); request.param("admin", "true"); request.param("salary", "12.3"); request.param("result", "theResult"); mockMvc.perform(request).andExpect(status().isOk()).andExpect(forwardedUrl("updateInfo")); }
From source file:org.craftercms.commons.rest.HttpMessageConvertingResponseWriter.java
/** * Returns the media types that can be produced: * <ul>/*from ww w . j a va2s . c o m*/ * <li>Media types of configured converters that can write the specific return value, or</li> * <li>{@link org.springframework.http.MediaType#ALL}</li> * </ul> */ protected List<MediaType> getProducibleMediaTypes(Class<?> returnValueClass) { if (!allSupportedMediaTypes.isEmpty()) { List<MediaType> result = new ArrayList<>(); for (HttpMessageConverter<?> converter : messageConverters) { if (converter.canWrite(returnValueClass, null)) { result.addAll(converter.getSupportedMediaTypes()); } } return result; } else { return Collections.singletonList(MediaType.ALL); } }
From source file:ch.ralscha.extdirectspring.controller.ControllerUtil.java
public static MvcResult performRouterRequest(MockMvc mockMvc, String content, Map<String, String> params, HttpHeaders headers, List<Cookie> cookies, boolean withSession) throws Exception { MockHttpServletRequestBuilder request = post("/router").accept(MediaType.ALL) .contentType(MediaType.APPLICATION_JSON).characterEncoding("UTF-8"); if (cookies != null) { request.cookie(cookies.toArray(new Cookie[cookies.size()])); }/*from w ww . j a va 2 s .co m*/ if (withSession) { request.session(new MockHttpSession()); } if (content != null) { request.content(content); } if (params != null) { for (String paramName : params.keySet()) { request.param(paramName, params.get(paramName)); } } if (headers != null) { request.headers(headers); } return mockMvc.perform(request).andExpect(status().isOk()) .andExpect(content().contentType("application/json;charset=UTF-8")) .andExpect(content().encoding("UTF-8")).andReturn(); }
From source file:org.ayfaar.app.spring.handler.RestExceptionHandler.java
@SuppressWarnings("unchecked") protected ModelAndView handleResponseBody(Object body, ServletWebRequest webRequest) throws ServletException, IOException { HttpInputMessage inputMessage = new ServletServerHttpRequest(webRequest.getRequest()); List<MediaType> acceptedMediaTypes = inputMessage.getHeaders().getAccept(); if (acceptedMediaTypes.isEmpty()) { acceptedMediaTypes = Collections.singletonList(MediaType.ALL); }/* w w w . j a v a2 s . c om*/ MediaType.sortByQualityValue(acceptedMediaTypes); HttpOutputMessage outputMessage = new ServletServerHttpResponse(webRequest.getResponse()); Class<?> bodyType = body.getClass(); List<HttpMessageConverter<?>> converters = this.allMessageConverters; if (converters != null) { for (MediaType acceptedMediaType : acceptedMediaTypes) { for (HttpMessageConverter messageConverter : converters) { if (messageConverter.canWrite(bodyType, acceptedMediaType)) { messageConverter.write(body, acceptedMediaType, outputMessage); //return empty model and view to short circuit the iteration and to let //Spring know that we've rendered the view ourselves: return new ModelAndView(); } } } } if (logger.isWarnEnabled()) { logger.warn("Could not find HttpMessageConverter that supports return type [" + bodyType + "] and " + acceptedMediaTypes); } return null; }
From source file:org.craftercms.commons.rest.HttpMessageConvertingResponseWriter.java
/** * Return the acceptable media types from the request. *//*ww w .j a v a2 s .c om*/ protected List<MediaType> getAcceptableMediaTypes(HttpServletRequest request) throws HttpMediaTypeNotAcceptableException { List<MediaType> mediaTypes = contentNegotiationManager.resolveMediaTypes(new ServletWebRequest(request)); return mediaTypes.isEmpty() ? Collections.singletonList(MediaType.ALL) : mediaTypes; }
From source file:de.qucosa.webapi.v1.DocumentResourceTest.java
@Test public void returns404WithNoContent() throws Exception { when(fedoraRepository.getDatastreamContent(anyString(), anyString())) .thenThrow(new FedoraClientException(404, "NOT FOUND")); mockMvc.perform(get("/document/no-valid-id").accept(MediaType.ALL)).andExpect(status().isNotFound()); }
From source file:de.qucosa.webapi.v1.DocumentResourceTest.java
@Test public void returns401WhenNotAuthorized() throws Exception { when(fedoraRepository.getDatastreamContent(anyString(), anyString())) .thenThrow(new FedoraClientException(401, "UNAUTHORIZED")); mockMvc.perform(get("/document/no-auth").accept(MediaType.ALL)).andExpect(status().isUnauthorized()); }