Skip to content

Instantly share code, notes, and snippets.

@johnou
Created May 7, 2014 07:45
Show Gist options
  • Save johnou/213a737802cc9fc32874 to your computer and use it in GitHub Desktop.
Save johnou/213a737802cc9fc32874 to your computer and use it in GitHub Desktop.
Akamai CCU REST API
public PurgeResult send(String user, String password, Collection<String> urls) throws PurgeException {
JsonObject payload = createPurgePayload(urls);
Response response = null;
try {
Client client = ClientBuilder.newClient();
client.register(HttpAuthenticationFeature.basic(user, password));
WebTarget target = client.target("https://api.ccu.akamai.com");
WebTarget resource = target.path("/ccu/v2/queues/default");
response = resource.request(MediaType.APPLICATION_JSON_TYPE)
.post(Entity.entity(payload.toString(), MediaType.APPLICATION_JSON_TYPE));
if (response.getStatus() != 201) {
throw new PurgeException(response.readEntity(String.class));
}
JsonObject object = JsonObject.readFrom(response.readEntity(String.class));
return new PurgeResult(object.get("estimatedSeconds").asInt(), object.get("progressUri").asString(),
object.get("purgeId").asString(), object.get("httpStatus").asInt(), object.get("detail").asString());
} finally {
if (response != null) {
response.close();
}
}
}
private JsonObject createPurgePayload(Collection<String> urls) {
JsonArray array = new JsonArray();
for (String url : urls) {
array.add(url);
}
JsonObject object = new JsonObject();
if (PurgeOptions.PurgeType.CPCODE.equals(options.getType())) {
object.add("type", "cpcode");
}
object.add("objects", array);
return object;
}
@homer-rocks
Copy link

Could you please upload the complete file along with the Util classes which you are using? I have tried to implement the purge feature using a org.apache.cxf.jaxrs.client.WebClient and I'm consistently getting 401 error even though the same credentials work fine on a Advanced Rest Client.

Greatly appreciate your help.

@johnou
Copy link
Author

johnou commented Nov 9, 2016

@homer-rocks sorry didn't see your message until now, here it is if you are still interested https://github.com/johnou/akamai-scrubber

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment