org.apiguardian.api.API Java Examples

The following examples show how to use org.apiguardian.api.API. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MethodNotAllowedAdviceTrait.java    From problem-spring-web with MIT License 6 votes vote down vote up
@API(status = INTERNAL)
@ExceptionHandler
default Mono<ResponseEntity<Problem>> handleRequestMethodNotSupportedException(
        final MethodNotAllowedException exception,
        final ServerWebExchange request) {

    final Set<HttpMethod> methods = exception.getSupportedMethods();

    if (methods.isEmpty()) {
        return create(Status.METHOD_NOT_ALLOWED, exception, request);
    }

    final HttpHeaders headers = new HttpHeaders();
    headers.setAllow(methods);

    return create(Status.METHOD_NOT_ALLOWED, exception, request, headers);
}
 
Example #2
Source File: QueryFilters.java    From logbook with MIT License 6 votes vote down vote up
@API(status = EXPERIMENTAL)
public static QueryFilter replaceQuery(
        final Predicate<String> predicate, final String replacement) {

    final Pattern pattern = compile("(?<name>[^&]*?)=(?:[^&]*)");

    return query -> {
        final Matcher matcher = pattern.matcher(query);
        final StringBuffer result = new StringBuffer(query.length());

        while (matcher.find()) {
            if (predicate.test(matcher.group("name"))) {
                matcher.appendReplacement(result, "${name}");
                result.append('=');
                result.append(replacement);
            } else {
                matcher.appendReplacement(result, "$0");
            }
        }
        matcher.appendTail(result);

        return result.toString();
    };
}
 
Example #3
Source File: RoutingTree.java    From riptide with MIT License 6 votes vote down vote up
@API(status = EXPERIMENTAL)
default RoutingTree<A> merge(final RoutingTree<A> other) {
    final Map<A, Route> bindings = new LinkedHashMap<>(keySet().size() + other.keySet().size());

    keySet().forEach(attribute ->
            bindings.merge(attribute, get(attribute)
                    .orElseThrow(IllegalStateException::new), Route::merge));

    getWildcard().ifPresent(route ->
            bindings.merge(null, route, Route::merge));

    other.keySet().forEach(attribute ->
            bindings.merge(attribute, other.get(attribute)
                    .orElseThrow(IllegalStateException::new), Route::merge));

    other.getWildcard().ifPresent(route ->
            bindings.merge(null, route, Route::merge));

    return dispatch(getNavigator(), bindings.entrySet().stream()
            .map(e -> Binding.create(e.getKey(), e.getValue()))
            .collect(toList()));
}
 
Example #4
Source File: FastJsonHttpLogFormatter.java    From logbook with MIT License 6 votes vote down vote up
@API(status = EXPERIMENTAL)
public void prepare(
        final Precorrelation precorrelation,
        final HttpRequest request,
        final JsonGenerator generator) throws IOException {

    generator.writeStringField("origin",
            request.getOrigin() == LOCAL ? "local" : "remote");
    generator.writeStringField("type", "request");
    generator.writeStringField("correlation", precorrelation.getId());
    generator.writeStringField("protocol", request.getProtocolVersion());
    generator.writeStringField("remote", request.getRemote());
    generator.writeStringField("method", request.getMethod());
    generator.writeStringField("uri", reconstructUri(request));

    writeHeaders(request, generator);
    writeBody(request, generator);
}
 
Example #5
Source File: LocServiceAdviceTrait.java    From loc-framework with MIT License 6 votes vote down vote up
@API(status = API.Status.INTERNAL)
@ExceptionHandler(value = LocServiceException.class)
default ResponseEntity<Problem> handleHnServiceException(
    final LocServiceException hnServiceException, final NativeWebRequest request) {
  int code = hnServiceException.getCode();
  if(code < 0) {
    code *= -1;
  }

  if(code < 10000) {
    code += 10000;
  }
  return this.create(hnServiceException,
      ProblemUtil.createProblem(hnServiceException.getMsg(), code),
      request);
}
 
Example #6
Source File: ProblemAdviceTrait.java    From problem-spring-web with MIT License 5 votes vote down vote up
@API(status = INTERNAL)
@ExceptionHandler
default Mono<ResponseEntity<Problem>> handleProblem(
        final ThrowableProblem problem,
        final ServerWebExchange request) {
    return create(problem, request);
}
 
Example #7
Source File: NotAcceptableAdviceTrait.java    From problem-spring-web with MIT License 5 votes vote down vote up
@API(status = INTERNAL)
@ExceptionHandler
default Mono<ResponseEntity<Problem>> handleMediaTypeNotAcceptable(
        final NotAcceptableStatusException exception,
        final ServerWebExchange request) {
    return create(Status.NOT_ACCEPTABLE, exception, request);
}
 
