use of com.palantir.logsafe.exceptions.SafeIllegalStateException in project tritium by palantir.
the class RemotingCompatibleTracingInvocationEventHandler method isUsingMultipleTracers.
// explicitly qualifying given remoting3 vs. tracing
@SuppressWarnings("UnnecessarilyFullyQualified")
private static boolean isUsingMultipleTracers(Class<?> tracersClass) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
if (tracersClass != null) {
Method wrapMethod = tracersClass.getMethod("wrap", Runnable.class);
if (wrapMethod != null) {
Object wrappedTrace = wrapMethod.invoke(null, (Runnable) () -> {
});
String expectedTracingPackage = com.palantir.tracing.Tracers.class.getPackage().getName();
String actualTracingPackage = wrappedTrace.getClass().getPackage().getName();
if (!Objects.equals(expectedTracingPackage, actualTracingPackage)) {
if (shouldLogFallbackError.compareAndSet(/* expectedValue= */
false, /* newValue= */
true)) {
log.error("Multiple tracing implementations detected, expected '{}' but found '{}'," + " using legacy remoting3 tracing for backward compatibility", SafeArg.of("expectedPackage", expectedTracingPackage), SafeArg.of("actualPackage", actualTracingPackage), new SafeIllegalStateException("Multiple tracing implementations detected"));
}
return true;
}
}
}
return false;
}
use of com.palantir.logsafe.exceptions.SafeIllegalStateException in project dialogue by palantir.
the class ReloadingClientFactory method getStickyChannels.
@Override
public StickyChannelFactory getStickyChannels(String serviceName) {
Refreshable<List<Channel>> perHostChannels = perHost(serviceName).getPerHostChannels();
Refreshable<Supplier<Channel>> bestSupplier = perHostChannels.map(singleHostChannels -> {
if (singleHostChannels.isEmpty()) {
EmptyInternalDialogueChannel alwaysThrowing = new EmptyInternalDialogueChannel(() -> new SafeIllegalStateException("Service not configured", SafeArg.of("serviceName", serviceName)));
return () -> alwaysThrowing;
}
if (singleHostChannels.size() == 1) {
return () -> singleHostChannels.get(0);
}
return StickyEndpointChannels.builder().channels(singleHostChannels.stream().map(c -> (DialogueChannel) c).collect(Collectors.toList())).channelName(ChannelNames.reloading(serviceName, params)).taggedMetricRegistry(params.taggedMetrics()).build();
});
return new StickyChannelFactory() {
@Override
public Channel getStickyChannel() {
return bestSupplier.get().get();
}
@Override
public <T> T getCurrentBest(Class<T> clientInterface) {
return Reflection.callStaticFactoryMethod(clientInterface, getStickyChannel(), params.runtime());
}
@Override
public String toString() {
return "StickyChannelFactory{" + bestSupplier.get() + '}';
}
};
}
use of com.palantir.logsafe.exceptions.SafeIllegalStateException in project dialogue by palantir.
the class ReloadingClientFactory method getInternalDialogueChannel.
private Refreshable<InternalDialogueChannel> getInternalDialogueChannel(String serviceName) {
Preconditions.checkNotNull(serviceName, "serviceName");
String channelName = ChannelNames.reloading(serviceName, params);
return params.scb().map(block -> {
Preconditions.checkNotNull(block, "Refreshable must not provide a null ServicesConfigBlock");
if (!block.services().containsKey(serviceName)) {
return new EmptyInternalDialogueChannel(() -> new SafeIllegalStateException("Service not configured (config block not present)", SafeArg.of("serviceName", serviceName), SafeArg.of("available", block.services().keySet())));
}
if (block.services().get(serviceName).uris().isEmpty()) {
return new EmptyInternalDialogueChannel(() -> {
Map<String, PartialServiceConfiguration> servicesWithUris = Maps.filterValues(block.services(), c -> !c.uris().isEmpty());
return new SafeIllegalStateException("Service not configured (no URIs)", SafeArg.of("serviceName", serviceName), SafeArg.of("available", servicesWithUris.keySet()));
});
}
ServiceConfiguration serviceConf = ServiceConfigurationFactory.of(block).get(serviceName);
DialogueChannel dialogueChannel = cache.getNonReloadingChannel(params, serviceConf, channelName, OptionalInt.empty());
return new InternalDialogueChannelFromDialogueChannel(dialogueChannel);
});
}
use of com.palantir.logsafe.exceptions.SafeIllegalStateException in project conjure-java by palantir.
the class ParamTypesResolver method getParameterType.
@SuppressWarnings("CyclomaticComplexity")
public Optional<ParameterType> getParameterType(VariableElement variableElement) {
List<AnnotationMirror> paramAnnotationMirrors = new ArrayList<>();
for (AnnotationMirror annotationMirror : variableElement.getAnnotationMirrors()) {
TypeElement annotationTypeElement = MoreElements.asType(annotationMirror.getAnnotationType().asElement());
if (SUPPORTED_ANNOTATIONS.contains(annotationTypeElement.getQualifiedName().toString())) {
paramAnnotationMirrors.add(annotationMirror);
}
}
List<AnnotationReflector> annotationReflectors = paramAnnotationMirrors.stream().map(ImmutableAnnotationReflector::of).collect(Collectors.toList());
boolean isSafe = annotationReflectors.stream().anyMatch(annotation -> annotation.isAnnotation(Safe.class));
boolean isUnsafe = annotationReflectors.stream().anyMatch(annotation -> annotation.isAnnotation(Unsafe.class));
SafeLoggingAnnotation safeLoggable = isUnsafe ? SafeLoggingAnnotation.UNSAFE : isSafe ? SafeLoggingAnnotation.SAFE : SafeLoggingAnnotation.UNKNOWN;
List<AnnotationReflector> otherAnnotationReflectors = annotationReflectors.stream().filter(annotation -> !annotation.isAnnotation(Safe.class) && !annotation.isAnnotation(Unsafe.class)).collect(Collectors.toList());
if (otherAnnotationReflectors.isEmpty()) {
if (!safeLoggable.equals(SafeLoggingAnnotation.UNKNOWN)) {
context.reportError("Parameter type cannot be annotated with safe logging annotations", variableElement, SafeArg.of("type", variableElement.asType()));
return Optional.empty();
}
if (context.isSameTypes(variableElement.asType(), AuthHeader.class)) {
return Optional.of(ParameterTypes.authHeader(variableElement.getSimpleName().toString()));
} else if (context.isSameTypes(variableElement.asType(), HttpServerExchange.class)) {
return Optional.of(ParameterTypes.exchange());
} else if (context.isSameTypes(variableElement.asType(), RequestContext.class)) {
return Optional.of(ParameterTypes.context());
} else {
context.reportError("At least one annotation should be present or type should be InputStream", variableElement, SafeArg.of("requestBody", InputStream.class), SafeArg.of("supportedAnnotations", PARAM_ANNOTATION_CLASSES));
return Optional.empty();
}
}
if (otherAnnotationReflectors.size() > 1) {
context.reportError("Only single annotation can be used", variableElement, SafeArg.of("annotations", otherAnnotationReflectors));
return Optional.empty();
}
// TODO(ckozak): More validation of values.
AnnotationReflector annotationReflector = Iterables.getOnlyElement(otherAnnotationReflectors);
if (annotationReflector.isAnnotation(Handle.Body.class)) {
return Optional.of(bodyParameter(variableElement, annotationReflector));
} else if (annotationReflector.isAnnotation(Handle.Header.class)) {
return Optional.of(headerParameter(variableElement, annotationReflector, safeLoggable));
} else if (annotationReflector.isAnnotation(Handle.PathParam.class)) {
return Optional.of(pathParameter(variableElement, annotationReflector, safeLoggable));
} else if (annotationReflector.isAnnotation(Handle.PathMultiParam.class)) {
return Optional.of(pathMultiParameter(variableElement, annotationReflector, safeLoggable));
} else if (annotationReflector.isAnnotation(Handle.QueryParam.class)) {
return Optional.of(queryParameter(variableElement, annotationReflector, safeLoggable));
} else if (annotationReflector.isAnnotation(Handle.Cookie.class)) {
return cookieParameter(variableElement, annotationReflector, safeLoggable);
}
throw new SafeIllegalStateException("Not possible");
}
Aggregations