• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java EncodeException类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中feign.codec.EncodeException的典型用法代码示例。如果您正苦于以下问题:Java EncodeException类的具体用法?Java EncodeException怎么用?Java EncodeException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



EncodeException类属于feign.codec包,在下文中一共展示了EncodeException类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: encode

import feign.codec.EncodeException; //导入依赖的package包/类
@Override
public void encode(Object object, Type bodyType, RequestTemplate template) throws EncodeException {

    if(object instanceof Pageable) {
        Pageable pageable = (Pageable) object;
        template.query("page", pageable.getPageNumber() + "");
        template.query("size", pageable.getPageSize() + "");
        if (pageable.getSort() != null) {
            applySort(template, pageable.getSort());
        }
    }else if(object instanceof Sort){
        Sort sort = (Sort)object;
        applySort(template, sort);
    }else{
        delegate.encode(object, bodyType, template);
    }
}
 
开发者ID:ElderByte-,项目名称:spring-cloud-starter-bootstrap,代码行数:18,代码来源:PageableQueryEncoder.java


示例2: encodeMultipartFormRequest

import feign.codec.EncodeException; //导入依赖的package包/类
/**
 * Encodes the request as a multipart form. It can detect a single {@link MultipartFile}, an
 * array of {@link MultipartFile}s, or POJOs (that are converted to JSON).
 *
 * @param formMap
 * @param template
 * @throws EncodeException
 */
private void encodeMultipartFormRequest(Map<String, ?> formMap, RequestTemplate template) throws EncodeException {
    if (formMap == null) {
        throw new EncodeException("Cannot encode request with null form.");
    }
    LinkedMultiValueMap<String, Object> map = new LinkedMultiValueMap<>();
    for (Entry<String, ?> entry : formMap.entrySet()) {
        Object value = entry.getValue();
        if (isMultipartFile(value)) {
            map.add(entry.getKey(), encodeMultipartFile((MultipartFile) value));
        } else if (isMultipartFileArray(value)) {
            encodeMultipartFiles(map, entry.getKey(), Arrays.asList((MultipartFile[]) value));
        } else {
            map.add(entry.getKey(), encodeJsonObject(value));
        }
    }
    encodeRequest(map, multipartHeaders, template);
}
 
开发者ID:pcan,项目名称:feign-client-test,代码行数:26,代码来源:FeignSpringFormEncoder.java


示例3: encodeMultipartFile

import feign.codec.EncodeException; //导入依赖的package包/类
/**
 * Wraps a single {@link MultipartFile} into a {@link HttpEntity} and sets the
 * {@code Content-type} header to {@code application/octet-stream}
 *
 * @param file
 * @return
 */
private HttpEntity<?> encodeMultipartFile(MultipartFile file) {
    HttpHeaders filePartHeaders = new HttpHeaders();
    filePartHeaders.setContentType(MediaType.APPLICATION_OCTET_STREAM);
    try {
        Resource multipartFileResource = new MultipartFileResource(file.getOriginalFilename(), file.getSize(), file.getInputStream());
        return new HttpEntity<>(multipartFileResource, filePartHeaders);
    } catch (IOException ex) {
        throw new EncodeException("Cannot encode request.", ex);
    }
}
 
开发者ID:pcan,项目名称:feign-client-test,代码行数:18,代码来源:FeignSpringFormEncoder.java


示例4: encodeRequest

import feign.codec.EncodeException; //导入依赖的package包/类
/**
 * Calls the conversion chain actually used by
 * {@link org.springframework.web.client.RestTemplate}, filling the body of the request
 * template.
 *
 * @param value
 * @param requestHeaders
 * @param template
 * @throws EncodeException
 */
private void encodeRequest(Object value, HttpHeaders requestHeaders, RequestTemplate template) throws EncodeException {
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    HttpOutputMessage dummyRequest = new HttpOutputMessageImpl(outputStream, requestHeaders);
    try {
        Class<?> requestType = value.getClass();
        MediaType requestContentType = requestHeaders.getContentType();
        for (HttpMessageConverter<?> messageConverter : converters) {
            if (messageConverter.canWrite(requestType, requestContentType)) {
                ((HttpMessageConverter<Object>) messageConverter).write(
                        value, requestContentType, dummyRequest);
                break;
            }
        }
    } catch (IOException ex) {
        throw new EncodeException("Cannot encode request.", ex);
    }
    HttpHeaders headers = dummyRequest.getHeaders();
    if (headers != null) {
        for (Entry<String, List<String>> entry : headers.entrySet()) {
            template.header(entry.getKey(), entry.getValue());
        }
    }
    /*
    we should use a template output stream... this will cause issues if files are too big, 
    since the whole request will be in memory.
     */
    template.body(outputStream.toByteArray(), UTF_8);
}
 
