Search in sources :

Example 1 with RebindInfo

use of org.apache.jackrabbit.webdav.bind.RebindInfo 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 2 with RebindInfo

use of org.apache.jackrabbit.webdav.bind.RebindInfo in project jackrabbit by apache.

the class BindTest method testRebindOverwrite.

public void testRebindOverwrite() 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 testSimpleBind/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);
        //create new resource R' with path testSimpleBind/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 rebind R with path testSimpleBind/bindtest2/res2 and Overwrite:F
        HttpRebind rebind = new HttpRebind(subcol2, new RebindInfo(testres1, "res2"));
        rebind.addHeader("Overwrite", "F");
        status = this.client.execute(rebind, this.context).getStatusLine().getStatusCode();
        assertEquals(412, status);
        //verify that testSimpleBind/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()));
        //rebind R with path testSimpleBind/bindtest2/res2
        rebind = new HttpRebind(subcol2, new RebindInfo(testres1, "res2"));
        status = this.client.execute(rebind, this.context).getStatusLine().getStatusCode();
        assertTrue("status: " + status, status == 200 || status == 204);
        //verify that testSimpleBind/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 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) 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 3 with RebindInfo

use of org.apache.jackrabbit.webdav.bind.RebindInfo in project jackrabbit by apache.

the class AbstractWebdavServlet method doRebind.

/**
     * The REBIND method
     *
     * @param request
     * @param response
     * @param resource the collection resource to which a new member will be added
     * @throws IOException
     * @throws DavException
     */
protected void doRebind(WebdavRequest request, WebdavResponse response, DavResource resource) throws IOException, DavException {
    if (!resource.exists()) {
        response.sendError(DavServletResponse.SC_NOT_FOUND);
    }
    RebindInfo rebindInfo = request.getRebindInfo();
    DavResource oldBinding = getResourceFactory().createResource(request.getHrefLocator(rebindInfo.getHref()), request, response);
    if (!(oldBinding instanceof BindableResource)) {
        response.sendError(DavServletResponse.SC_METHOD_NOT_ALLOWED);
        return;
    }
    DavResource newBinding = getResourceFactory().createResource(request.getMemberLocator(rebindInfo.getSegment()), request, response);
    int status = validateDestination(newBinding, request, false);
    if (status > DavServletResponse.SC_NO_CONTENT) {
        response.sendError(status);
        return;
    }
    ((BindableResource) oldBinding).rebind(resource, newBinding);
    response.setStatus(status);
}
Also used : DavResource(org.apache.jackrabbit.webdav.DavResource) BindableResource(org.apache.jackrabbit.webdav.bind.BindableResource) RebindInfo(org.apache.jackrabbit.webdav.bind.RebindInfo)

Example 4 with RebindInfo

use of org.apache.jackrabbit.webdav.bind.RebindInfo in project jackrabbit by apache.

the class WebdavRequestImpl method getRebindInfo.

/**
     * @see org.apache.jackrabbit.webdav.bind.BindServletRequest#getRebindInfo()
     */
public RebindInfo getRebindInfo() throws DavException {
    RebindInfo info = null;
    Document requestDocument = getRequestDocument();
    if (requestDocument != null) {
        info = RebindInfo.createFromXml(requestDocument.getDocumentElement());
    }
    return info;
}
Also used : Document(org.w3c.dom.Document) RebindInfo(org.apache.jackrabbit.webdav.bind.RebindInfo)

Aggregations

RebindInfo (org.apache.jackrabbit.webdav.bind.RebindInfo)4 HttpResponse (org.apache.http.HttpResponse)2 HttpGet (org.apache.http.client.methods.HttpGet)2 HttpHead (org.apache.http.client.methods.HttpHead)2 HttpPut (org.apache.http.client.methods.HttpPut)2 StringEntity (org.apache.http.entity.StringEntity)2 HttpMkcol (org.apache.jackrabbit.webdav.client.methods.HttpMkcol)2 HttpRebind (org.apache.jackrabbit.webdav.client.methods.HttpRebind)2 HttpVersionControl (org.apache.jackrabbit.webdav.client.methods.HttpVersionControl)2 URI (java.net.URI)1 DavResource (org.apache.jackrabbit.webdav.DavResource)1 BindableResource (org.apache.jackrabbit.webdav.bind.BindableResource)1 Document (org.w3c.dom.Document)1