com.atlassian.applinks.api
Interface ApplicationLinkRequestFactory

All Superinterfaces:
AuthorisationURIGenerator

public interface ApplicationLinkRequestFactory
extends AuthorisationURIGenerator

Provides authenticated ApplicationLinkRequest objects. Use the ApplicationLink.createAuthenticatedRequestFactory() or ApplicationLink.createAuthenticatedRequestFactory(Class) method to create an ApplicationLinkRequestFactory targeting a particular remote ApplicationLink.

Since:
3.0

Method Summary
 ApplicationLinkRequest createRequest(com.atlassian.sal.api.net.Request.MethodType methodType, java.lang.String url)
          Creates a request of the given method type to the given url.
 
Methods inherited from interface com.atlassian.applinks.api.AuthorisationURIGenerator
getAuthorisationURI, getAuthorisationURI
 

Method Detail

createRequest

ApplicationLinkRequest createRequest(com.atlassian.sal.api.net.Request.MethodType methodType,
                                     java.lang.String url)
                                     throws CredentialsRequiredException
Creates a request of the given method type to the given url. ApplicationLinkRequestFactory implementations can be transparently authenticated by different AuthenticationProviders. See ApplicationLink.createAuthenticatedRequestFactory() for more details.

Example usage:
  ApplicationLinkRequestFactory requestFactory = ApplicationLink.createAuthenticatedRequestFactory();
  ApplicationLinkRequest request;

  try {
      request = requestFactory.createRequest(Request.MethodType#GET, "/rest/my-plugin/1.0/my-resource");
  } catch (CredentialsRequiredException e) {
      // we don't have credentials stored for the context user, so prompt user to authenticate
      // using the URI provided by CredentialsRequiredException.getAuthorisationURI()
      // ...
  }

  try {
      boolean success = request.execute(new ApplicationLinkResponseHandler<Boolean>() {

          Boolean handle(Response response) throws ResponseException {
              return response.Response.isSuccessful())
          }

          Boolean credentialsRequired(Response response) throws ResponseException {
              // the remote server rejected our credentials, so prompt the user to authenticate
              // using the URI provided by AuthorisationURIGenerator.getAuthorisationURI()
              // ...
          }

      });

  } catch (ResponseException re) {
      // the request failed to complete normally
  }
 

Parameters:
methodType - The HTTP method type
url - The target of the request. If you specify a URI that does not start with a protocol string (e.g. http: or https:) the target ApplicationLink's rpcUrl will be pre-pended to the request URI. Specified absolute URIs will be used as is.
Returns:
The ApplicationLinkRequest object
Throws:
CredentialsRequiredException - when the target ApplicationLink requires authentication, but no credentials are available for the context user.
See Also:
CredentialsRequiredException


Copyright © 2011 Atlassian. All Rights Reserved.