开发者ID:pcan,项目名称:feign-client-test,代码行数:39,代码来源:FeignSpringFormEncoder.java


示例5: encode

import feign.codec.EncodeException; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public void encode (Object object, Type bodyType, RequestTemplate template) throws EncodeException {
  String contentTypeValue = getContentTypeValue(template.headers());
  val contentType = ContentType.of(contentTypeValue);
  if (!MAP_STRING_WILDCARD.equals(bodyType) || !processors.containsKey(contentType)) {
    delegate.encode(object, bodyType, template);
    return;
  }

  val charset = getCharset(contentTypeValue);
  val data = (Map<String, Object>) object;
  try {
    processors.get(contentType).process(template, charset, data);
  } catch (Exception ex) {
    throw new EncodeException(ex.getMessage());
  }
}
 
开发者ID:OpenFeign,项目名称:feign-form,代码行数:19,代码来源:FormEncoder.java


示例6: encode

import feign.codec.EncodeException; //导入依赖的package包/类
@Override
public void encode(Object object, Type bodyType, RequestTemplate template) throws EncodeException {
    if(object instanceof ContinuationToken){
        ContinuationToken pageable = (ContinuationToken)object;
        template.query("continuationToken", pageable.getToken() + "");
    }else{
        delegate.encode(object, bodyType, template);
    }
}
 
开发者ID:ElderByte-,项目名称:spring-cloud-starter-bootstrap,代码行数:10,代码来源:ContinuationTokenQueryEncoder.java


示例7: encode

import feign.codec.EncodeException; //导入依赖的package包/类
@Override
public void encode(Object object, Type bodyType, RequestTemplate template) throws EncodeException {
  ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
  try {
    jacksonJaxbJsonProvider.writeTo(object, bodyType.getClass(), null, null, APPLICATION_JSON_TYPE, null, outputStream);
    template.body(outputStream.toByteArray(), Charset.defaultCharset());
  } catch (IOException e) {
    throw new EncodeException(e.getMessage(), e);
  }
}
 
开发者ID:wenwu315,项目名称:XXXX,代码行数:11,代码来源:JacksonJaxbJsonEncoder.java


示例8: encode

import feign.codec.EncodeException; //导入依赖的package包/类
@Override
public void encode(Object object, Type bodyType, RequestTemplate template) {
  if (!(bodyType instanceof Class)) {
    throw new UnsupportedOperationException(
        "JAXB only supports encoding raw types. Found " + bodyType);
  }
  try {
    Marshaller marshaller = jaxbContextFactory.createMarshaller((Class) bodyType);
    StringWriter stringWriter = new StringWriter();
    marshaller.marshal(object, stringWriter);
    template.body(stringWriter.toString());
  } catch (JAXBException e) {
    throw new EncodeException(e.toString(), e);
  }
}
 
开发者ID:wenwu315,项目名称:XXXX,代码行数:16,代码来源:JAXBEncoder.java


示例9: encode

import feign.codec.EncodeException; //导入依赖的package包/类
@Override
public void encode(Object object, Type bodyType, RequestTemplate template) {
  try {
    JavaType javaType = mapper.getTypeFactory().constructType(bodyType);
    template.body(mapper.writerFor(javaType).writeValueAsString(object));
  } catch (JsonProcessingException e) {
    throw new EncodeException(e.getMessage(), e);
  }
}
 
开发者ID:wenwu315,项目名称:XXXX,代码行数:10,代码来源:JacksonEncoder.java


示例10: okIfEncodeRootCauseHasNoMessage

import feign.codec.EncodeException; //导入依赖的package包/类
@Test
public void okIfEncodeRootCauseHasNoMessage() throws Exception {
  server.enqueue(new MockResponse().setBody("success!"));
  thrown.expect(EncodeException.class);

  TestInterface api = new TestInterfaceBuilder()
      .encoder(new Encoder() {
        @Override
        public void encode(Object object, Type bodyType, RequestTemplate template) {
          throw new RuntimeException();
        }
      }).target("http://localhost:" + server.getPort());

  api.body(Arrays.asList("foo"));
}
 
开发者ID:wenwu315,项目名称:XXXX,代码行数:16,代码来源:FeignTest.java


示例11: encode