Example #8
Source File: ResponseStatusAdviceTrait.java    From problem-spring-web with MIT License 5 votes vote down vote up
@API(status = INTERNAL)
@ExceptionHandler
default Mono<ResponseEntity<Problem>> handleResponseStatusException(
        final ResponseStatusException exception,
        final ServerWebExchange request) {
    return create(exception.getStatus(), exception, request);
}
 
Example #9
Source File: ConstraintViolationAdviceTrait.java    From problem-spring-web with MIT License 5 votes vote down vote up
@API(status = INTERNAL)
@ExceptionHandler
default Mono<ResponseEntity<Problem>> handleConstraintViolation(
        final ConstraintViolationException exception,
        final ServerWebExchange request) {

    final List<Violation> violations = exception.getConstraintViolations().stream()
            .map(this::createViolation)
            .collect(toList());

    return newConstraintViolationProblem(exception, violations, request);
}
 
Example #10
Source File: LogbookAutoConfiguration.java    From logbook with MIT License 5 votes vote down vote up
@API(status = INTERNAL)
@Bean
@ConditionalOnMissingBean(HttpLogFormatter.class)
@ConditionalOnProperty(name = "logbook.format.style", havingValue = "curl")
public HttpLogFormatter curlFormatter() {
    return new CurlHttpLogFormatter();
}
 
Example #11
Source File: OpenTracingProxyAutoConfiguration.java    From opentracing-toolbox with MIT License 5 votes vote down vote up
@API(status = INTERNAL)
@Bean
@ConditionalOnMissingBean(Naming.class)
@ConditionalOnProperty(
        name = "opentracing.proxy.rename.enabled",
        havingValue = "true",
        matchIfMissing = true)
public Rename rename(final ProxyProperties properties) {
    return new Rename(properties.getRename().getFormat());
}
 
Example #12
Source File: UnsupportedOperationAdviceTrait.java    From problem-spring-web with MIT License 5 votes vote down vote up
@API(status = INTERNAL)
@ExceptionHandler
default ResponseEntity<Problem> handleUnsupportedOperation(
        final UnsupportedOperationException exception,
        final NativeWebRequest request) {
    return create(Status.NOT_IMPLEMENTED, exception, request);
}
 
Example #13
Source File: ResponseStatusAdviceTrait.java    From problem-spring-web with MIT License 5 votes vote down vote up
@API(status = INTERNAL)
@ExceptionHandler
default ResponseEntity<Problem> handleResponseStatusException(
        final ResponseStatusException exception,
        final NativeWebRequest request) {
    return create(new HttpStatusAdapter(exception.getStatus()),exception, request);
}
 
Example #14
Source File: ProblemAdviceTrait.java    From problem-spring-web with MIT License 5 votes vote down vote up
@API(status = INTERNAL)
@ExceptionHandler
default ResponseEntity<Problem> handleProblem(
        final ThrowableProblem problem,
        final NativeWebRequest request) {
    return create(problem, request);
}
 
Example #15
Source File: NotAcceptableAdviceTrait.java    From problem-spring-web with MIT License 5 votes vote down vote up
@API(status = INTERNAL)
@ExceptionHandler
default ResponseEntity<Problem> handleMediaTypeNotAcceptable(
        final HttpMediaTypeNotAcceptableException exception,
        final NativeWebRequest request) {
    return create(Status.NOT_ACCEPTABLE, exception, request);
}
 
Example #16
Source File: SocketTimeoutAdviceTrait.java    From problem-spring-web with MIT License 5 votes vote down vote up
@API(status = INTERNAL)
@ExceptionHandler
default Mono<ResponseEntity<Problem>> handleSocketTimeout(
        final SocketTimeoutException exception,
        final ServerWebExchange request) {
    return create(Status.GATEWAY_TIMEOUT, exception, request);
}
 
Example #17
Source File: MissingServletRequestParameterAdviceTrait.java    From problem-spring-web with MIT License 5 votes vote down vote up
@API(status = INTERNAL)
@ExceptionHandler
default ResponseEntity<Problem> handleMissingServletRequestParameter(
        final MissingServletRequestParameterException exception,
        final NativeWebRequest request) {
    return create(Status.BAD_REQUEST, exception, request);
}
 
Example #18
Source File: OpenApiValidationAdviceTrait.java    From problem-spring-web with MIT License 5 votes vote down vote up
@API(status = INTERNAL)
@ExceptionHandler
default Mono<ResponseEntity<Problem>> handleInvalidRequest(
        final InvalidRequestException exception,
        final ServerWebExchange request) {

    return newConstraintViolationProblem(exception, request, exception.getValidationReport());
}
 
Example #19
Source File: LogbookAutoConfiguration.java    From logbook with MIT License 5 votes vote down vote up
@API(status = INTERNAL)
@Bean
@ConditionalOnMissingBean(HttpLogFormatter.class)
@ConditionalOnProperty(name = "logbook.format.style", havingValue = "splunk")
public HttpLogFormatter splunkHttpLogFormatter() {
    return new SplunkHttpLogFormatter();
}
 
