Search in sources :

Example 56 with HttpPut

use of org.apache.http.client.methods.HttpPut in project jackrabbit by apache.

the class BindTest method testBindOverwrite.

public void testBindOverwrite() throws Exception {
    String testcol = this.root + "testSimpleBind/";
    String subcol1 = testcol + "bindtest1/";
    String testres1 = subcol1 + "res1";
    String subcol2 = testcol + "bindtest2/";
    String testres2 = subcol2 + "res2";
    int status;
    try {
        HttpMkcol mkcol = new HttpMkcol(testcol);
        status = this.client.execute(mkcol, this.context).getStatusLine().getStatusCode();
        assertEquals(201, status);
        mkcol = new HttpMkcol(subcol1);
        status = this.client.execute(mkcol, this.context).getStatusLine().getStatusCode();
        assertEquals(201, status);
        mkcol = new HttpMkcol(subcol2);
        status = this.client.execute(mkcol, this.context).getStatusLine().getStatusCode();
        assertEquals(201, status);
        //create new resource R with path bindtest1/res1
        HttpPut put = new HttpPut(testres1);
        put.setEntity(new StringEntity("foo", ContentType.create("text/plain", "UTF-8")));
        status = this.client.execute(put, this.context).getStatusLine().getStatusCode();
        assertEquals(201, status);
        //create new resource R' with path bindtest2/res2
        put = new HttpPut(testres2);
        put.setEntity(new StringEntity("bar", ContentType.create("text/plain", "UTF-8")));
        status = this.client.execute(put, this.context).getStatusLine().getStatusCode();
        assertEquals(201, status);
        //try to create new binding of R with path bindtest2/res2 and Overwrite:F
        HttpBind bind = new HttpBind(subcol2, new BindInfo(testres1, "res2"));
        bind.addHeader("Overwrite", "F");
        status = this.client.execute(bind, this.context).getStatusLine().getStatusCode();
        assertEquals(412, status);
        //verify that bindtest2/res2 still points to R'
        HttpGet get = new HttpGet(testres2);
        HttpResponse resp = this.client.execute(get, this.context);
        status = resp.getStatusLine().getStatusCode();
        assertEquals(200, status);
        assertEquals("bar", EntityUtils.toString(resp.getEntity()));
        //create new binding of R with path bindtest2/res2
        bind = new HttpBind(subcol2, new BindInfo(testres1, "res2"));
        status = this.client.execute(bind, this.context).getStatusLine().getStatusCode();
        assertTrue("status: " + status, status == 200 || status == 204);
        //verify that bindtest2/res2 now points to R
        get = new HttpGet(testres2);
        resp = this.client.execute(get, this.context);
        status = resp.getStatusLine().getStatusCode();
        assertEquals(200, status);
        assertEquals("foo", EntityUtils.toString(resp.getEntity()));
        //verify that the initial binding is still there
        HttpHead head = new HttpHead(testres1);
        status = this.client.execute(head, this.context).getStatusLine().getStatusCode();
        assertEquals(200, status);
    } finally {
        delete(testcol);
    }
}
Also used : StringEntity(org.apache.http.entity.StringEntity) HttpMkcol(org.apache.jackrabbit.webdav.client.methods.HttpMkcol) HttpBind(org.apache.jackrabbit.webdav.client.methods.HttpBind) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) HttpPut(org.apache.http.client.methods.HttpPut) HttpHead(org.apache.http.client.methods.HttpHead) BindInfo(org.apache.jackrabbit.webdav.bind.BindInfo)

Example 57 with HttpPut

use of org.apache.http.client.methods.HttpPut in project jackrabbit by apache.

the class BindTest method testResourceId.

