Package org.restlet.data

Examples of org.restlet.data.Status


                    } else {
                        // Keep the current status as the developer might prefer
                        // a special status like 'method not authorized'.
                    }
                } else {
                    Status status = getConditions().getStatus(getMethod(),
                            resultInfo);

                    if (status != null) {
                        if (status.isError()) {
                            doError(status);
                        } else {
                            setStatus(status);
                        }
                    }
                }
            } else {
                Status status = getConditions().getStatus(getMethod(),
                        resultInfo);

                if (status != null) {
                    if (status.isError()) {
                        doError(status);
                    } else {
                        setStatus(status);
                    }
                }
View Full Code Here


     *            The error status received.
     * @param errorMessage
     *            The custom error message.
     */
    protected final void doError(Status errorStatus, String errorMessage) {
        doError(new Status(errorStatus, errorMessage));
    }
View Full Code Here

        if ((getStatuses() != null) && !getStatuses().isEmpty()) {
            StringBuilder builder = new StringBuilder();

            for (Iterator<Status> iterator = getStatuses().iterator(); iterator
                    .hasNext();) {
                Status status = iterator.next();
                builder.append(status.getCode());
                if (iterator.hasNext()) {
                    builder.append(" ");
                }
            }
View Full Code Here

         request.getCookies().add(cookie);
      }
      request.setEntity(new StringRepresentation(xml,MediaType.APPLICATION_ATOM_XML));
      Response response = new Response(request);
      editClient.handle(request,response);
      Status status = response.getStatus();
      if (response.isEntityAvailable()) {
         response.getEntity().release();
      }
      if (!status.isSuccess()) {
         throw new StatusException("Cannot create entry due to status "+status.getCode(),status);
      }
      Reference location = response.getLocationRef();
     
      request = new Request(Method.GET,location);
      if (identity!=null) {
View Full Code Here

     
      Identity admin = new Identity("admin","admin");
      Reference autoRef = new Reference("http://localhost:8080/R/");
      FeedClient client = new FeedClient(autoRef,admin);
     
      Status status = client.create("<feed xmlns='http://www.w3.org/2005/Atom'><title>autoconf</title></feed>");
      assertTrue(status.isSuccess());
     
      client.createEntry(
         "<entry xmlns='http://www.w3.org/2005/Atom'>" +
         "<title>test1 db</title>" +
         "<category scheme='http://www.atomojo.org/O/configuration/' term='db'/>"+
View Full Code Here

            feedClient.setIdentity("admin","admin");

            Entry entry = null;
            if (!feedClient.exists()) {
               log.info("Creating feed "+i);
               Status status = feedClient.create("<feed xmlns='http://www.w3.org/2005/Atom'><title>Feed "+i+"</title></feed>");
               if (!status.isSuccess()) {
                  log.info("Failure, status="+status.getCode());
               }
               assertTrue(status.isSuccess());
            } else {

               log.info("Checking feed "+i);
               final AtomicReference<Entry> theEntry = new AtomicReference<Entry>();
               feedClient.get(new FeedDestination() {
                  public void onEntry(Document entryDoc) {
                     Entry entry = new Entry(entryDoc);
                     entry.index();
                     theEntry.set(entry);
                  }
               });
               entry = theEntry.get();
            }
            if (entry==null) {
               try {
                  log.info("Creating entry in "+i);
                  feedClient.createEntry("<entry xmlns='http://www.w3.org/2005/Atom'><title>Entry "+i+"</title></entry>");
               } catch (StatusException ex) {
                  log.info("Failure, status="+ex.getStatus().getCode());
                  assertTrue(false);
               }
            } else {
               log.info("Updating entry in "+i);
               entry.setTitle("Updated "+entry.getTitle());
               EntryClient entryClient = feedClient.getEntryClient(entry);
               Status status = entryClient.update();
               if (!status.isSuccess()) {
                  log.info("Failure, status="+status.getCode());
               }
               assertTrue(status.isSuccess());
            }
         }

   }
View Full Code Here

            feedClient.setIdentity("admin","admin");

            log.info("Checking feed "+j+","+i);
            Entry entry = null;
            final AtomicReference<Entry> theEntry = new AtomicReference<Entry>();
            Status status = feedClient.get(new FeedDestination() {
               public void onEntry(Document entryDoc) {
                  Entry entry = new Entry(entryDoc);
                  entry.index();
                  theEntry.set(entry);
               }
            }).getStatus();
            if (status.getCode()==404) {
               log.info("Creating feed "+j+","+i);
               status = feedClient.create("<feed xmlns='http://www.w3.org/2005/Atom'><title>Feed "+j+","+i+"</title></feed>");
               if (!status.isSuccess()) {
                  log.info("Failure, status="+status.getCode());
               }
               assertTrue(status.isSuccess());
            } else if (status.isSuccess()) {
               entry = theEntry.get();
            } else {
               if (!status.isSuccess()) {
                  log.info("Failure, status="+status.getCode());
               }
               assertTrue(status.isSuccess());
            }
            if (entry==null) {
               try {
                  log.info("Creating entry in "+j+","+i);
                  feedClient.createEntry("<entry xmlns='http://www.w3.org/2005/Atom'><title>Entry "+i+"</title></entry>");
               } catch (StatusException ex) {
                  log.info("Failure, status="+ex.getStatus().getCode());
                  assertTrue(false);
               }
            } else {
               log.info("Updating entry in "+i);
               entry.setTitle("Updated "+entry.getTitle());
               EntryClient entryClient = feedClient.getEntryClient(entry);
               status = entryClient.update();
               if (!status.isSuccess()) {
                  log.info("Failure, status="+status.getCode());
               }
               assertTrue(status.isSuccess());
            }
         }

   }