Example #20
Source File: MissingServletRequestPartAdviceTrait.java    From problem-spring-web with MIT License 5 votes vote down vote up
@API(status = INTERNAL)
@ExceptionHandler
default ResponseEntity<Problem> handleMissingServletRequestPart(
        final MissingServletRequestPartException exception,
        final NativeWebRequest request) {
    return create(Status.BAD_REQUEST, exception, request);
}
 
Example #21
Source File: LogbookAutoConfiguration.java    From logbook with MIT License 5 votes vote down vote up
@API(status = INTERNAL)
@Bean
@ConditionalOnMissingBean(HttpLogFormatter.class)
@ConditionalOnProperty(name = "logbook.format.style", havingValue = "http")
public HttpLogFormatter httpFormatter() {
    return new DefaultHttpLogFormatter();
}
 
Example #22
Source File: LogbookAutoConfiguration.java    From logbook with MIT License 5 votes vote down vote up
@API(status = INTERNAL)
@Bean
@Primary
@ConditionalOnBean(Sink.class)
@ConditionalOnProperty("logbook.write.chunk-size")
public Sink chunkingSink(final Sink sink) {
    return new ChunkingSink(sink, properties.getWrite().getChunkSize());
}
 
Example #23
Source File: LogbookAutoConfiguration.java    From logbook with MIT License 5 votes vote down vote up
@API(status = INTERNAL)
@Bean
@ConditionalOnMissingBean(Sink.class)
public Sink sink(
        @SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection") final HttpLogFormatter formatter,
        final HttpLogWriter writer) {
    return new DefaultSink(formatter, writer);
}
 
Example #24
Source File: LogbookAutoConfiguration.java    From logbook with MIT License 5 votes vote down vote up
@API(status = INTERNAL)
@Bean
@ConditionalOnMissingBean(Strategy.class)
@ConditionalOnProperty(name = "logbook.strategy", havingValue = "without-body")
public Strategy withoutBody() {
    return new WithoutBodyStrategy();
}
 
Example #25
Source File: MethodArgumentNotValidAdviceTrait.java    From problem-spring-web with MIT License 5 votes vote down vote up
@API(status = INTERNAL)
@ExceptionHandler
default ResponseEntity<Problem> handleMethodArgumentNotValid(
        final MethodArgumentNotValidException exception,
        final NativeWebRequest request) {
    return newConstraintViolationProblem(exception, createViolations(exception.getBindingResult()), request);
}
 
Example #26
Source File: LogbookAutoConfiguration.java    From logbook with MIT License 5 votes vote down vote up
@API(status = INTERNAL)
@Bean
@ConditionalOnMissingBean(BodyFilter.class)
public BodyFilter bodyFilter() {
    final LogbookProperties.Write write = properties.getWrite();
    final int maxBodySize = write.getMaxBodySize();

    if (maxBodySize < 0) {
        return defaultValue();
    }

    return BodyFilter.merge(defaultValue(), truncate(maxBodySize));
}
 
Example #27
Source File: LogbookAutoConfiguration.java    From logbook with MIT License 5 votes vote down vote up
@API(status = INTERNAL)
@Bean
@ConditionalOnMissingBean(HeaderFilter.class)
public HeaderFilter headerFilter() {
    final Set<String> headers = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
    headers.addAll(properties.getObfuscate().getHeaders());

    return headers.isEmpty() ?
            HeaderFilters.defaultValue() :
            replaceHeaders(headers, "XXX");
}
 
Example #28
Source File: OpenTracingProxyAutoConfiguration.java    From opentracing-toolbox with MIT License 5 votes vote down vote up
@API(status = INTERNAL)
@Bean
@ConditionalOnMissingBean(AutoTagging.class)
@ConditionalOnProperty(
        name = "opentracing.proxy.auto-tagging.enabled",
        havingValue = "true",
        matchIfMissing = true)
public AutoTagging autoTagging(final ProxyProperties properties) {
    final List<String> keys = properties.getAutoTagging().getKeys();
    final Map<String, String> mapping = keys.stream()
            .collect(toMap(identity(), identity()));

    return new AutoTagging(mapping);
}
 
Example #29
Source File: MessageNotReadableAdviceTrait.java    From problem-spring-web with MIT License 5 votes vote down vote up
@API(status = INTERNAL)
@ExceptionHandler
default ResponseEntity<Problem> handleMessageNotReadableException(
        final HttpMessageNotReadableException exception,
        final NativeWebRequest request) {
    return create(Status.BAD_REQUEST, exception, request);
}
 
Example #30
Source File: SocketTimeoutAdviceTrait.java    From problem-spring-web with MIT License 5 votes vote down vote up
@API(status = INTERNAL)
@ExceptionHandler
default ResponseEntity<Problem> handleSocketTimeout(
        final SocketTimeoutException exception,
        final NativeWebRequest request) {
    return create(Status.GATEWAY_TIMEOUT, exception, request);
}