Search in sources :

Example 1 with HttpMove

use of org.apache.jackrabbit.webdav.client.methods.HttpMove 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 2 with HttpMove

use of org.apache.jackrabbit.webdav.client.methods.HttpMove 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 3 with HttpMove

use of org.apache.jackrabbit.webdav.client.methods.HttpMove in project jackrabbit by apache.

the class RepositoryServiceImpl method move.

@Override
public void move(SessionInfo sessionInfo, NodeId srcNodeId, NodeId destParentNodeId, Name destName) throws RepositoryException {
    String uri = getItemUri(srcNodeId, sessionInfo);
    String destUri = getItemUri(destParentNodeId, destName, sessionInfo);
    if (isDavClass3(sessionInfo)) {
        destUri = obtainAbsolutePathFromUri(destUri);
    }
    HttpMove request = new HttpMove(uri, destUri, false);
    try {
        initMethod(request, sessionInfo);
        HttpResponse response = executeRequest(sessionInfo, request);
        request.checkSuccess(response);
        // need to clear the cache as the move may have affected nodes with
        // uuid.
        clearItemUriCache(sessionInfo);
    } catch (IOException ex) {
        throw new RepositoryException(ex);
    } catch (DavException e) {
        throw ExceptionConverter.generate(e, request);
    } finally {
        request.releaseConnection();
    }
}
Also used : HttpMove(org.apache.jackrabbit.webdav.client.methods.HttpMove) DavException(org.apache.jackrabbit.webdav.DavException) HttpResponse(org.apache.http.HttpResponse) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException)

Aggregations

HttpMove (org.apache.jackrabbit.webdav.client.methods.HttpMove)3 URI (java.net.URI)2 HttpPut (org.apache.http.client.methods.HttpPut)2 IOException (java.io.IOException)1 RepositoryException (javax.jcr.RepositoryException)1 HttpResponse (org.apache.http.HttpResponse)1 HttpDelete (org.apache.http.client.methods.HttpDelete)1 HttpHead (org.apache.http.client.methods.HttpHead)1 StringEntity (org.apache.http.entity.StringEntity)1 DavException (org.apache.jackrabbit.webdav.DavException)1 HttpMkcol (org.apache.jackrabbit.webdav.client.methods.HttpMkcol)1 HttpVersionControl (org.apache.jackrabbit.webdav.client.methods.HttpVersionControl)1