View Full Code Here

            try {
               Document doc = InfosetFactory.getDefaultInfoset().createItemConstructor().createDocument();
               Element feed = doc.createDocumentElement(FeedClient.FEED_NAME);
               Element title = feed.addElement(FeedClient.TITLE_NAME);
               title.addCharacters(target.dir.getName());
               Status status = feedClient.create(doc);
               if (!status.isSuccess()) {
                  log.log(Level.SEVERE,"Cannot create feed "+target.feed+" due to error "+status.getCode());
                  continue;
               }
            } catch (XMLException ex) {
               log.log(Level.SEVERE,"Cannot create feed "+target.feed+" due to exception.",ex);
               continue;
            }
         }
        
         final Map<String,Entry> entries = new HashMap<String,Entry>();
         try {
            feedClient.get(new FeedDestination() {
               public void onFeed(Document feedDoc) {}
               public void onEntry(Document entryDoc) {
                  Entry entry = new Entry(entryDoc);
                  Entry.Media media = entry.getMediaContent();
                  if (media!=null) {
                     //log.info("Caching entry for "+media.getName());
                     entries.put(media.getName(),entry);
                  }
               }
            });
         } catch (XMLException ex) {
            log.log(Level.SEVERE,"Cannot get feed "+target.feed+" due to XML exception.",ex);
            continue;
         } catch (IOException ex) {
            log.log(Level.SEVERE,"Cannot get feed "+target.feed+" due to I/O exception.",ex);
            continue;
         }
        
         String u = target.feed.toString();
         if (u.charAt(u.length()-1)!='/') {
            u += "/";
         }
         final String feedBase = u;
         final MetadataService metadataService = new MetadataService();
         target.dir.listFiles(new FileFilter() {
            public boolean accept(File file) {
               if (file.isDirectory()) {
                  URI subFeed = URI.create(feedBase+file.getName()+"/");
                  targets.add(new Target(file,subFeed));
               } else {
                  if (!excludeDot || file.getName().charAt(0)!='.') {
                     // Sync content
                     Entry entry = entries.get(file.getName());
                     Status status = null;
                     if (entry!=null) {
                        log.info("Updating "+file);
                        // update existing media
                        try {
                           FileInputStream is = new FileInputStream(file);
                           EntryClient client = feedClient.getEntryClient(entry);
                           status = client.updateMedia(new InputRepresentation(is,entry.getMediaContent().getMediaType()));
                           is.close();
                        } catch (IOException ex) {
                           log.log(Level.SEVERE,"Cannot update "+file+" due to I/O exception.",ex);
                        }
                        entries.remove(file.getName());
                     } else {
                        log.info("Creating "+file);
                        // create new media
                        try {
                           FileInputStream is = new FileInputStream(file);
                           int extPos = file.getName().lastIndexOf('.');
                           String ext = extPos<0 ? null : file.getName().substring(extPos+1);
                           Metadata metadata = ext==null ? null : metadataService.getMetadata(ext);
                           MediaType type = metadata==null ? MediaType.APPLICATION_OCTET_STREAM : MediaType.valueOf(metadata.getName());
                           Entry mediaEntry = feedClient.createMedia(file.getName(),new InputRepresentation(is,type));
                           is.close();
                        } catch (StatusException ex) {
                           log.log(Level.SEVERE,"Cannot create media entry from "+file+" due to status "+ex.getStatus().getCode(),ex);
                        } catch (Exception ex) {
                           log.log(Level.SEVERE,"Cannot create media entry from "+file+" due to exception.",ex);
                        }
                     }
                     if (status!=null && !status.isSuccess()) {
                        log.severe("Cannot update/create media entry for "+file+" due to status "+status.getCode());
                     }
                  }
               }
               return false;
            }
         });
         if (exact) {
            for (Entry entry : entries.values()) {
               EntryClient client = feedClient.getEntryClient(entry);
               Status status = client.delete();
               if (!status.isSuccess()) {
                  log.severe("Cannot delete extra entry "+entry.getId()+" due to status "+status.getCode());
               }
            }
         }
      }
   }
