Created
May 7, 2014 07:45
-
-
Save johnou/213a737802cc9fc32874 to your computer and use it in GitHub Desktop.
Akamai CCU REST API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 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
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.