예제 #1
0
 /**
  * Set the absolute URI of the ultimate request that was made to receive this response.
  *
  * <p>If the original request URI has been modified (e.g. due to redirections), the absolute URI
  * of the ultimate request being made to receive the response should be set by the caller on the
  * response instance using this method.
  *
  * @param uri absolute URI of the ultimate request made to receive this response. Must not be
  *     {@code null}.
  * @throws java.lang.NullPointerException in case the passed {@code uri} parameter is null.
  * @throws java.lang.IllegalArgumentException in case the passed {@code uri} parameter does not
  *     represent an absolute URI.
  * @see ClientProperties#FOLLOW_REDIRECTS
  * @see #getResolvedRequestUri()
  * @since 2.6
  */
 public void setResolvedRequestUri(final URI uri) {
   if (uri == null) {
     throw new NullPointerException(LocalizationMessages.CLIENT_RESPONSE_RESOLVED_URI_NULL());
   }
   if (!uri.isAbsolute()) {
     throw new IllegalArgumentException(
         LocalizationMessages.CLIENT_RESPONSE_RESOLVED_URI_NOT_ABSOLUTE());
   }
   this.resolvedUri = uri;
 }
예제 #2
0
 @Override
 public void setStatusInfo(Response.StatusType status) {
   if (status == null) {
     throw new NullPointerException(LocalizationMessages.CLIENT_RESPONSE_STATUS_NULL());
   }
   this.status = status;
 }
예제 #3
0
 private InvocationException convertToException(Response response) {
   try {
     return new InvocationException(response, true);
   } catch (Throwable t) {
     return new InvocationException(
         LocalizationMessages.RESPONSE_TO_EXCEPTION_CONVERSION_FAILED(), t);
   }
 }
예제 #4
0
 @Override
 public void close() {
   if (!closed.compareAndSet(false, true)) {
     if (inputStream != null) {
       try {
         inputStream.close();
       } catch (IOException e) {
         LOGGER.log(Level.FINE, LocalizationMessages.CHUNKED_INPUT_STREAM_CLOSING_ERROR(), e);
       }
     }
   }
 }
예제 #5
0
  /**
   * Read next chunk from the response stream and convert it to a Java instance using the {@link
   * #getChunkType() chunk media type}. The method returns {@code null} if the underlying entity
   * input stream has been closed (either implicitly or explicitly by calling the {@link #close()}
   * method).
   *
   * <p>Note: Access to internal chunk parser is not a thread-safe operation and has to be
   * explicitly synchronized in case the chunked input is used from multiple threads.
   *
   * @return next streamed chunk or {@code null} if the underlying entity input stream has been
   *     closed while reading next chunk data.
   * @throws IllegalStateException in case this chunked input has been closed.
   */
  @SuppressWarnings("unchecked")
  public T read() throws IllegalStateException {
    if (closed.get()) {
      throw new IllegalStateException(LocalizationMessages.CHUNKED_INPUT_CLOSED());
    }

    try {
      final byte[] chunk = parser.readChunk(inputStream);
      if (chunk == null) {
        close();
      } else {
        ByteArrayInputStream chunkStream = new ByteArrayInputStream(chunk);
        //noinspection unchecked
        // TODO: add interceptors: interceptors are used in ChunkedOutput, so the stream should
        // be intercepted in the ChunkedInput too. Interceptors cannot be easily added to the
        // readFrom
        // method as they should wrap the stream before it is processed by ChunkParser. Also please
        // check todo
        // in ChunkedInput (this should be fixed together with this todo)
        // issue: JERSEY-1809
        return (T)
            messageBodyWorkers.readFrom(
                getRawType(),
                getType(),
                annotations,
                mediaType,
                headers,
                propertiesDelegate,
                chunkStream,
                Collections.<ReaderInterceptor>emptyList(),
                false);
      }
    } catch (IOException e) {
      Logger.getLogger(this.getClass().getName()).log(Level.FINE, e.getMessage(), e);
      close();
    }
    return null;
  }
예제 #6
0
 /**
  * Set custom chunk data media type.
  *
  * <p>By default, chunk data media type is derived from the value of the response <tt>{@value
  * javax.ws.rs.core.HttpHeaders#CONTENT_TYPE}</tt> header field. Using this methods will override
  * the default chunk media type value and set it to a custom non-{@code null} chunk media type.
  * Once this method is invoked, all subsequent {@link #read chunk reads} will use the newly set
  * chunk media type when selecting the proper {@link javax.ws.rs.ext.MessageBodyReader} for chunk
  * de-serialization.
  *
  * <p>Note: Access to internal chunk media type is not a thread-safe operation and has to be
  * explicitly synchronized in case the chunked input is used from multiple threads.
  *
  * @param mediaType custom chunk data media type. Must not be {@code null}.
  * @throws IllegalArgumentException in case the {@code mediaType} is {@code null}.
  */
 public void setChunkType(MediaType mediaType) throws IllegalArgumentException {
   if (mediaType == null) {
     throw new IllegalArgumentException(LocalizationMessages.CHUNKED_INPUT_MEDIA_TYPE_NULL());
   }
   this.mediaType = mediaType;
 }