Esempio n. 1
0
  /**
   * Update entry by posting new representation of entry to server. Note that you should not attempt
   * to update entries that you get from iterating over a collection they may be "partial" entries.
   * If you want to update an entry, you must get it via one of the <code>getEntry()</code> methods
   * in {@link com.sun.syndication.propono.atom.common.Collection} or {@link
   * com.sun.syndication.propono.atom.common.AtomService}.
   *
   * @throws ProponoException If entry is a "partial" entry.
   */
  public void update() throws ProponoException {
    if (partial) throw new ProponoException("ERROR: attempt to update partial entry");
    EntityEnclosingMethod method = new PutMethod(getEditURI());
    addAuthentication(method);
    StringWriter sw = new StringWriter();
    int code = -1;
    try {
      Atom10Generator.serializeEntry(this, sw);
      method.setRequestEntity(new StringRequestEntity(sw.toString()));
      method.setRequestHeader("Content-type", "application/atom+xml; charset=utf-8");
      getHttpClient().executeMethod(method);
      InputStream is = method.getResponseBodyAsStream();
      if (method.getStatusCode() != 200 && method.getStatusCode() != 201) {
        throw new ProponoException(
            "ERROR HTTP status=" + method.getStatusCode() + " : " + Utilities.streamToString(is));
      }

    } catch (Exception e) {
      String msg = "ERROR: updating entry, HTTP code: " + code;
      logger.debug(msg, e);
      throw new ProponoException(msg, e);
    } finally {
      method.releaseConnection();
    }
  }
Esempio n. 2
0
  void addToCollection(ClientCollection col) throws ProponoException {
    setCollection(col);
    EntityEnclosingMethod method = new PostMethod(getCollection().getHrefResolved());
    addAuthentication(method);
    StringWriter sw = new StringWriter();
    int code = -1;
    try {
      Atom10Generator.serializeEntry(this, sw);
      method.setRequestEntity(new StringRequestEntity(sw.toString()));
      method.setRequestHeader("Content-type", "application/atom+xml; charset=utf-8");
      getHttpClient().executeMethod(method);
      InputStream is = method.getResponseBodyAsStream();
      code = method.getStatusCode();
      if (code != 200 && code != 201) {
        throw new ProponoException(
            "ERROR HTTP status=" + code + " : " + Utilities.streamToString(is));
      }
      Entry romeEntry =
          Atom10Parser.parseEntry(new InputStreamReader(is), getCollection().getHrefResolved());
      BeanUtils.copyProperties(this, romeEntry);

    } catch (Exception e) {
      String msg = "ERROR: saving entry, HTTP code: " + code;
      logger.debug(msg, e);
      throw new ProponoException(msg, e);
    } finally {
      method.releaseConnection();
    }
    Header locationHeader = method.getResponseHeader("Location");
    if (locationHeader == null) {
      logger.warn("WARNING added entry, but no location header returned");
    } else if (getEditURI() == null) {
      List links = getOtherLinks();
      Link link = new Link();
      link.setHref(locationHeader.getValue());
      link.setRel("edit");
      links.add(link);
      setOtherLinks(links);
    }
  }