Skip to content

Commit

Permalink
add webhook id to the webhooks response; delete method
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeer committed Mar 19, 2013
1 parent 5738d3e commit 9c7fc8e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
Expand Up @@ -2,6 +2,7 @@


import static javax.ws.rs.core.Response.created;
import static javax.ws.rs.core.Response.noContent;
import static javax.ws.rs.core.Response.ok;

import java.io.IOException;
Expand All @@ -17,6 +18,7 @@
import javax.jcr.NodeIterator;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.ws.rs.DELETE;
import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
Expand Down Expand Up @@ -115,7 +117,7 @@ public Response showWebhooks() throws RepositoryException {
while(webhooksIterator.hasNext()) {
final Node hook = webhooksIterator.nextNode();
final String callbackUrl = hook.getProperty("webhook:callbackUrl").getString();
str.append(callbackUrl + ", ");
str.append(hook.getIdentifier() + ": " + callbackUrl + ", ");
}

return ok(str.toString()).build();
Expand All @@ -137,6 +139,21 @@ public Response registerWebhook(@PathParam("id") final String id, @FormParam("ca
return created(uriInfo.getAbsolutePath()).build();
}

@DELETE
@Path("{id}")
public Response registerWebhook(@PathParam("id") final String id) throws RepositoryException {

final Session session = repo.login();

Node n = jcrTools.findOrCreateChild(session.getRootNode(), "webhook:" + id, "webhook:callback");
n.remove();

session.save();
session.logout();

return noContent().build();
}



@Subscribe
Expand Down
Expand Up @@ -13,6 +13,7 @@

import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.message.BasicNameValuePair;
Expand Down Expand Up @@ -53,6 +54,25 @@ public void registerWebhookCallbackTest() throws IOException {

}

public void deleteWebhookTest() throws Exception {
HttpPost method = new HttpPost(serverAddress +
"/webhooks/callback_id");

List<NameValuePair> formparams = new ArrayList<NameValuePair>();

formparams.add(new BasicNameValuePair("callbackUrl", "info:fedora/fake:url"));
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formparams, "UTF-8");
method.setEntity(entity);

assertEquals(201, getStatus(method));


HttpDelete delete_method = new HttpDelete(serverAddress + "/webhooks/callback_id");


assertEquals(204, getStatus(delete_method));
}

@Test
public void FireWebhooksTest() throws IOException {

Expand Down

0 comments on commit 9c7fc8e

Please sign in to comment.