コード例 #1
0
  @Override
  public <T2> T2 getEntity(Class<T2> type, Type genericType, Annotation[] anns) {
    if (exception != null) {
      throw new RuntimeException(
          Messages.MESSAGES.unableToUnmarshalResponse(attributeExceptionsTo), exception);
    }

    if (unmarshaledEntity != null && !type.isInstance(this.unmarshaledEntity))
      throw new RuntimeException(Messages.MESSAGES.entityAlreadyRead(unmarshaledEntity.getClass()));

    if (unmarshaledEntity == null) {
      if (status == HttpResponseCodes.SC_NO_CONTENT) return null;

      unmarshaledEntity = readFrom(type, genericType, getMediaType(), anns);
      // only release connection if we actually unmarshalled something and if the object is *NOT* an
      // InputStream
      // If it is an input stream, the user may be doing their own stream processing.
      if (unmarshaledEntity != null && !InputStream.class.isInstance(unmarshaledEntity))
        releaseConnection();
    }
    return (T2) unmarshaledEntity;
  }
コード例 #2
0
 @Override
 public void close() {
   releaseConnection();
 }
コード例 #3
0
 @Override
 // this is synchronized to protect against premature finalize called by the GC
 protected final synchronized void finalize() throws Throwable {
   releaseConnection();
 }