Package org.apache.abdera.protocol.client

Examples of org.apache.abdera.protocol.client.ClientResponse


        }

        RequestOptions requestOptions = getAuthorization();
        requestOptions.setSlug(relativePath);

        ClientResponse resp;
        if (!alreadyExists) {
            resp = abderaClient.post(baseURI + APPConstants.ATOM + encodeURL(parentPath),
                    element, requestOptions);
        } else {
            resp = abderaClient.put(baseURI + APPConstants.ATOM + encodeURL(suggestedPath),
                    element, requestOptions);
        }
        if (resp.getType() == Response.ResponseType.SUCCESS) {
            if (log.isDebugEnabled()) {
//                log.debug(Messages.getMessage("resource.add", suggestedPath));
            }
        } else if (resp.getStatus() == 401) {
            abderaClient.teardown();
            String msg = "User is not authorized to add the resource to " + suggestedPath;
            log.error(msg);
            throw new RegistryException(msg);
        } else {
            String msg = "Add resource fail. Suggested Path: " + suggestedPath +
                    ", Response Status: " + resp.getStatus() +
                    ", Response Type: " + resp.getType();
            abderaClient.teardown();
            log.error(msg);
            throw new RegistryException(msg);
        }
//        ResourceImpl impl = (ResourceImpl)resource;
View Full Code Here


            entry.addSimpleExtension(new QName(APPConstants.NAMESPACE, "contentModified"), "true");
        }
        RequestOptions opts = getAuthorization();
        opts.setSlug(suggestedPath);
        opts.setContentType(resource.getMediaType());
        ClientResponse response =
                abderaClient.post(baseURI + APPConstants.ATOM + "?importURL=" +
                        encodeURL(sourceURL + RegistryConstants.URL_SEPARATOR +
                                APPConstants.IMPORT_MEDIA_TYPE),
                        entry,
                        opts);
        if (response.getType() == Response.ResponseType.SUCCESS) {
            if (log.isDebugEnabled()) {
                log.debug("resource at " + sourceURL + " imported." +
                        ", Response Status: " + response.getStatus() +
                        ", Response Type: " + response.getType());
            }
            abderaClient.teardown();
            return response.getLocation().toString();
        } else {
            String msg = "failed to import resource at " + sourceURL + "." +
                    ", Response Status: " + response.getStatus() +
                    ", Response Type: " + response.getType();
            abderaClient.teardown();
            log.error(msg);
            throw new RegistryException(msg);
        }
    }
View Full Code Here

        }
    }

    public void delete(String path) throws RegistryException {
        AbderaClient abderaClient = new AbderaClient(abdera);
        ClientResponse resp = abderaClient.delete(baseURI + APPConstants.ATOM + encodeURL(path),
                getAuthorization());
        if (resp.getType() == Response.ResponseType.SUCCESS) {
            if (log.isDebugEnabled()) {
                log.debug("resource at " + path + " deleted" +
                        ", Response Status: " + resp.getStatus() +
                        ", Response Type: " + resp.getType());
            }
            abderaClient.teardown();
        } else {
            String msg = "resource at " + path + " delete failed" +
                    ", Response Status: " + resp.getStatus() +
                    ", Response Type: " + resp.getType();
            abderaClient.teardown();
            log.error(msg);
            throw new RegistryException(msg);
        }
    }