import feign.codec.EncodeException; //导入依赖的package包/类
@Override
public void encode(Object requestBody, Type bodyType, RequestTemplate request) throws EncodeException {
    if (requestBody != null) {
        Class<?> requestType = requestBody.getClass();
        Collection<String> contentTypes = request.headers().get(HttpHeaders.CONTENT_TYPE);
        MediaType requestContentType = null;
        if (contentTypes != null && !contentTypes.isEmpty()) {
            String type = contentTypes.iterator().next();
            requestContentType = MediaType.valueOf(type);
        }
        for (HttpMessageConverter<?> messageConverter : this.messageConverters.getObject().getConverters()) {
            if (messageConverter.canWrite(requestType, requestContentType)) {

                FeignOutputMessage outputMessage = new FeignOutputMessage(request);
                try {
                    @SuppressWarnings("unchecked")
                    HttpMessageConverter<Object> copy = (HttpMessageConverter<Object>) messageConverter;
                    copy.write(requestBody, requestContentType, outputMessage);
                } catch (IOException ex) {
                    throw new EncodeException("Error converting request body", ex);
                }
                request.headers(null);
                request.headers(FeignUtils.getHeaders(outputMessage.getHeaders()));
                request.body(outputMessage.getOutputStream().toByteArray(), Charset.forName("UTF-8")); // TODO:
                return;
            }
        }
        String message = "Could not write request: no suitable HttpMessageConverter " + "found for request type ["
                + requestType.getName() + "]";
        if (requestContentType != null) {
            message += " and content type [" + requestContentType + "]";
        }
        throw new EncodeException(message);
    }
}
 
开发者ID:zhaoqilong3031,项目名称:spring-cloud-samples,代码行数:36,代码来源:CustomEncode.java


示例12: encode

import feign.codec.EncodeException; //导入依赖的package包/类
/**
 * {@inheritDoc }
 */
@Override
public void encode(Object object, Type bodyType, RequestTemplate template) throws EncodeException {
    if (isFormRequest(bodyType)) {
        encodeMultipartFormRequest((Map<String, ?>) object, template);
    } else {
        encodeRequest(object, jsonHeaders, template);
    }
}
 
开发者ID:pcan,项目名称:feign-client-test,代码行数:12,代码来源:FeignSpringFormEncoder.java


示例13: encodeMultipartFiles

import feign.codec.EncodeException; //导入依赖的package包/类
/**
 * Fills the request map with {@link HttpEntity}s containing the given {@link MultipartFile}s.
 * Sets the {@code Content-type} header to {@code application/octet-stream} for each file.
 *
 * @param the current request map.
 * @param name the name of the array field in the multipart form.
 * @param files
 */
private void encodeMultipartFiles(LinkedMultiValueMap<String, Object> map, String name, List<? extends MultipartFile> files) {
    HttpHeaders filePartHeaders = new HttpHeaders();
    filePartHeaders.setContentType(MediaType.APPLICATION_OCTET_STREAM);
    try {
        for (MultipartFile file : files) {
            Resource multipartFileResource = new MultipartFileResource(file.getOriginalFilename(), file.getSize(), file.getInputStream());
            map.add(name, new HttpEntity<>(multipartFileResource, filePartHeaders));
        }
    } catch (IOException ex) {
        throw new EncodeException("Cannot encode request.", ex);
    }
}
 
开发者ID:pcan,项目名称:feign-client-test,代码行数:21,代码来源:FeignSpringFormEncoder.java


示例14: encode

import feign.codec.EncodeException; //导入依赖的package包/类
/**
 * Converts objects to an appropriate representation in the template.
 *
 * @param object   what to encode as the request body.
 * @param bodyType the type the object should be encoded as. {@code Map<String, ?>}, if form
 *                 encoding.
 * @param template the request template to populate.
 * @throws feign.codec.EncodeException when encoding failed due to a checked exception.
 */
@Override
public void encode(final Object object, final Type bodyType, final RequestTemplate template)
    throws EncodeException {
    try {
        template.body(mapper.writeValueAsString(object));
    } catch (JsonProcessingException e) {
        throw new EncodeException(e.getMessage(), e);
    }
}
 
开发者ID:Netflix,项目名称:metacat,代码行数:19,代码来源:JacksonEncoder.java


示例15: encode

import feign.codec.EncodeException; //导入依赖的package包/类
@Override
public void encode (Object object, Type bodyType, RequestTemplate template) throws EncodeException {
  if (!bodyType.equals(MultipartFile.class)) {
    super.encode(object, bodyType, template);
    return;
  }

  val file = (MultipartFile) object;
  val data = singletonMap(file.getName(), object);
  super.encode(data, MAP_STRING_WILDCARD, template);
}
 
开发者ID:OpenFeign,项目名称:feign-form,代码行数:12,代码来源:SpringFormEncoder.java


示例16: encodeMultipartFormRequest

import feign.codec.EncodeException; //导入依赖的package包/类
private void encodeMultipartFormRequest(final Object value, final RequestTemplate template) {
    if (value == null) {
        throw new EncodeException("Cannot encode request with null value.");
    }
    if (!isMultipartFile(value)) {
        throw new EncodeException("Only multipart can be handled by this encoder");
    }
    encodeRequest(encodeMultipartFile((MultipartFile) value), multipartHeaders, template);
}
 
开发者ID:eclipse,项目名称:hawkbit-examples,代码行数:10,代码来源:FeignMultipartEncoder.java