// create test resource, make it referenceable, check resource id, move resource, check again
public void testResourceId() throws IOException, DavException, URISyntaxException {
    String testcol = this.root + "testResourceId/";
    String testuri1 = testcol + "bindtest1";
    String testuri2 = testcol + "bindtest2";
    int status;
    try {
        HttpMkcol mkcol = new HttpMkcol(testcol);
        status = this.client.execute(mkcol, this.context).getStatusLine().getStatusCode();
        assertEquals(201, status);
        HttpPut put = new HttpPut(testuri1);
        put.setEntity(new StringEntity("foo", ContentType.create("text/plain", "UTF-8")));
        status = this.client.execute(put, this.context).getStatusLine().getStatusCode();
        assertEquals(201, status);
        // enabling version control always makes the resource referenceable
        HttpVersionControl versioncontrol = new HttpVersionControl(testuri1);
        status = this.client.execute(versioncontrol, this.context).getStatusLine().getStatusCode();
        assertTrue("status: " + status, status == 200 || status == 201);
        URI resourceId = getResourceId(testuri1);
        HttpMove move = new HttpMove(testuri1, testuri2, true);
        status = this.client.execute(move, this.context).getStatusLine().getStatusCode();
        assertEquals(201, status);
        URI resourceId2 = getResourceId(testuri2);
        assertEquals(resourceId, resourceId2);
    } finally {
        delete(testcol);
    }
}
Also used : StringEntity(org.apache.http.entity.StringEntity) HttpMove(org.apache.jackrabbit.webdav.client.methods.HttpMove) HttpMkcol(org.apache.jackrabbit.webdav.client.methods.HttpMkcol) HttpVersionControl(org.apache.jackrabbit.webdav.client.methods.HttpVersionControl) URI(java.net.URI) HttpPut(org.apache.http.client.methods.HttpPut)

Example 58 with HttpPut

use of org.apache.http.client.methods.HttpPut in project jackrabbit by apache.

the class RFC4918DestinationHeaderTest method testMove.

public void testMove() throws IOException, DavException, URISyntaxException {
    String testuri = this.root + "movetest";
    String destinationuri = testuri + "2";
    String destinationpath = new URI(destinationuri).getRawPath();
    // make sure the scheme is removed
    assertFalse(destinationpath.contains(":"));
    try {
        HttpPut put = new HttpPut(testuri);
        int status = this.client.execute(put, this.context).getStatusLine().getStatusCode();
        assertTrue("status: " + status, status == 200 || status == 201 || status == 204);
        // try to move outside the servlet's name space
        HttpMove move = new HttpMove(testuri, "/foobar", true);
        status = this.client.execute(move, this.context).getStatusLine().getStatusCode();
        assertTrue("status: " + status, status == 502);
        // try a relative path
        move = new HttpMove(testuri, "foobar", true);
        status = this.client.execute(move, this.context).getStatusLine().getStatusCode();
        assertTrue("status: " + status, status == 400);
        move = new HttpMove(testuri, destinationpath, true);
        status = this.client.execute(move, this.context).getStatusLine().getStatusCode();
        assertTrue("status: " + status, status == 200 || status == 201 || status == 204);
        HttpHead head = new HttpHead(destinationuri);
        status = this.client.execute(head, this.context).getStatusLine().getStatusCode();
        assertTrue("status: " + status, status == 200);
        head = new HttpHead(testuri);
        status = this.client.execute(head, this.context).getStatusLine().getStatusCode();
        assertTrue("status: " + status, status == 404);
    } finally {
        HttpDelete delete = new HttpDelete(testuri);
        int status = this.client.execute(delete, this.context).getStatusLine().getStatusCode();
        assertTrue("status: " + status, status == 200 || status == 204 || status == 404);
        delete = new HttpDelete(destinationuri);
        status = this.client.execute(delete, this.context).getStatusLine().getStatusCode();
        assertTrue("status: " + status, status == 200 || status == 204 || status == 404);
    }
}
Also used : HttpMove(org.apache.jackrabbit.webdav.client.methods.HttpMove) HttpDelete(org.apache.http.client.methods.HttpDelete) URI(java.net.URI) HttpPut(org.apache.http.client.methods.HttpPut) HttpHead(org.apache.http.client.methods.HttpHead)

Example 59 with HttpPut

use of org.apache.http.client.methods.HttpPut in project jackrabbit by apache.

the class BindTest method testRebind.

