Skip to content

Commit

Permalink
Fix issue where buffer sometimes throws size-related error.
Browse files Browse the repository at this point in the history
  • Loading branch information
msavy committed Feb 4, 2017
1 parent 3e9d6ab commit 56c206f
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 10 deletions.
Expand Up @@ -122,7 +122,7 @@ public boolean matches(ApiRequest request) {
String apiVersion = request.getApiVersion();
return matches(apiOrgId, apiId, apiVersion);
}

/**
* Checks the API unique identifier against what this contract expects (org id, id, version).
* Returns true if they match.
Expand All @@ -135,4 +135,12 @@ public boolean matches(String apiOrgId, String apiId, String apiVersion) {
return this.apiOrgId.equals(apiOrgId) && this.apiId.equals(apiId) && this.apiVersion.equals(apiVersion);
}

@Override
@SuppressWarnings("nls")
public String toString() {
final int maxLen = 10;
return "Contract [apiOrgId=" + apiOrgId + ", apiId=" + apiId + ", apiVersion=" + apiVersion + ", plan=" + plan + ", policies="
+ (policies != null ? policies.subList(0, Math.min(policies.size(), maxLen)) : null) + "]";
}

}
Expand Up @@ -19,13 +19,13 @@

/**
* Models a policy.
*
*
* @author Marc Savy <msavy@redhat.com>
*/
public class Policy implements Serializable {

private static final long serialVersionUID = -5945877012261045491L;

private String policyJsonConfig; //config_info json str
private String policyImpl; //Reference to policy (classname?) we're going to load?

Expand Down Expand Up @@ -99,4 +99,11 @@ public boolean equals(Object obj) {
return false;
return true;
}

@Override
@SuppressWarnings("nls")
public String toString() {
return "Policy [policyJsonConfig=" + policyJsonConfig + ", policyImpl=" + policyImpl + "]";
}

}
Expand Up @@ -190,7 +190,7 @@ private void checkQueue() {
private void loadDataIntoRegistries() {
URILoadingRegistry reg = null;
while ((reg = awaiting.poll()) != null) {
log.debug("Loading data into registry: {0} ", reg);
log.debug("Loading data into registry {0}:", reg);
for (Api api : apis) {
reg.publishApiInternal(api, handleAnyFailure());
log.debug("Publishing: {0} ", api);
Expand Down
Expand Up @@ -40,7 +40,7 @@ public class HttpResourceFetcher implements ResourceFetcher {
private URI uri;
private boolean isHttps;
private Vertx vertx;
private Buffer rawData;
private Buffer rawData = Buffer.buffer();
private Handler<Throwable> exceptionHandler;
private Map<String, String> config;
private Authenticator authenticator;
Expand Down Expand Up @@ -72,11 +72,7 @@ public void fetch(Handler<Buffer> resultHandler) {
.get(port, uri.getHost(), uri.getPath(), clientResponse -> {
if (clientResponse.statusCode() / 100 == 2) {
clientResponse.handler(data -> {
if (rawData == null) {
rawData = data;
} else {
rawData.appendBuffer(data);
}
rawData.appendBuffer(data);
})
.endHandler(end -> resultHandler.handle(rawData))
.exceptionHandler(exceptionHandler);
Expand Down
Expand Up @@ -18,6 +18,7 @@

import io.apiman.common.util.Basic;
import io.vertx.core.AsyncResultHandler;
import io.vertx.core.Future;
import io.vertx.core.MultiMap;
import io.vertx.core.Vertx;

Expand All @@ -40,6 +41,7 @@ public Authenticator validateConfig(Map<String, String> config) {
@Override
public Authenticator authenticate(Vertx vertx, Map<String, String> config, MultiMap headerMap, AsyncResultHandler<Void> resultHandler) {
headerMap.set("Authorization", Basic.encode(config.get("username"), config.get("password")));
resultHandler.handle(Future.succeededFuture());
return this;
}
}

0 comments on commit 56c206f

Please sign in to comment.