示例17: encodeRequest

import feign.codec.EncodeException; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private void encodeRequest(final Object value, final HttpHeaders requestHeaders, final RequestTemplate template) {
    final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    final HttpOutputMessage dummyRequest = new HttpOutputMessageImpl(outputStream, requestHeaders);
    try {
        final Class<?> requestType = value.getClass();
        final MediaType requestContentType = requestHeaders.getContentType();
        for (final HttpMessageConverter<?> messageConverter : converters) {
            if (messageConverter.canWrite(requestType, requestContentType)) {
                ((HttpMessageConverter<Object>) messageConverter).write(value, requestContentType, dummyRequest);
                break;
            }
        }
    } catch (final IOException ex) {
        throw new EncodeException("Cannot encode request.", ex);
    }
    final HttpHeaders headers = dummyRequest.getHeaders();
    if (headers != null) {
        for (final Entry<String, List<String>> entry : headers.entrySet()) {
            template.header(entry.getKey(), entry.getValue());
        }
    }
    /*
     * we should use a template output stream... this will cause issues if
     * files are too big, since the whole request will be in memory.
     */
    template.body(outputStream.toByteArray(), UTF_8);
}
 
开发者ID:eclipse,项目名称:hawkbit-examples,代码行数:29,代码来源:FeignMultipartEncoder.java


示例18: encodeMultipartFile

import feign.codec.EncodeException; //导入依赖的package包/类
private MultiValueMap<String, Object> encodeMultipartFile(final MultipartFile file) {
    try {
        final MultiValueMap<String, Object> multiValueMap = new LinkedMultiValueMap<>();
        multiValueMap.add("file", new MultipartFileResource(file.getName(), file.getSize(), file.getInputStream()));
        return multiValueMap;
    } catch (final IOException ex) {
        throw new EncodeException("Cannot encode request.", ex);
    }
}
 
开发者ID:eclipse,项目名称:hawkbit-examples,代码行数:10,代码来源:FeignMultipartEncoder.java


示例19: encode

import feign.codec.EncodeException; //导入依赖的package包/类
@Override
public void encode(final Object object, final Type bodyType, final RequestTemplate template)
    throws EncodeException {
  encoder.encode(object, bodyType, template);
}
 
开发者ID:client-side,项目名称:completable-feign,代码行数:6,代码来源:TestCoder.java


示例20: encode

import feign.codec.EncodeException; //导入依赖的package包/类
@Override
public void encode(Object requestBody, Type bodyType, RequestTemplate request)
		throws EncodeException {
	// template.body(conversionService.convert(object, String.class));
	if (requestBody != null) {
		Class<?> requestType = requestBody.getClass();
		Collection<String> contentTypes = request.headers().get("Content-Type");

		MediaType requestContentType = null;
		if (contentTypes != null && !contentTypes.isEmpty()) {
			String type = contentTypes.iterator().next();
			requestContentType = MediaType.valueOf(type);
		}

		for (HttpMessageConverter<?> messageConverter : this.messageConverters
				.getObject().getConverters()) {
			if (messageConverter.canWrite(requestType, requestContentType)) {
				if (log.isDebugEnabled()) {
					if (requestContentType != null) {
						log.debug("Writing [" + requestBody + "] as \""
								+ requestContentType + "\" using ["
								+ messageConverter + "]");
					}
					else {
						log.debug("Writing [" + requestBody + "] using ["
								+ messageConverter + "]");
					}

				}

				FeignOutputMessage outputMessage = new FeignOutputMessage(request);
				try {
					@SuppressWarnings("unchecked")
					HttpMessageConverter<Object> copy = (HttpMessageConverter<Object>) messageConverter;
					copy.write(requestBody, requestContentType, outputMessage);
				}
				catch (IOException ex) {
					throw new EncodeException("Error converting request body", ex);
				}
				// clear headers
				request.headers(null);
				// converters can modify headers, so update the request
				// with the modified headers
				request.headers(getHeaders(outputMessage.getHeaders()));

				// do not use charset for binary data
				if (messageConverter instanceof ByteArrayHttpMessageConverter) {
					request.body(outputMessage.getOutputStream().toByteArray(), null);
				} else {
					request.body(outputMessage.getOutputStream().toByteArray(), Charset.forName("UTF-8"));
				}
				return;
			}
		}
		String message = "Could not write request: no suitable HttpMessageConverter "
				+ "found for request type [" + requestType.getName() + "]";
		if (requestContentType != null) {
			message += " and content type [" + requestContentType + "]";
		}
		throw new EncodeException(message);
	}
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-netflix,代码行数:63,代码来源:SpringEncoder.java



注:本文中的feign.codec.EncodeException类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java TextBox类代码示例发布时间:2022-05-22
下一篇:
Java ValidationException类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap