Package org.springframework.http.converter

Examples of org.springframework.http.converter.GenericHttpMessageConverter


              allSupportedMediaTypes.addAll(getSupportedMediaTypes(converter));
            }
          }
          else if (converter instanceof GenericHttpMessageConverter) {

            GenericHttpMessageConverter genericConverter = (GenericHttpMessageConverter) converter;
            if (genericConverter.canRead(responseType, null, null)) {
              allSupportedMediaTypes.addAll(getSupportedMediaTypes(converter));
            }
          }

        }
View Full Code Here


    }
    MediaType contentType = getContentType(response);

    for (HttpMessageConverter messageConverter : this.messageConverters) {
      if (messageConverter instanceof GenericHttpMessageConverter) {
        GenericHttpMessageConverter genericMessageConverter = (GenericHttpMessageConverter) messageConverter;
        if (genericMessageConverter.canRead(this.responseType, null, contentType)) {
          if (logger.isDebugEnabled()) {
            logger.debug("Reading [" + this.responseType + "] as \"" +
                contentType + "\" using [" + messageConverter + "]");
          }
          return (T) genericMessageConverter.read(this.responseType, null, response);
        }
      }
      if (this.responseClass != null) {
        if (messageConverter.canRead(this.responseClass, contentType)) {
          if (logger.isDebugEnabled()) {
View Full Code Here

        Map<TypeVariable, Type> map = GenericTypeResolver.getTypeVariableMap(contextClass);
        Class<T> targetClass = (Class<T>) GenericTypeResolver.resolveType(targetType, map);

        for (HttpMessageConverter<?> converter : this.messageConverters) {
          if (converter instanceof GenericHttpMessageConverter) {
            GenericHttpMessageConverter genericConverter = (GenericHttpMessageConverter) converter;
            if (genericConverter.canRead(targetType, contextClass, contentType)) {
              if (logger.isDebugEnabled()) {
                logger.debug("Reading [" + targetType + "] as \"" +
                    contentType + "\" using [" + converter + "]");
              }
              return (T) genericConverter.read(targetType, contextClass, inputMessage);
            }
          }
          if (targetClass != null) {
            if (converter.canRead(targetClass, contentType)) {
              if (logger.isDebugEnabled()) {
View Full Code Here

  }

  @Test
  @SuppressWarnings("rawtypes")
  public void exchangeParameterizedType() throws Exception {
    GenericHttpMessageConverter converter = mock(GenericHttpMessageConverter.class);
    template.setMessageConverters(Collections.<HttpMessageConverter<?>>singletonList(converter));

    ParameterizedTypeReference<List<Integer>> intList = new ParameterizedTypeReference<List<Integer>>() {};
    given(converter.canRead(intList.getType(), null, null)).willReturn(true);
    given(converter.getSupportedMediaTypes()).willReturn(Collections.singletonList(MediaType.TEXT_PLAIN));
    given(requestFactory.createRequest(new URI("http://example.com"), HttpMethod.POST)).willReturn(this.request);
    HttpHeaders requestHeaders = new HttpHeaders();
    given(this.request.getHeaders()).willReturn(requestHeaders);
    given(converter.canWrite(String.class, null)).willReturn(true);
    String requestBody = "Hello World";
    converter.write(requestBody, null, this.request);
    given(this.request.execute()).willReturn(response);
    given(errorHandler.hasError(response)).willReturn(false);
    HttpHeaders responseHeaders = new HttpHeaders();
    responseHeaders.setContentType(MediaType.TEXT_PLAIN);
    responseHeaders.setContentLength(10);
    given(response.getStatusCode()).willReturn(HttpStatus.OK);
    given(response.getHeaders()).willReturn(responseHeaders);
    List<Integer> expected = Collections.singletonList(42);
    given(converter.canRead(intList.getType(), null, MediaType.TEXT_PLAIN)).willReturn(true);
    given(converter.read(intList.getType(), null, response)).willReturn(expected);
    given(response.getStatusCode()).willReturn(HttpStatus.OK);
    HttpStatus status = HttpStatus.OK;
    given(response.getStatusCode()).willReturn(status);
    given(response.getStatusText()).willReturn(status.getReasonPhrase());
View Full Code Here

TOP

Related Classes of org.springframework.http.converter.GenericHttpMessageConverter

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.