Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ Beyond that, it is helpful to capture the following information:
If you open a Github issue with a request for help, please include as much of the information above as possible and do not forget to sanitize any request/response data posted.

## Development
The project depends on Java 8. To build from source and install to your local Maven cache, run the following:
The project depends on Java 8 to 21. To build from source and install to your local Maven cache, run the following:

```shell
$ git submodule update --init --recursive
Expand Down Expand Up @@ -297,6 +297,7 @@ Name | Description
`TEST_PROXY_PORT` | _(Optional)_ The port of a proxy to route all requests through. Defaults to `8080`.
`TEST_PROXY_USERNAME` | _(Optional)_ The username for a proxy to route all requests through
`TEST_SKIPSSLVALIDATION` | _(Optional)_ Whether to skip SSL validation when connecting to the Cloud Foundry instance. Defaults to `false`.
`UAA_API_REQUEST_LIMIT` | _(Optional)_ If your UAA server does rate limiting and returns 429 errors, set this variable to a value smaller than the limit. Defaults to `0` (no limit)

If you do not have access to a CloudFoundry instance with admin access, you can run one locally using [bosh-deployment](https://github.com/cloudfoundry/bosh-deployment) & [cf-deployment](https://github.com/cloudfoundry/cf-deployment/) and Virtualbox.

Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright 2013-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.cloudfoundry.reactor.uaa;

import java.util.Map;
import org.cloudfoundry.reactor.ConnectionContext;
import org.cloudfoundry.reactor.TokenProvider;
import org.cloudfoundry.uaa.ratelimit.Ratelimit;
import org.cloudfoundry.uaa.ratelimit.RatelimitRequest;
import org.cloudfoundry.uaa.ratelimit.RatelimitResponse;
import reactor.core.publisher.Mono;

public final class ReactorRatelimit extends AbstractUaaOperations implements Ratelimit {

/**
* Creates an instance
*
* @param connectionContext the {@link ConnectionContext} to use when communicating with the server
* @param root the root URI of the server. Typically something like {@code https://uaa.run.pivotal.io}.
* @param tokenProvider the {@link TokenProvider} to use when communicating with the server
* @param requestTags map with custom http headers which will be added to web request
*/
public ReactorRatelimit(
ConnectionContext connectionContext,
Mono<String> root,
TokenProvider tokenProvider,
Map<String, String> requestTags) {
super(connectionContext, root, tokenProvider, requestTags);
}

@Override
public Mono<RatelimitResponse> getRatelimit(RatelimitRequest request) {
return get(
request,
RatelimitResponse.class,
builder -> builder.pathSegment("RateLimitingStatus"))
.checkpoint();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* Copyright 2013-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.cloudfoundry.reactor.uaa;

import io.netty.handler.codec.http.HttpHeaders;
import java.util.Objects;
import java.util.function.Consumer;
import java.util.function.Function;
import org.cloudfoundry.reactor.uaa.UaaThrottler.Token;
import org.cloudfoundry.reactor.util.ErrorPayloadMapper;
import org.cloudfoundry.reactor.util.Operator;
import org.cloudfoundry.reactor.util.OperatorContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import reactor.core.publisher.Mono;
import reactor.netty.http.client.HttpClient;

public class UaaOperator extends Operator {

private Token token = null;
private static final Logger LOGGER = LoggerFactory.getLogger("cloudfoundry-client.test");

public UaaOperator(OperatorContext context, HttpClient httpClient, Token value, String caller) {
super(context, httpClient);
token = Objects.requireNonNull(value, "value must not be null");
if (token != UaaThrottler.NON_UAA_TOKEN) {
LOGGER.trace("UaaOperator creating instance for " + value.id() + " caller " + caller);
}
}

@Override
public UaaOperator followRedirects() {
return new UaaOperator(
this.context, super.getHttpClient().followRedirect(true), this.token, "follow");
}

@Override
public UaaOperator headers(Consumer<HttpHeaders> headersTransformer) {
return new UaaOperator(
this.context,
super.getHttpClient().headers(headersTransformer),
this.token,
"headers");
}

@Override
public UaaOperator headersWhen(
Function<HttpHeaders, Mono<? extends HttpHeaders>> headersWhenTransformer) {
return new UaaOperator(
this.context,
super.getHttpClient().headersWhen(headersWhenTransformer),
this.token,
"headersWhen");
}

@Override
public UaaOperator withErrorPayloadMapper(ErrorPayloadMapper errorPayloadMapper) {
return new UaaOperator(
this.context.withErrorPayloadMapper(errorPayloadMapper),
super.getHttpClient(),
this.token,
"errorPayload");
}

@Override
protected HttpClient attachRequestLogger(HttpClient httpClient) {
return super.attachRequestLogger(httpClient)
.doAfterRequest((response, connection) -> token.activate());
}
}
Loading