Package org.springframework.web

Examples of org.springframework.web.HttpMediaTypeNotSupportedException


      if (StringUtils.hasLength(request.getContentType())) {
        try {
          contentType = MediaType.parseMediaType(request.getContentType());
        }
        catch (InvalidMediaTypeException ex) {
          throw new HttpMediaTypeNotSupportedException(ex.getMessage());
        }
      }
      throw new HttpMediaTypeNotSupportedException(contentType, new ArrayList<MediaType>(consumableMediaTypes));
    }
    else if (!producibleMediaTypes.isEmpty()) {
      throw new HttpMediaTypeNotAcceptableException(new ArrayList<MediaType>(producibleMediaTypes));
    }
    else if (!CollectionUtils.isEmpty(paramConditions)) {
View Full Code Here


  }

  @Test
  public void handleHttpMediaTypeNotSupported() {
    List<MediaType> acceptable = Arrays.asList(MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_XML);
    Exception ex = new HttpMediaTypeNotSupportedException(MediaType.APPLICATION_JSON, acceptable);

    ResponseEntity<Object> responseEntity = testException(ex);
    assertEquals(acceptable, responseEntity.getHeaders().getAccept());
  }
View Full Code Here

    assertEquals("Invalid Allow header", "POST, PUT", response.getHeader("Allow"));
  }

  @Test
  public void handleHttpMediaTypeNotSupported() {
    HttpMediaTypeNotSupportedException ex = new HttpMediaTypeNotSupportedException(new MediaType("text", "plain"),
        Collections.singletonList(new MediaType("application", "pdf")));
    ModelAndView mav = exceptionResolver.resolveException(request, response, null, ex);
    assertNotNull("No ModelAndView returned", mav);
    assertTrue("No Empty ModelAndView returned", mav.isEmpty());
    assertEquals("Invalid status code", 415, response.getStatus());
View Full Code Here

      String paramName = methodParam.getParameterName();
      if (paramName != null) {
        builder.append(' ');
        builder.append(paramName);
      }
      throw new HttpMediaTypeNotSupportedException(
          "Cannot extract @RequestBody parameter (" + builder.toString() + "): no Content-Type found");
    }
    List<MediaType> allSupportedMediaTypes = new ArrayList<MediaType>();
    if (this.messageConverters != null) {
      for (HttpMessageConverter<?> messageConverter : this.messageConverters) {
        allSupportedMediaTypes.addAll(messageConverter.getSupportedMediaTypes());
        if (messageConverter.canRead(paramType, contentType)) {
          return messageConverter.read(paramType, inputMessage);
        }
      }
    }
    throw new HttpMediaTypeNotSupportedException(contentType, allSupportedMediaTypes);
  }
View Full Code Here

      String paramName = methodParam.getParameterName();
      if (paramName != null) {
        builder.append(' ');
        builder.append(paramName);
      }
      throw new HttpMediaTypeNotSupportedException(
          "Cannot extract parameter (" + builder.toString() + "): no Content-Type found");
    }

    List<MediaType> allSupportedMediaTypes = new ArrayList<MediaType>();
    if (this.messageConverters != null) {
      for (HttpMessageConverter<?> messageConverter : this.messageConverters) {
        allSupportedMediaTypes.addAll(messageConverter.getSupportedMediaTypes());
        if (messageConverter.canRead(paramType, contentType)) {
          if (logger.isDebugEnabled()) {
            logger.debug("Reading [" + paramType.getName() + "] as \"" + contentType
                +"\" using [" + messageConverter + "]");
          }
          return messageConverter.read(paramType, inputMessage);
        }
      }
    }
    throw new HttpMediaTypeNotSupportedException(contentType, allSupportedMediaTypes);
  }
View Full Code Here

TOP

Related Classes of org.springframework.web.HttpMediaTypeNotSupportedException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.