View Full Code Here

            // This is the actual feed we're creating, so massage the
            // document
            AtomResource.mergeFeedDocument(feedDoc,parent.getUUID(),parent.getCreated(),parent.getEdited());
            log.fine("Creating root...");
           
            Status status = storage.storeFeed(parent.getPath(),parent.getUUID(),feedDoc);
            if (!status.isSuccess()) {
               throw new AppException(status,"Failed to create root feed.");
            }
         } catch (IOException ex) {
            throw new AppException(Status.SERVER_ERROR_INTERNAL,"Failed to create root feed  due to exception.",ex);
         } catch (SQLException ex) {
            throw new AppException(Status.SERVER_ERROR_INTERNAL,"Failed to create root feed  due to exception.",ex);
         }
      } else {
     
         if (parent==null) {
           
            try {
               parent = db.createRoot();
            } catch (SQLException ex) {
               throw new AppException(Status.SERVER_ERROR_INTERNAL,"Failed to get root feed  due to exception.",ex);
            }
           
            log.fine("Creating root feed.");
            try {
               Status status = storage.storeFeed(parent.getPath(),parent.getUUID(),AtomResource.createFeedDocument("",parent.getUUID(),parent.getCreated()));
               if (!status.isSuccess()) {
                  throw new AppException(status,"Failed to create root feed");
               }
            } catch (XMLException ex) {
               throw new AppException(Status.SERVER_ERROR_INTERNAL,"Failed to create root feed due to exception.",ex);
            } catch (IOException ex) {
               throw new AppException(Status.SERVER_ERROR_INTERNAL,"Failed to create root feed due to exception.",ex);
            } catch (SQLException ex) {
               throw new AppException(Status.SERVER_ERROR_INTERNAL,"Failed to create root feed due to exception.",ex);
            }
         }
        
         if (feedPath.length()==0) {
            throw new AppException(Status.CLIENT_ERROR_CONFLICT,"The root feed already exists.");
         }
        
         int current = 0;
         for (; current<segments.length; current++) {
            try {
               Feed next = parent.getChild(segments[current]);
               if (next==null) {
                  break;
               } else {
                  parent = next;
               }
            } catch (SQLException ex) {
               throw new AppException(Status.SERVER_ERROR_INTERNAL,"Cannot get segment "+segments[current]+" from database due to exception.",ex);
            }
         }

         // If we found the whole path, the feed alreayd exists
         if (current==segments.length) {
            throw new AppException(Status.CLIENT_ERROR_CONFLICT,"Feed already exists at path: "+feedPath);
         }

         if (log.isLoggable(Level.FINE)) {
            log.fine("Parentage '"+join(segments,0,current,'/')+"' already exists...");
         }

         // Create all the path segments
         for (int i=current; i<segments.length; i++) {
            String path = join(segments,0,i+1,'/');
            if (log.isLoggable(Level.FINE)) {
               log.fine("Creating path: "+path);
            }
            boolean last = i==(segments.length-1);
            boolean created = false;
            try {
               Feed next = parent.getChild(segments[i]);
               if (next!=null && last) {
                  // This shouldn't happen
                  throw new AppException(Status.CLIENT_ERROR_CONFLICT,"Collection already exists at "+path);
               }
               if (next==null) {
                  parent = parent.createChild(segments[i],last ? index.getId() : null);
                  created = true;
               } else {
                  parent = next;
               }
            } catch (SQLException ex) {
               throw new AppException(Status.SERVER_ERROR_INTERNAL,"Cannot create segment "+segments[i]+" due to SQL exception.",ex);
            }
            // Create the feeds along the way
            if (last) {
               // This is the actual feed we're creating, so massage the
               // document
               AtomResource.mergeFeedDocument(feedDoc,parent.getUUID(),parent.getCreated(),parent.getEdited());
            }

            if (created) {
               if (log.isLoggable(Level.FINE)) {
                  log.fine("Creating feed for: "+path);
               }
               try {
                  Status status = storage.storeFeed(parent.getPath(),parent.getUUID(),last ? feedDoc : AtomResource.createFeedDocument(segments[i],parent.getUUID(),parent.getCreated()));
                  if (!status.isSuccess()) {
                     throw new AppException(Status.SERVER_ERROR_INTERNAL,"Failed to create feed at path "+path);
                  }
               } catch (XMLException ex) {
                  throw new AppException(Status.SERVER_ERROR_INTERNAL,"Failed to create feed at path "+path+" due to exception.",ex);
               } catch (IOException ex) {
View Full Code Here

      }

      AtomResource.mergeFeedDocument(doc,feed.getUUID(),feed.getCreated(),feed.getEdited());

      try {
         Status status = storage.storeFeed(feed.getPath(),feed.getUUID(),doc);
         if (!status.isSuccess()) {
            throw new AppException(Status.SERVER_ERROR_INTERNAL,"Cannot store udpated XML");
         }
      } catch (IOException ex) {
         throw new AppException(Status.SERVER_ERROR_INTERNAL,"Cannot store updated XML.",ex);
      } catch (SQLException ex) {
View Full Code Here

TOP

Related Classes of org.restlet.data.Status

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.