Package ch.iterate.openstack.swift.exception

Examples of ch.iterate.openstack.swift.exception.GenericException


            JSONObject json;
            try {
                json = (JSONObject) JSONValue.parseWithException(new InputStreamReader(response.getEntity().getContent(), charset));
            }
            catch(ParseException e) {
                throw new GenericException(e.getMessage(), e);
            }
            JSONObject auth = (JSONObject) json.get("auth");
            String token = ((JSONObject) auth.get("token")).get("id").toString();

            Map<String, String> cdnUrls = new HashMap<String, String>();
            JSONObject serviceCatalog = (JSONObject) auth.get("serviceCatalog");
            for(Object cloudFilesCDN : (JSONArray) serviceCatalog.get("cloudFilesCDN")) {
                String regionId = ((JSONObject) cloudFilesCDN).get("region").toString();
                String publicUrl = ((JSONObject) cloudFilesCDN).get("publicURL").toString();
                cdnUrls.put(regionId, publicUrl);
            }
            Set<Region> regions = new HashSet<Region>();
            for(Object cloudFiles : (JSONArray) serviceCatalog.get("cloudFiles")) {
                String regionId = ((JSONObject) cloudFiles).get("region").toString();
                String publicUrl = ((JSONObject) cloudFiles).get("publicURL").toString();
                String cdnUrl = cdnUrls.containsKey(regionId) ? cdnUrls.get(regionId) : null;
                Boolean v1Default = ((JSONObject) cloudFiles).containsKey("v1Default")
                        ? (Boolean) ((JSONObject) cloudFiles).get("v1Default")
                        : Boolean.FALSE;
                regions.add(new Region(regionId, URI.create(publicUrl), cdnUrl == null ? null : URI.create(cdnUrl), v1Default));
            }
            return new AuthenticationResponse(response, token, regions);
        }
        else if(response.getStatusLine().getStatusCode() == 401 || response.getStatusLine().getStatusCode() == 403) {
            throw new AuthorizationException(new Response(response));
        }
        throw new GenericException(new Response(response));
    }
View Full Code Here


            throw new NotFoundException(new Response(response));
        }
        else if(response.getStatusLine().getStatusCode() == HttpStatus.SC_UNAUTHORIZED) {
            throw new AuthorizationException(new Response(response));
        }
        throw new GenericException(new Response(response));
    }
View Full Code Here

                Document document = builder.parse(response.getEntity().getContent());

                NodeList nodes = document.getChildNodes();
                Node containerList = nodes.item(0);
                if(!"container".equals(containerList.getNodeName())) {
                    throw new GenericException("Unexpected node name", response.getAllHeaders(), response.getStatusLine());
                }
                List<StorageObject> objectList = new ArrayList<StorageObject>();
                NodeList objectNodes = containerList.getChildNodes();
                for(int i = 0; i < objectNodes.getLength(); ++i) {
                    Node objectNode = objectNodes.item(i);
                    String nodeName = objectNode.getNodeName();
                    if(!("object".equals(nodeName) || "subdir".equals(nodeName))) {
                        continue;
                    }
                    String name = null;
                    String eTag = null;
                    long size = -1;
                    String mimeType = null;
                    String lastModified = null;
                    NodeList objectData = objectNode.getChildNodes();
                    if("subdir".equals(nodeName)) {
                        size = 0;
                        mimeType = "application/directory";
                        name = objectNode.getAttributes().getNamedItem("name").getNodeValue();
                    }
                    for(int j = 0; j < objectData.getLength(); ++j) {
                        Node data = objectData.item(j);
                        if("name".equals(data.getNodeName())) {
                            name = data.getTextContent();
                        }
                        else if("content_type".equals(data.getNodeName())) {
                            mimeType = data.getTextContent();
                        }
                        else if("hash".equals(data.getNodeName())) {
                            eTag = data.getTextContent();
                        }
                        else if("bytes".equals(data.getNodeName())) {
                            size = Long.parseLong(data.getTextContent());
                        }
                        else if("last_modified".equals(data.getNodeName())) {
                            lastModified = data.getTextContent();
                        }
                        else {
                            logger.warn("Unexpected tag:" + data.getNodeName());
                        }
                    }
                    if(name != null) {
                        StorageObject obj = new StorageObject(name);
                        obj.setMd5sum(eTag);
                        obj.setMimeType(mimeType);
                        obj.setSize(size);
                        obj.setLastModified(lastModified);
                        objectList.add(obj);
                    }
                }
                return objectList;
            }
            catch(ParserConfigurationException e) {
                throw new GenericException("Parser configuration failure", e);
            }
            catch(SAXException e) {
                throw new GenericException("Error parsing XML server response", e);
            }
        }
        else if(response.getStatusLine().getStatusCode() == HttpStatus.SC_NO_CONTENT) {
            return Collections.emptyList();
        }
        else if(response.getStatusLine().getStatusCode() == HttpStatus.SC_NOT_FOUND) {
            throw new NotFoundException(new Response(response));
        }
        else if(response.getStatusLine().getStatusCode() == HttpStatus.SC_UNAUTHORIZED) {
            throw new AuthorizationException(new Response(response));
        }
        throw new GenericException(new Response(response));
    }
