本文整理了Java中feign.Util
类的一些代码示例,展示了Util
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Util
类的具体详情如下:
包路径:feign.Util
类名称:Util
[英]Utilities, typically copied in from guava, so as to avoid dependency conflicts.
[中]实用程序,通常从guava中复制,以避免依赖冲突。
代码示例来源:origin: spring-cloud-incubator/spring-cloud-alibaba
SentinelInvocationHandler(Target<?> target, Map<Method, MethodHandler> dispatch) {
this.target = checkNotNull(target, "target");
this.dispatch = checkNotNull(dispatch, "dispatch");
}
代码示例来源:origin: org.springframework.cloud/spring-cloud-openfeign-core
private void parseConsumes(MethodMetadata md, Method method,
RequestMapping annotation) {
String[] serverConsumes = annotation.consumes();
String clientProduces = serverConsumes.length == 0 ? null
: emptyToNull(serverConsumes[0]);
if (clientProduces != null) {
md.template().header(CONTENT_TYPE, clientProduces);
}
}
代码示例来源:origin: spring-cloud/spring-cloud-openfeign
@Override
public boolean processArgument(AnnotatedParameterContext context, Annotation annotation, Method method) {
int parameterIndex = context.getParameterIndex();
Class<?> parameterType = method.getParameterTypes()[parameterIndex];
MethodMetadata data = context.getMethodMetadata();
if (Map.class.isAssignableFrom(parameterType)) {
checkState(data.headerMapIndex() == null, "Header map can only be present once.");
data.headerMapIndex(parameterIndex);
return true;
}
String name = ANNOTATION.cast(annotation).value();
checkState(emptyToNull(name) != null,
"RequestHeader.value() was empty on parameter %s", parameterIndex);
context.setParameterName(name);
Collection<String> header = context.setTemplateParameter(name, data.template().headers().get(name));
data.template().header(name, header);
return true;
}
}
代码示例来源:origin: com.netflix.feign/feign-jaxrs
private void handleProducesAnnotation(MethodMetadata data, Produces produces, String name) {
String[] serverProduces = produces.value();
String clientAccepts = serverProduces.length == 0 ? null : emptyToNull(serverProduces[0]);
checkState(clientAccepts != null, "Produces.value() was empty on %s", name);
data.template().header(ACCEPT, (String) null); // remove any previous produces
data.template().header(ACCEPT, clientAccepts);
}
代码示例来源:origin: spring-cloud/spring-cloud-openfeign
@Override
public boolean processArgument(AnnotatedParameterContext context, Annotation annotation, Method method) {
String name = ANNOTATION.cast(annotation).value();
checkState(emptyToNull(name) != null,
"PathVariable annotation was empty on param %s.", context.getParameterIndex());
context.setParameterName(name);
MethodMetadata data = context.getMethodMetadata();
String varName = '{' + name + '}';
if (!data.template().url().contains(varName)
&& !searchMapValues(data.template().queries(), varName)
&& !searchMapValues(data.template().headers(), varName)) {
data.formParams().add(name);
}
return true;
}
代码示例来源:origin: kptfh/feign-reactive
public PublisherClientMethodHandler(Target target,
MethodMetadata methodMetadata,
PublisherHttpClient publisherClient) {
this.target = checkNotNull(target, "target must be not null");
this.methodMetadata = checkNotNull(methodMetadata,
"methodMetadata must be not null");
this.publisherClient = checkNotNull(publisherClient, "client must be not null");
this.pathExpander = buildExpandFunction(methodMetadata.template().url());
this.headerExpanders = buildExpanders(methodMetadata.template().headers());
this.queriesAll = new HashMap<>(methodMetadata.template().queries());
if (methodMetadata.formParams() != null) {
methodMetadata.formParams()
.forEach(param -> add(queriesAll, param, "{" + param + "}"));
}
this.queryExpanders = buildExpanders(queriesAll);
}
代码示例来源:origin: com.palantir.remoting3/jaxrs-clients
@Override
public void encode(Object object, Type bodyType, RequestTemplate template) throws EncodeException {
if (bodyType.equals(InputStream.class)) {
try {
template.body(Util.toByteArray((InputStream) object), StandardCharsets.UTF_8);
} catch (IOException e) {
throw new RuntimeException(e);
}
} else {
delegate.encode(object, bodyType, template);
}
}
}
代码示例来源:origin: io.github.reactivefeign/feign-reactive-core
private ReactiveClientMethodHandler(Target target, MethodMetadata methodMetadata,
ReactiveHttpClient reactiveClient) {
this.target = checkNotNull(target, "target must be not null");
this.methodMetadata = checkNotNull(methodMetadata,
"methodMetadata must be not null");
this.reactiveClient = checkNotNull(reactiveClient, "client must be not null");
this.defaultUriBuilderFactory = new DefaultUriBuilderFactory(target.url());
Stream<AbstractMap.SimpleImmutableEntry<String, String>> simpleImmutableEntryStream = methodMetadata
.template().headers().entrySet().stream()
.flatMap(e -> e.getValue().stream()
.map(v -> new AbstractMap.SimpleImmutableEntry<>(e.getKey(), v)));
this.headerExpanders = simpleImmutableEntryStream.collect(groupingBy(
entry -> entry.getKey(),
mapping(entry -> buildExpandHeaderFunction(entry.getValue()), toList())));
}
代码示例来源:origin: kptfh/feign-reactive
public static Type getBodyActualType(Type bodyType) {
return ofNullable(bodyType).map(type -> {
if (type instanceof ParameterizedType) {
Class<?> bodyClass = (Class<?>) ((ParameterizedType) type).getRawType();
if (Publisher.class.isAssignableFrom(bodyClass)) {
return resolveLastTypeParameter(bodyType, bodyClass);
}
else {
return type;
}
}
else {
return type;
}
}).orElse(null);
}
代码示例来源:origin: com.marvinformatics.feign/feign-mock
public MockClient ok(RequestKey requestKey, InputStream responseBody) throws IOException {
return ok(requestKey, Util.toByteArray(responseBody));
}
代码示例来源:origin: com.netflix.feign/feign-core
@Override
protected void processAnnotationOnClass(MethodMetadata data, Class<?> targetType) {
if (targetType.isAnnotationPresent(Headers.class)) {
String[] headersOnType = targetType.getAnnotation(Headers.class).value();
checkState(headersOnType.length > 0, "Headers annotation was empty on type %s.",
targetType.getName());
Map<String, Collection<String>> headers = toMap(headersOnType);
headers.putAll(data.template().headers());
data.template().headers(null); // to clear
data.template().headers(headers);
}
}
代码示例来源:origin: OpenFeign/feign-vertx
@Override
public List<MethodMetadata> parseAndValidatateMetadata(final Class<?> targetType) {
checkNotNull(targetType, "Argument targetType must be not null");
final List<MethodMetadata> metadatas = delegate.parseAndValidatateMetadata(targetType);
for (final MethodMetadata metadata : metadatas) {
final Type type = metadata.returnType();
if (type instanceof ParameterizedType
&& ((ParameterizedType) type).getRawType().equals(Future.class)) {
final Type actualType = resolveLastTypeParameter(type, Future.class);
metadata.returnType(actualType);
} else {
throw new IllegalStateException(String.format(
"Method %s of contract %s doesn't returns io.vertx.core.Future",
metadata.configKey(), targetType.getSimpleName()));
}
}
return metadatas;
}
}
代码示例来源:origin: com.netflix.feign/feign-core
public HardCodedTarget(Class<T> type, String name, String url) {
this.type = checkNotNull(type, "type");
this.name = checkNotNull(emptyToNull(name), "name");
this.url = checkNotNull(emptyToNull(url), "url");
}
代码示例来源:origin: org.springframework.cloud/spring-cloud-openfeign-core
private void checkOne(Method method, Object[] values, String fieldName) {
checkState(values != null && values.length == 1,
"Method %s can only contain 1 %s field. Found: %s", method.getName(),
fieldName, values == null ? null : Arrays.asList(values));
}
代码示例来源:origin: ppdai-incubator/raptor
@Override
protected void processAnnotationOnClass(MethodMetadata data, Class<?> clz) {
if (clz.getInterfaces().length == 0) {
RequestMapping classAnnotation = findMergedAnnotation(clz,
RequestMapping.class);
if (classAnnotation != null) {
// Prepend path from class annotation if specified
if (classAnnotation.value().length > 0) {
String pathValue = emptyToNull(classAnnotation.value()[0]);
pathValue = resolve(pathValue);
if (!pathValue.startsWith("/")) {
pathValue = "/" + pathValue;
}
data.template().insert(0, pathValue);
}
}
}
}
代码示例来源:origin: OpenFeign/feign-vertx
@Override
@SuppressWarnings("unchecked")
public <T> T newInstance(final Target<T> target) {
checkNotNull(target, "Argument target must be not null");
final Map<String, MethodHandler> nameToHandler = targetToHandlersByName.apply(target);
final Map<Method, MethodHandler> methodToHandler = new HashMap<>();
final List<DefaultMethodHandler> defaultMethodHandlers = new ArrayList<>();
for (final Method method : target.type().getMethods()) {
if (isDefault(method)) {
final DefaultMethodHandler handler = new DefaultMethodHandler(method);
defaultMethodHandlers.add(handler);
methodToHandler.put(method, handler);
} else {
methodToHandler.put(method, nameToHandler.get(Feign.configKey(target.type(), method)));
}
}
final InvocationHandler handler = factory.create(target, methodToHandler);
final T proxy = (T) Proxy.newProxyInstance(
target.type().getClassLoader(),
new Class<?>[] { target.type() },
handler);
for (final DefaultMethodHandler defaultMethodHandler : defaultMethodHandlers) {
defaultMethodHandler.bindTo(proxy);
}
return proxy;
}
代码示例来源:origin: com.netflix.feign/feign-core
public RequestTemplate method(String method) {
this.method = checkNotNull(method, "method");
checkArgument(method.matches("^[A-Z]+$"), "Invalid HTTP Method: %s", method);
return this;
}
代码示例来源:origin: com.netflix.feign/feign-core
private RequestTemplate doQuery(boolean encoded, String name, String... values) {
checkNotNull(name, "name");
String paramName = encoded ? name : encodeIfNotVariable(name);
queries.remove(paramName);
if (values != null && values.length > 0 && values[0] != null) {
ArrayList<String> paramValues = new ArrayList<String>();
for (String value : values) {
paramValues.add(encoded ? value : encodeIfNotVariable(value));
}
this.queries.put(paramName, paramValues);
}
return this;
}
代码示例来源:origin: com.netflix.feign/feign-core
@Override
public Object decode(Response response, Type type) throws IOException {
if (response.status() == 404) return Util.emptyValueOf(type);
if (response.body() == null) return null;
if (byte[].class.equals(type)) {
return Util.toByteArray(response.body().asInputStream());
}
return super.decode(response, type);
}
}
代码示例来源:origin: com.netflix.feign/feign-core
@Override
public List<MethodMetadata> parseAndValidatateMetadata(Class<?> targetType) {
checkState(targetType.getTypeParameters().length == 0, "Parameterized types unsupported: %s",
targetType.getSimpleName());
checkState(targetType.getInterfaces().length <= 1, "Only single inheritance supported: %s",
targetType.getSimpleName());
if (targetType.getInterfaces().length == 1) {
checkState(targetType.getInterfaces()[0].getInterfaces().length == 0,
"Only single-level inheritance supported: %s",
targetType.getSimpleName());
}
Map<String, MethodMetadata> result = new LinkedHashMap<String, MethodMetadata>();
for (Method method : targetType.getMethods()) {
if (method.getDeclaringClass() == Object.class ||
(method.getModifiers() & Modifier.STATIC) != 0 ||
Util.isDefault(method)) {
continue;
}
MethodMetadata metadata = parseAndValidateMetadata(targetType, method);
checkState(!result.containsKey(metadata.configKey()), "Overrides unsupported: %s",
metadata.configKey());
result.put(metadata.configKey(), metadata);
}
return new ArrayList<MethodMetadata>(result.values());
}
内容来源于网络,如有侵权,请联系作者删除!