View Full Code Here


    public String rename(String currentPath, String newPath) throws RegistryException {
        AbderaClient abderaClient = new AbderaClient(abdera);
        ByteArrayInputStream is = new ByteArrayInputStream(newPath.getBytes());
        ClientResponse resp =
                abderaClient.post(baseURI + APPConstants.ATOM +
                        encodeURL(currentPath +
                                RegistryConstants.URL_SEPARATOR +
                                APPConstants.PARAMETER_RENAME),
                        is,
                        getAuthorization());
        if (resp.getType() == Response.ResponseType.SUCCESS) {
            if (log.isDebugEnabled()) {
                log.debug("resource rename " + currentPath + " to " + newPath + "  succeeded" +
                        ", Response Status: " + resp.getStatus() +
                        ", Response Type: " + resp.getType());
            }
            abderaClient.teardown();
        } else {
            String msg = "resource rename from " + currentPath + " to " + newPath + " failed" +
                    ", Response Status: " + resp.getStatus() +
                    ", Response Type: " + resp.getType();
            abderaClient.teardown();
            log.error(msg);
            throw new RegistryException(msg);
        }
        return newPath;
View Full Code Here

    }

    public String move(String currentPath, String newPath) throws RegistryException {
        AbderaClient abderaClient = new AbderaClient(abdera);
        ByteArrayInputStream is = new ByteArrayInputStream(newPath.getBytes());
        ClientResponse resp =
                abderaClient.post(baseURI + APPConstants.ATOM +
                        encodeURL(currentPath +
                                RegistryConstants.URL_SEPARATOR +
                                APPConstants.PARAMETER_MOVE),
                        is,
                        getAuthorization());
        if (resp.getType() == Response.ResponseType.SUCCESS) {
            if (log.isDebugEnabled()) {
                log.debug("resource move  from " + currentPath + " to " + newPath + " succeeded" +
                        ", Response Status: " + resp.getStatus() +
                        ", Response Type: " + resp.getType());
            }
            abderaClient.teardown();
        } else {
            String msg = "resource move from " + currentPath + " to " + newPath + " failed" +
                    ", Response Status: " + resp.getStatus() +
                    ", Response Type: " + resp.getType();
            abderaClient.teardown();
            log.error(msg);
            throw new RegistryException(msg);
        }
        // TODO - should pull real result path from the server response.
View Full Code Here

    }

    public String copy(String sourcePath, String targetPath) throws RegistryException {
        AbderaClient abderaClient = new AbderaClient(abdera);
        ByteArrayInputStream is = new ByteArrayInputStream(targetPath.getBytes());
        ClientResponse resp =
                abderaClient.post(baseURI + APPConstants.ATOM +
                        encodeURL(sourcePath +
                                RegistryConstants.URL_SEPARATOR +
                                APPConstants.PARAMETER_COPY),
                        is,
                        getAuthorization());
        if (resp.getType() == Response.ResponseType.SUCCESS) {
            if (log.isDebugEnabled()) {
                log.debug("resource copy from " + sourcePath + " to " + targetPath + " succeeded" +
                        ", Response Status: " + resp.getStatus() +
                        ", Response Type: " + resp.getType());
            }
            abderaClient.teardown();
        } else {
            String msg = "resource copy from " + sourcePath + " to " + targetPath + "  failed" +
                    ", Response Status: " + resp.getStatus() +
                    ", Response Type: " + resp.getType();
            abderaClient.teardown();
            log.error(msg);
            throw new RegistryException(msg);
        }
        // TODO - should pull real result path from the server response.
View Full Code Here

    }

    public void createVersion(String path) throws RegistryException {
        AbderaClient abderaClient = new AbderaClient(abdera);
        ByteArrayInputStream is = new ByteArrayInputStream("createVersion".getBytes());
        ClientResponse clientResponse =
                abderaClient.post(baseURI + APPConstants.ATOM +
                        encodeURL(path + RegistryConstants.URL_SEPARATOR +
                                APPConstants.CHECKPOINT),
                        is,
                        getAuthorization());
        final int status = clientResponse.getStatus();
        if (status < 200 || status > 299) {
            RegistryException e;
            if (status == 404) {
                e = new ResourceNotFoundException(path);
            } else {
                e = new RegistryException("Response Status: " + clientResponse.getStatusText());
            }
            abderaClient.teardown();
            throw e;
        }
        abderaClient.teardown();
View Full Code Here

        abderaClient.teardown();
    }

    public String[] getVersions(String path) throws RegistryException {
        AbderaClient abderaClient = new AbderaClient(abdera);
        ClientResponse clientResponse =
                abderaClient.get(baseURI + APPConstants.ATOM +
                        encodeURL(path +
                                RegistryConstants.URL_SEPARATOR +
                                APPConstants.PARAMETER_VERSION),
                        getAuthorization());
        Document introspection = clientResponse.getDocument();
        Feed feed = (Feed) introspection.getRoot();
        List entries = feed.getEntries();
        if (entries != null) {
            String[] versions = new String[entries.size()];
            for (int i = 0; i < entries.size(); i++) {
View Full Code Here

    }

    public void restoreVersion(String versionPath) throws RegistryException {
        AbderaClient abderaClient = new AbderaClient(abdera);
        Entry entry = abdera.getFactory().newEntry();
        ClientResponse resp = abderaClient.post(baseURI + APPConstants.ATOM +
                encodeURL(versionPath +
                        RegistryConstants.URL_SEPARATOR +
                        APPConstants.PARAMETER_RESTORE),
                entry,
                getAuthorization());
        if (resp.getType() == Response.ResponseType.SUCCESS) {
            if (log.isDebugEnabled()) {
                log.debug("resource restore to " + versionPath + " succeeded" +
                        ", Response Status: " + resp.getStatus() +
                        ", Response Type: " + resp.getType());
            }
            abderaClient.teardown();
        } else {
            String msg = "resource restore " + versionPath + "  failed" +
                    ", Response Status: " + resp.getStatus() +
                    ", Response Type: " + resp.getType();
            abderaClient.teardown();
            log.error(msg);
            throw new RegistryException(msg);
        }
    }
View Full Code Here

        AbderaClient abderaClient = new AbderaClient(abdera);
        final Factory factory = abdera.getFactory();
        Element el = factory.newElement(APPConstants.QN_ASSOC);
        el.setAttributeValue(APPConstants.ASSOC_TYPE, associationType);
        el.setText(associationPaths);
        ClientResponse resp = abderaClient.post(baseURI + APPConstants.ATOM +
                encodeURL(sourcePath +
                        RegistryConstants.URL_SEPARATOR +
                        APPConstants.ASSOCIATIONS),
                el,
                getAuthorization());
        if (resp.getType() == Response.ResponseType.SUCCESS) {
            if (log.isDebugEnabled()) {
                log.debug("associating " + sourcePath + " to " + associationPaths +
                        " type " + associationType + " succeeded" +
                        ", Response Status: " + resp.getStatus() +
                        ", Response Type: " + resp.getType());
            }
            abderaClient.teardown();
        } else {
            String msg = "associating " + sourcePath + " to " + associationPaths +
                    " type " + associationType + "failed" +
                    ", Response Status: " + resp.getStatus() +
                    ", Response Type: " + resp.getType();
            abderaClient.teardown();
            log.error(msg);
            throw new RegistryException(msg);
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.abdera.protocol.client.ClientResponse

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.