Search in sources :

Example 1 with BaseDavRequest

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

the class RepositoryServiceImpl method submit.

@Override
public void submit(Batch batch) throws RepositoryException {
    if (!(batch instanceof BatchImpl)) {
        throw new RepositoryException("Unknown Batch implementation.");
    }
    BatchImpl batchImpl = (BatchImpl) batch;
    if (batchImpl.isEmpty()) {
        batchImpl.dispose();
        return;
    }
    HttpRequestBase request = null;
    try {
        HttpClient client = batchImpl.start();
        boolean success = false;
        try {
            Iterator<HttpRequestBase> it = batchImpl.requests();
            while (it.hasNext()) {
                request = it.next();
                initMethod(request, batchImpl, true);
                HttpResponse response = client.execute(request);
                if (request instanceof BaseDavRequest) {
                    ((BaseDavRequest) request).checkSuccess(response);
                } else {
                    // use generic HTTP status code checking
                    int statusCode = response.getStatusLine().getStatusCode();
                    if (statusCode < 200 || statusCode >= 300) {
                        throw new DavException(statusCode, "Unexpected status code " + statusCode + " in response to " + request.getMethod() + " request.");
                    }
                }
                request.releaseConnection();
            }
            success = true;
        } finally {
            // make sure the lock is removed. if any of the methods
            // failed the unlock is used to abort any pending changes
            // on the server.
            batchImpl.end(client, success);
        }
    } catch (IOException e) {
        throw new RepositoryException(e);
    } catch (DavException e) {
        throw ExceptionConverter.generate(e, request);
    } finally {
        batchImpl.dispose();
    }
}
Also used : HttpRequestBase(org.apache.http.client.methods.HttpRequestBase) DavException(org.apache.jackrabbit.webdav.DavException) HttpClient(org.apache.http.client.HttpClient) HttpResponse(org.apache.http.HttpResponse) RepositoryException(javax.jcr.RepositoryException) BaseDavRequest(org.apache.jackrabbit.webdav.client.methods.BaseDavRequest) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)1 RepositoryException (javax.jcr.RepositoryException)1 HttpResponse (org.apache.http.HttpResponse)1 HttpClient (org.apache.http.client.HttpClient)1 HttpRequestBase (org.apache.http.client.methods.HttpRequestBase)1 DavException (org.apache.jackrabbit.webdav.DavException)1 BaseDavRequest (org.apache.jackrabbit.webdav.client.methods.BaseDavRequest)1