com.atlassian.httpclient.api
Interface ResponseTransformation<O>

Type Parameters:
O - The target object for the transformation.

public interface ResponseTransformation<O>

Transforms the ResponsePromise into a target object, allowing for transforming functions based on different HTTP codes or exceptions. Under the covers, all functions are used in a fold() call.


Method Summary
 ResponseTransformation<O> badRequest(com.google.common.base.Function<Response,? extends O> f)
          Register a function to transform 'bad request' (400) HTTP responses.
 O claim()
          Blocks the thread waiting for a result.
 ResponseTransformation<O> clientError(com.google.common.base.Function<Response,? extends O> f)
          Register a function to transform 'client error' (4xx) HTTP responses.
 ResponseTransformation<O> conflict(com.google.common.base.Function<Response,? extends O> f)
          Register a function to transform 'conflict' (409) HTTP responses.
 ResponseTransformation<O> created(com.google.common.base.Function<Response,? extends O> f)
          Register a function to transform 'created' (201) HTTP responses.
 ResponseTransformation<O> done(com.google.common.base.Function<Response,O> f)
          Register a function to transform all completed (1xx, 2xx, 3xx, 4xx, and 5xx) HTTP responses.
 ResponseTransformation<O> error(com.google.common.base.Function<Response,? extends O> f)
          Register a function to transform all error (4xx and 5xx) HTTP responses.
 ResponseTransformation<O> fail(com.google.common.base.Function<java.lang.Throwable,? extends O> f)
          Register a function to transform exceptions thrown while executing the HTTP request.
 ResponseTransformation<O> forbidden(com.google.common.base.Function<Response,? extends O> f)
          Register a function to transform 'forbidden' (403) HTTP responses.
 ResponseTransformation<O> informational(com.google.common.base.Function<Response,? extends O> f)
          Register a function to transform 'informational' (1xx) HTTP responses.
 ResponseTransformation<O> internalServerError(com.google.common.base.Function<Response,? extends O> f)
          Register a function to transform 'internal server error' (500) HTTP responses.
 ResponseTransformation<O> noContent(com.google.common.base.Function<Response,? extends O> f)
          Register a function to transform 'no content' (204) HTTP responses.
 ResponseTransformation<O> notFound(com.google.common.base.Function<Response,? extends O> f)
          Register a function to transform 'not found' (404) HTTP responses.
 ResponseTransformation<O> notModified(com.google.common.base.Function<Response,? extends O> f)
          Register a function to transform 'not modified' (304) HTTP responses.
 ResponseTransformation<O> notSuccessful(com.google.common.base.Function<Response,? extends O> f)
          Register a function to transform all non-'successful' (1xx, 3xx, 4xx, 5xx) HTTP responses.
 ResponseTransformation<O> ok(com.google.common.base.Function<Response,? extends O> f)
          Register a function to transform 'ok' (200) HTTP responses.
 ResponseTransformation<O> on(HttpStatus status, com.google.common.base.Function<Response,? extends O> f)
          Register a function to transform HTTP responses with a specific status.
 ResponseTransformation<O> on(int statusCode, com.google.common.base.Function<Response,? extends O> f)
          Register a function to transform HTTP responses with a specific status code.
 ResponseTransformation<O> others(com.google.common.base.Function<Response,? extends O> f)
          Register a function to transform all other HTTP responses (i.e.
 ResponseTransformation<O> otherwise(com.google.common.base.Function<java.lang.Throwable,O> f)
          Register a function to transform both of the following events: Any value passed to fail() Any value passed to others(), converted into an exception
 ResponseTransformation<O> redirection(com.google.common.base.Function<Response,? extends O> f)
          Register a function to transform 'redirection' (3xx) HTTP responses.
 ResponseTransformation<O> seeOther(com.google.common.base.Function<Response,? extends O> f)
          Register a function to transform 'see other' (303) HTTP responses.
 ResponseTransformation<O> serverError(com.google.common.base.Function<Response,? extends O> f)
          Register a function to transform 'server error' (5xx) HTTP responses.
 ResponseTransformation<O> serviceUnavailable(com.google.common.base.Function<Response,? extends O> f)
          Register a function to transform 'service unavailable' (503) HTTP responses.
 ResponseTransformation<O> successful(com.google.common.base.Function<Response,? extends O> f)
          Register a function to transform 'successful' (2xx) HTTP responses.
 com.atlassian.util.concurrent.Promise<O> toPromise()
          Converts the transformation into a promise for further mapping
 ResponseTransformation<O> unauthorized(com.google.common.base.Function<Response,? extends O> f)
          Register a function to transform 'unauthorized' (401) HTTP responses.
 

Method Detail

on

ResponseTransformation<O> on(HttpStatus status,
                             com.google.common.base.Function<Response,? extends O> f)
Register a function to transform HTTP responses with a specific status. Use this as a fallback if the status code you're interested in does not have a more explicit registration method for it.

Parameters:
status - The HTTP status to select on
f - The transformation function
Returns:
This instance for chaining
See Also:
on(int, com.google.common.base.Function)

on

ResponseTransformation<O> on(int statusCode,
                             com.google.common.base.Function<Response,? extends O> f)

Register a function to transform HTTP responses with a specific status code. Use this as a fallback if the status code you're interested in does not have a more explicit registration method for it.

Prefer the on(HttpStatus, com.google.common.base.Function) method if you're using standard HTTP status.

Parameters:
statusCode - The code to select on
f - The transformation function
Returns:
This instance for chaining
See Also:
on(HttpStatus, com.google.common.base.Function)

informational

ResponseTransformation<O> informational(com.google.common.base.Function<Response,? extends O> f)
Register a function to transform 'informational' (1xx) HTTP responses.

Parameters:
f - The transformation function
Returns:
This instance for chaining

successful

ResponseTransformation<O> successful(com.google.common.base.Function<Response,? extends O> f)
Register a function to transform 'successful' (2xx) HTTP responses.

Parameters:
f - The transformation function
Returns:
This instance for chaining

ok

ResponseTransformation<O> ok(com.google.common.base.Function<Response,? extends O> f)
Register a function to transform 'ok' (200) HTTP responses.

Parameters:
f - The transformation function
Returns:
This instance for chaining

created

ResponseTransformation<O> created(com.google.common.base.Function<Response,? extends O> f)
Register a function to transform 'created' (201) HTTP responses.

Parameters:
f - The transformation function
Returns:
This instance for chaining

noContent

ResponseTransformation<O> noContent(com.google.common.base.Function<Response,? extends O> f)
Register a function to transform 'no content' (204) HTTP responses.

Parameters:
f - The transformation function
Returns:
This instance for chaining

redirection

ResponseTransformation<O> redirection(com.google.common.base.Function<Response,? extends O> f)
Register a function to transform 'redirection' (3xx) HTTP responses.

Parameters:
f - The transformation function
Returns:
This instance for chaining

seeOther

ResponseTransformation<O> seeOther(com.google.common.base.Function<Response,? extends O> f)
Register a function to transform 'see other' (303) HTTP responses.

Parameters:
f - The transformation function
Returns:
This instance for chaining

notModified

ResponseTransformation<O> notModified(com.google.common.base.Function<Response,? extends O> f)
Register a function to transform 'not modified' (304) HTTP responses.

Parameters:
f - The transformation function
Returns:
This instance for chaining

clientError

ResponseTransformation<O> clientError(com.google.common.base.Function<Response,? extends O> f)
Register a function to transform 'client error' (4xx) HTTP responses.

Parameters:
f - The transformation function
Returns:
This instance for chaining

badRequest

ResponseTransformation<O> badRequest(com.google.common.base.Function<Response,? extends O> f)
Register a function to transform 'bad request' (400) HTTP responses.

Parameters:
f - The transformation function
Returns:
This instance for chaining

unauthorized

ResponseTransformation<O> unauthorized(com.google.common.base.Function<Response,? extends O> f)
Register a function to transform 'unauthorized' (401) HTTP responses.

Parameters:
f - The transformation function
Returns:
This instance for chaining

forbidden

ResponseTransformation<O> forbidden(com.google.common.base.Function<Response,? extends O> f)
Register a function to transform 'forbidden' (403) HTTP responses.

Parameters:
f - The transformation function
Returns:
This instance for chaining

notFound

ResponseTransformation<O> notFound(com.google.common.base.Function<Response,? extends O> f)
Register a function to transform 'not found' (404) HTTP responses.

Parameters:
f - The transformation function
Returns:
This instance for chaining

conflict

ResponseTransformation<O> conflict(com.google.common.base.Function<Response,? extends O> f)
Register a function to transform 'conflict' (409) HTTP responses.

Parameters:
f - The transformation function
Returns:
This instance for chaining

serverError

ResponseTransformation<O> serverError(com.google.common.base.Function<Response,? extends O> f)
Register a function to transform 'server error' (5xx) HTTP responses.

Parameters:
f - The transformation function
Returns:
This instance for chaining

internalServerError

ResponseTransformation<O> internalServerError(com.google.common.base.Function<Response,? extends O> f)
Register a function to transform 'internal server error' (500) HTTP responses.

Parameters:
f - The transformation function
Returns:
This instance for chaining

serviceUnavailable

ResponseTransformation<O> serviceUnavailable(com.google.common.base.Function<Response,? extends O> f)
Register a function to transform 'service unavailable' (503) HTTP responses.

Parameters:
f - The transformation function
Returns:
This instance for chaining

error

ResponseTransformation<O> error(com.google.common.base.Function<Response,? extends O> f)
Register a function to transform all error (4xx and 5xx) HTTP responses.

Parameters:
f - The transformation function
Returns:
This instance for chaining

notSuccessful

ResponseTransformation<O> notSuccessful(com.google.common.base.Function<Response,? extends O> f)
Register a function to transform all non-'successful' (1xx, 3xx, 4xx, 5xx) HTTP responses.

Parameters:
f - The transformation function
Returns:
This instance for chaining

others

ResponseTransformation<O> others(com.google.common.base.Function<Response,? extends O> f)
Register a function to transform all other HTTP responses (i.e. those not explicitly registered for).

Parameters:
f - The transformation function
Returns:
This instance for chaining

otherwise

ResponseTransformation<O> otherwise(com.google.common.base.Function<java.lang.Throwable,O> f)
Register a function to transform both of the following events:

Parameters:
f - The transformation function
Returns:
This instance for chaining

done

ResponseTransformation<O> done(com.google.common.base.Function<Response,O> f)
Register a function to transform all completed (1xx, 2xx, 3xx, 4xx, and 5xx) HTTP responses.

Parameters:
f - The transformation function
Returns:
This instance for chaining

fail

ResponseTransformation<O> fail(com.google.common.base.Function<java.lang.Throwable,? extends O> f)
Register a function to transform exceptions thrown while executing the HTTP request.

Parameters:
f - The transformation function
Returns:
This instance for chaining

claim

O claim()
Blocks the thread waiting for a result. Exceptions are thrown as runtime exceptions. Convenience method for toPromise().claim()

Returns:
The final object

toPromise

com.atlassian.util.concurrent.Promise<O> toPromise()
Converts the transformation into a promise for further mapping

Returns:
A promise that will return the object


Copyright © 2012-2013 Atlassian. All Rights Reserved.