public void testRebind() throws Exception {
    String testcol = this.root + "testRebind/";
    String subcol1 = testcol + "bindtest1/";
    String testres1 = subcol1 + "res1";
    String subcol2 = testcol + "bindtest2/";
    String testres2 = subcol2 + "res2";
    int status;
    try {
        HttpMkcol mkcol = new HttpMkcol(testcol);
        status = this.client.execute(mkcol, this.context).getStatusLine().getStatusCode();
        assertEquals(201, status);
        mkcol = new HttpMkcol(subcol1);
        status = this.client.execute(mkcol, this.context).getStatusLine().getStatusCode();
        assertEquals(201, status);
        mkcol = new HttpMkcol(subcol2);
        status = this.client.execute(mkcol, this.context).getStatusLine().getStatusCode();
        assertEquals(201, status);
        //create new resource R with path bindtest1/res1
        HttpPut put = new HttpPut(testres1);
        put.setEntity(new StringEntity("foo", ContentType.create("text/plain", "UTF-8")));
        status = this.client.execute(put, this.context).getStatusLine().getStatusCode();
        assertEquals(201, status);
        // enabling version control always makes the resource referenceable
        HttpVersionControl versioncontrol = new HttpVersionControl(testres1);
        status = this.client.execute(versioncontrol, this.context).getStatusLine().getStatusCode();
        assertTrue("status: " + status, status == 200 || status == 201);
        URI r1 = this.getResourceId(testres1);
        HttpGet get = new HttpGet(testres1);
        HttpResponse resp = this.client.execute(get, this.context);
        status = resp.getStatusLine().getStatusCode();
        assertEquals(200, status);
        assertEquals("foo", EntityUtils.toString(resp.getEntity()));
        //rebind R with path bindtest2/res2
        HttpRebind rebind = new HttpRebind(subcol2, new RebindInfo(testres1, "res2"));
        status = this.client.execute(rebind, this.context).getStatusLine().getStatusCode();
        assertEquals(201, status);
        URI r2 = this.getResourceId(testres2);
        get = new HttpGet(testres2);
        resp = this.client.execute(get, this.context);
        status = resp.getStatusLine().getStatusCode();
        assertEquals(200, status);
        assertEquals("foo", EntityUtils.toString(resp.getEntity()));
        //make sure that rebind did not change the resource-id
        assertEquals(r1, r2);
        //verify that the initial binding is gone
        HttpHead head = new HttpHead(testres1);
        status = this.client.execute(head, this.context).getStatusLine().getStatusCode();
        assertEquals(404, status);
    } finally {
        delete(testcol);
    }
}
Also used : StringEntity(org.apache.http.entity.StringEntity) HttpMkcol(org.apache.jackrabbit.webdav.client.methods.HttpMkcol) HttpVersionControl(org.apache.jackrabbit.webdav.client.methods.HttpVersionControl) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) URI(java.net.URI) HttpPut(org.apache.http.client.methods.HttpPut) RebindInfo(org.apache.jackrabbit.webdav.bind.RebindInfo) HttpHead(org.apache.http.client.methods.HttpHead) HttpRebind(org.apache.jackrabbit.webdav.client.methods.HttpRebind)

Example 60 with HttpPut

use of org.apache.http.client.methods.HttpPut in project jackrabbit by apache.

the class RFC4918IfHeaderTest method testPutIfEtag.

public void testPutIfEtag() throws IOException, DavException, URISyntaxException {
    String testuri = this.root + "iftest";
    try {
        HttpPut put = new HttpPut(testuri);
        String condition = "<" + testuri + "> ([" + "\"an-etag-this-testcase-invented\"" + "])";
        put.setEntity(new StringEntity("1"));
        put.setHeader("If", condition);
        int status = this.client.execute(put, this.context).getStatusLine().getStatusCode();
        assertEquals("status: " + status, 412, status);
    } finally {
        HttpDelete delete = new HttpDelete(testuri);
        int status = this.client.execute(delete, this.context).getStatusLine().getStatusCode();
        assertTrue("status: " + status, status == 200 || status == 204 || status == 404);
    }
}
Also used : StringEntity(org.apache.http.entity.StringEntity) HttpDelete(org.apache.http.client.methods.HttpDelete) HttpPut(org.apache.http.client.methods.HttpPut)

Aggregations

HttpPut (org.apache.http.client.methods.HttpPut)153 StringEntity (org.apache.http.entity.StringEntity)89 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)50 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)40 HttpResponse (org.apache.http.HttpResponse)29 Test (org.junit.Test)29 JsonNode (com.fasterxml.jackson.databind.JsonNode)27 Deployment (org.activiti.engine.test.Deployment)27 HttpPost (org.apache.http.client.methods.HttpPost)19 HttpGet (org.apache.http.client.methods.HttpGet)17 IOException (java.io.IOException)16 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)16 HttpDelete (org.apache.http.client.methods.HttpDelete)14 HttpEntity (org.apache.http.HttpEntity)13 URI (java.net.URI)12 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)12 HttpHead (org.apache.http.client.methods.HttpHead)11 Execution (org.activiti.engine.runtime.Execution)10 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)9 HttpEntityEnclosingRequestBase (org.apache.http.client.methods.HttpEntityEnclosingRequestBase)9