Package org.restlet.data

Examples of org.restlet.data.Tag


        // Test partial Get.
        Request request = new Request(Method.GET, "http://localhost:"
                + TEST_PORT + "/testGet");
        Response response = client.handle(request);
        Tag entityTag = response.getEntity().getTag();

        request.setRanges(Arrays.asList(new Range(1, Range.SIZE_MAX)));
        request.getConditions().setRangeTag(entityTag);
        response = client.handle(request);
        assertEquals(Status.SUCCESS_PARTIAL_CONTENT, response.getStatus());
        assertEquals("234567890", response.getEntity().getText());
        assertEquals(10, response.getEntity().getSize());
        assertEquals(9, response.getEntity().getAvailableSize());
        assertEquals(1, response.getEntity().getRange().getIndex());
        assertEquals(9, response.getEntity().getRange().getSize());

        entityTag = new Tag(entityTag.getName() + "-test");
        request.setRanges(Arrays.asList(new Range(1, Range.SIZE_MAX)));
        request.getConditions().setRangeTag(entityTag);
        response = client.handle(request);
        assertEquals(Status.SUCCESS_OK, response.getStatus());
        assertEquals("1234567890", response.getEntity().getText());
View Full Code Here


     */
    private static class TestRangeGetRestlet extends Restlet {
        @Override
        public void handle(Request request, Response response) {
            response.setEntity(new StringRepresentation("1234567890"));
            response.getEntity().setTag(new Tag("TestRangeGetRestlet"));
        }
View Full Code Here

     */
    public static Tag toRestletTag(EntityTag jaxRsEntityTag) {
        if (jaxRsEntityTag == null) {
            return null;
        }
        return new Tag(jaxRsEntityTag.getValue(), jaxRsEntityTag.isWeak());
    }
View Full Code Here

                    result.setUnmodifiedSince(ifUnmodifiedSince);
                }

                // Set the If-Match tags
                List<Tag> match = null;
                Tag current = null;
                if (ifMatchHeader != null) {
                    try {
                        HeaderReader<Object> hr = new HeaderReader<Object>(
                                ifMatchHeader);
                        String value = hr.readRawValue();

                        while (value != null) {
                            current = Tag.parse(value);

                            // Is it the first tag?
                            if (match == null) {
                                match = new ArrayList<Tag>();
                                result.setMatch(match);
                            }

                            // Add the new tag
                            match.add(current);

                            // Read the next token
                            value = hr.readRawValue();
                        }
                    } catch (Exception e) {
                        this.context.getLogger().log(
                                Level.INFO,
                                "Unable to process the if-match header: "
                                        + ifMatchHeader);
                    }
                }

                // Set the If-None-Match tags
                List<Tag> noneMatch = null;
                if (ifNoneMatchHeader != null) {
                    try {
                        HeaderReader<Object> hr = new HeaderReader<Object>(
                                ifNoneMatchHeader);
                        String value = hr.readRawValue();

                        while (value != null) {
                            current = Tag.parse(value);

                            // Is it the first tag?
                            if (noneMatch == null) {
                                noneMatch = new ArrayList<Tag>();
                                result.setNoneMatch(noneMatch);
                            }

                            noneMatch.add(current);

                            // Read the next token
                            value = hr.readRawValue();
                        }
                    } catch (Exception e) {
                        this.context.getLogger().log(
                                Level.INFO,
                                "Unable to process the if-none-match header: "
                                        + ifNoneMatchHeader);
                    }
                }

                if (ifRangeHeader != null && ifRangeHeader.length() > 0) {
                    Tag tag = Tag.parse(ifRangeHeader);
                    if (tag != null) {
                        result.setRangeTag(tag);
                    } else {
                        Date date = HeaderReader.readDate(ifRangeHeader, false);
                        result.setRangeDate(date);
View Full Code Here

            StringRepresentation r = new StringRepresentation(o.toString(),
                    MediaType.APPLICATION_ATOM);
            String tag = getTag(entity);
            if (tag != null) {
                // Add a condition
                resource.getConditions().setMatch(Arrays.asList(new Tag(tag)));
            }
            resource.put(r);
        } catch (ResourceException re) {
            throw new ResourceException(re.getStatus(),
                    "Can't update this entity " + resource.getReference());
View Full Code Here

         Representation rep = app.getEntryRepresentation(feedBaseURI,feed,entryId);
         if (rep==null) {
            getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND);
            return null;
         } else {
            rep.setTag(new Tag(Long.toString(entry.getEdited().getTime()),false));
            // Don't trust the storage to get the modification right
            rep.setModificationDate(entry.getEdited());
         }
         MediaType entryType = new MediaType(rep.getMediaType().getName(),rep.getMediaType().getParameters().createSeries(entryParameters));
         rep.setMediaType(entryType);
View Full Code Here

      try {
         final Entry entry = feed.findEntry(entryId);
         getResponse().setStatus(Status.SUCCESS_NO_CONTENT);
         Representation rep = new StringRepresentation("",MediaType.APPLICATION_ATOM);
         rep.setModificationDate(entry.getEdited());
         rep.setTag(new Tag(Long.toString(entry.getEdited().getTime()),false));
         return rep;
      } catch (SQLException ex) {
         getContext().getLogger().log(Level.SEVERE,"Exception while deleting entry: "+ex.getMessage(),ex);
         getResponse().setStatus(Status.SERVER_ERROR_INTERNAL);
         return new StringRepresentation("Exception while deleting entry.");
View Full Code Here

         String maxS = parameters.getFirstValue("max");
         int start = startS==null ? 1 : Integer.parseInt(startS);
         int max = maxS==null ? -1 : Integer.parseInt(maxS);
         Representation rep = storage.getFeed(feed.getPath(),feed.getUUID(),feed.getEntries(start, max));
         if (rep!=null) {
            rep.setTag(new Tag(Long.toString(feed.getEdited().getTime()),false));
            // Don't trust the storage to get the modification right
            rep.setModificationDate(feed.getEdited());
            rep.setExpirationDate(feed.getEdited());
         }
         getResponse().setStatus(Status.SUCCESS_OK);
View Full Code Here

            getResponse().getAttributes().put("org.restlet.http.headers",headers);
            Reference ref = new Reference(myself+"_/"+entry.getUUID().toString());
            getResponse().setLocationRef(ref);
            Representation rep = new InfosetRepresentation(MediaType.APPLICATION_ATOM,doc);
            rep.setCharacterSet(CharacterSet.UTF_8);
            rep.setTag(new Tag(Long.toString(entry.getEdited().getTime()),false));
            MediaType entryType = new MediaType(rep.getMediaType().getName(),rep.getMediaType().getParameters().createSeries(EntryResource.entryParameters));
            rep.setMediaType(entryType);
            return rep;
           
         } catch (AppException ex) {
            getContext().getLogger().log(Level.SEVERE,ex.getMessage(),ex.getCause());
            getResponse().setStatus(ex.getStatus());
            return new StringRepresentation(ex.getMessage());
         }
        
      } else {
         // Get the slug for the resource & entry
         Form headers = (Form)getRequest().getAttributes().get("org.restlet.http.headers");
         String slug = headers.getValues("slug");
         if (slug==null) {
            slug = headers.getValues("Slug");
         }
         if (slug!=null) {
            try {
               // Decode the precent encoding of the UTF-8 values
               slug = URLDecoder.decode(slug,"UTF-8");
               // Encode the slug as a URL encoding
               slug = URLEncoder.encode(slug,"UTF-8");
            } catch (UnsupportedEncodingException ex) {
               getLogger().log(Level.SEVERE,"Cannot decode slug value: "+slug,ex);
            }
            getContext().getLogger().info("Slug="+slug);
         }
         String idS = headers.getValues("id");
         UUID id = null;
         if (idS!=null) {
            try {
               id = UUID.fromString(idS);
            } catch (Exception ex) {
            }
         } else {
            id = UUID.randomUUID();
         }
        
         try {

            // Get author name for identity
            User user = (User)getRequest().getAttributes().get(App.USER_ATTR);
            Entry entry = app.createMediaEntry(user,feed,entity,slug,id);
           
            getResponse().setStatus(Status.SUCCESS_CREATED);
            headers = new Form();
            getResponse().getAttributes().put("org.restlet.http.headers",headers);
            Reference ref = new Reference(myself+"_/"+entry.getUUID().toString());
            getResponse().setLocationRef(ref);
            Representation rep = app.getEntryRepresentation(myself.toString(),entry);
            rep.setCharacterSet(CharacterSet.UTF_8);
            rep.setTag(new Tag(Long.toString(entry.getEdited().getTime()),false));
            return rep;
         } catch (AppException ex) {
            if (ex.getStatus().getCode()==Status.SERVER_ERROR_INTERNAL.getCode()) {
               getContext().getLogger().log(Level.SEVERE,ex.getMessage(),ex.getCause());
            }
View Full Code Here

  
   public Representation head() {
      getResponse().setStatus(Status.SUCCESS_NO_CONTENT);
      Representation rep = new StringRepresentation("",MediaType.APPLICATION_ATOM);
      rep.setModificationDate(feed.getEdited());
      rep.setTag(new Tag(Long.toString(feed.getEdited().getTime()),false));
      return rep;
      /*
      Form headers = (Form)getResponse().getAttributes().get("org.restlet.http.headers");
      if (headers==null) {
         headers = new Form();
View Full Code Here

TOP

Related Classes of org.restlet.data.Tag

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.