View Full Code Here

                Document document = builder.parse(response.getEntity().getContent());

                NodeList nodes = document.getChildNodes();
                Node accountNode = nodes.item(0);
                if(!"account".equals(accountNode.getNodeName())) {
                    throw new GenericException("Unexpected node name", response.getAllHeaders(), response.getStatusLine());
                }
                List<CDNContainer> list = new ArrayList<CDNContainer>();
                NodeList containerNodes = accountNode.getChildNodes();
                for(int i = 0; i < containerNodes.getLength(); ++i) {
                    Node containerNode = containerNodes.item(i);
                    if(!"container".equals(containerNode.getNodeName())) {
                        continue;
                    }
                    CDNContainer container = new CDNContainer(region);
                    NodeList objectData = containerNode.getChildNodes();
                    for(int j = 0; j < objectData.getLength(); ++j) {
                        Node data = objectData.item(j);
                        if("name".equals(data.getNodeName())) {
                            container.setName(data.getTextContent());
                        }
                        else if("cdn_url".equals(data.getNodeName())) {
                            container.setCdnURL(data.getTextContent());
                        }
                        else if("cdn_ssl_url".equals(data.getNodeName())) {
                            container.setSslURL(data.getTextContent());
                        }
                        else if("cdn_streaming_url".equals(data.getNodeName())) {
                            container.setStreamingURL(data.getTextContent());
                        }
                        else if("cdn_ios_url".equals(data.getNodeName())) {
                            container.setiOSStreamingURL(data.getTextContent());
                        }
                        else if("cdn_enabled".equals(data.getNodeName())) {
                            container.setEnabled(Boolean.parseBoolean(data.getTextContent()));
                        }
                        else if("log_retention".equals(data.getNodeName())) {
                            container.setRetainLogs(Boolean.parseBoolean(data.getTextContent()));
                        }
                        else if("ttl".equals(data.getNodeName())) {
                            container.setTtl(Integer.parseInt(data.getTextContent()));
                        }
                        else if("referrer_acl".equals(data.getNodeName())) {
                            container.setReferrerACL(data.getTextContent());
                        }
                        else if("useragent_acl".equals(data.getNodeName())) {
                            container.setUserAgentACL(data.getTextContent());
                        }
                        else {
                            logger.warn(String.format("Unexpected node name %s", data.getNodeName()));
                        }
                    }
                    if(container.getName() != null) {
                        list.add(container);
                    }
                }
                return list;
            }
            catch(ParserConfigurationException e) {
                throw new GenericException("Parser configuration failure", e);
            }
            catch(SAXException e) {
                throw new GenericException("Error parsing XML server response", e);
            }
        }
        else if(response.getStatusLine().getStatusCode() == HttpStatus.SC_UNAUTHORIZED) {
            throw new AuthorizationException(new Response(response));
        }
        throw new GenericException(new Response(response));
    }
View Full Code Here

            throw new NotFoundException(new Response(response));
        }
        else if(statusCode == HttpStatus.SC_UNAUTHORIZED) {
            throw new AuthorizationException(new Response(response));
        }
        throw new GenericException(new Response(response));
    }
View Full Code Here

                    this.getAccountTempUrlKey(response));
        }
        else if(response.getStatusLine().getStatusCode() == HttpStatus.SC_UNAUTHORIZED) {
            throw new AuthorizationException(new Response(response));
        }
        throw new GenericException(new Response(response));
    }
View Full Code Here

            JSONObject json;
            try {
                json = (JSONObject) JSONValue.parseWithException(new InputStreamReader(response.getEntity().getContent(), charset));
            }
            catch(ParseException e) {
                throw new GenericException(e.getMessage(), e);
            }
            JSONObject auth = (JSONObject) json.get("access");
            JSONObject user = ((JSONObject) auth.get("user"));
            String defaultRegion = null;
            if(user.containsKey("RAX-AUTH:defaultRegion")) {
                defaultRegion = user.get("RAX-AUTH:defaultRegion").toString();
            }
            String token = ((JSONObject) auth.get("token")).get("id").toString();
            JSONArray serviceCatalogs = (JSONArray) auth.get("serviceCatalog");
            Set<Region> regions = new HashSet<Region>();
            Map<String, String> cdnUrls = new HashMap<String, String>();
            for(Object serviceCatalog : serviceCatalogs) {
                if(((JSONObject) serviceCatalog).get("type").equals("rax:object-cdn")) {
                    for(Object endpoint : (JSONArray) ((JSONObject) serviceCatalog).get("endpoints")) {
                        String regionId = ((JSONObject) endpoint).get("region").toString();
                        String publicUrl = ((JSONObject) endpoint).get("publicURL").toString();
                        cdnUrls.put(regionId, publicUrl);
                    }
                }
                if(((JSONObject) serviceCatalog).get("type").equals("hpext:cdn")) {
                    for(Object endpoint : (JSONArray) ((JSONObject) serviceCatalog).get("endpoints")) {
                        String regionId = ((JSONObject) endpoint).get("region").toString();
                        String publicUrl = ((JSONObject) endpoint).get("publicURL").toString();
                        cdnUrls.put(regionId, publicUrl);
                    }
                }
            }
            for(Object serviceCatalog : serviceCatalogs) {
                if(((JSONObject) serviceCatalog).get("type").equals("object-store")) {
                    for(Object endpoint : (JSONArray) ((JSONObject) serviceCatalog).get("endpoints")) {
                        String regionId = ((JSONObject) endpoint).get("region").toString();
                        String publicUrl = ((JSONObject) endpoint).get("publicURL").toString();
                        String cdnUrl = cdnUrls.containsKey(regionId) ? cdnUrls.get(regionId) : null;
                        regions.add(new Region(regionId, URI.create(publicUrl), cdnUrl == null ? null : URI.create(cdnUrl),
                                regionId.equals(defaultRegion)));
                    }
                }
            }
            return new AuthenticationResponse(response, token, regions);
        }
        else if(response.getStatusLine().getStatusCode() == 401 || response.getStatusLine().getStatusCode() == 403) {
            throw new AuthorizationException(new Response(response));
        }
        throw new GenericException(new Response(response));
    }
View Full Code Here

                Document document = builder.parse(response.getEntity().getContent());

                NodeList nodes = document.getChildNodes();
                Node accountNode = nodes.item(0);
                if(!"account".equals(accountNode.getNodeName())) {
                    throw new GenericException("Unexpected node name", response.getAllHeaders(), response.getStatusLine());
                }
                List<CDNContainer> list = new ArrayList<CDNContainer>();
                NodeList containerNodes = accountNode.getChildNodes();
                for(int i = 0; i < containerNodes.getLength(); ++i) {
                    Node containerNode = containerNodes.item(i);
                    if(!"container".equals(containerNode.getNodeName())) {
                        continue;
                    }
                    CDNContainer container = new CDNContainer(region);
                    NodeList objectData = containerNode.getChildNodes();
                    for(int j = 0; j < objectData.getLength(); ++j) {
                        Node data = objectData.item(j);
                        if("name".equals(data.getNodeName())) {
                            container.setName(data.getTextContent());
                        }
                        else if("cdn_url".equals(data.getNodeName())) {
                            container.setCdnURL(data.getTextContent());
                        }
                        else if("cdn_ssl_url".equals(data.getNodeName())) {
                            container.setSslURL(data.getTextContent());
                        }
                        else if("cdn_streaming_url".equals(data.getNodeName())) {
                            container.setStreamingURL(data.getTextContent());
                        }
                        else if("cdn_ios_url".equals(data.getNodeName())) {
                            container.setiOSStreamingURL(data.getTextContent());
                        }
                        else if("cdn_enabled".equals(data.getNodeName())) {
                            container.setEnabled(Boolean.parseBoolean(data.getTextContent()));
                        }
                        else if("log_retention".equals(data.getNodeName())) {
                            container.setRetainLogs(Boolean.parseBoolean(data.getTextContent()));
                        }
                        else if("ttl".equals(data.getNodeName())) {
                            container.setTtl(Integer.parseInt(data.getTextContent()));
                        }
                        else if("referrer_acl".equals(data.getNodeName())) {
                            container.setReferrerACL(data.getTextContent());
                        }
                        else if("useragent_acl".equals(data.getNodeName())) {
                            container.setUserAgentACL(data.getTextContent());
                        }
                        else {
                            logger.warn(String.format("Unexpected node name %s", data.getNodeName()));
                        }
                    }
                    if(container.getName() != null) {
                        list.add(container);
                    }
                }
                return list;
            }
            catch(ParserConfigurationException e) {
                throw new GenericException("Parser configuration failure", e);
            }
            catch(SAXException e) {
                throw new GenericException("Error parsing XML server response", e);
            }
        }
        else if(response.getStatusLine().getStatusCode() == HttpStatus.SC_UNAUTHORIZED) {
            throw new AuthorizationException(new Response(response));
        }
        else {
            throw new GenericException(new Response(response));
        }
    }
View Full Code Here

        }
        else if(response.getStatusLine().getStatusCode() == 401 || response.getStatusLine().getStatusCode() == 403) {
            throw new AuthorizationException(new Response(response));
        }
        else {
            throw new GenericException(new Response(response));
        }
    }
View Full Code Here

            throw new NotFoundException(new Response(response));
        }
        else if(statusCode == HttpStatus.SC_UNAUTHORIZED) {
            throw new AuthorizationException(new Response(response));
        }
        throw new GenericException("Unexpected response", response.getAllHeaders(), statusLine);
    }
View Full Code Here

TOP

Related Classes of ch.iterate.openstack.swift.exception.GenericException

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.