View Javadoc

1   /*
2    * Copyright (C) 2012 Atlassian
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package com.atlassian.jira.rest.client.internal.async;
17  
18  import com.atlassian.httpclient.api.HttpClient;
19  import com.atlassian.jira.rest.client.api.AuthenticationHandler;
20  import com.atlassian.jira.rest.client.api.JiraRestClient;
21  import com.atlassian.jira.rest.client.api.JiraRestClientFactory;
22  import com.atlassian.jira.rest.client.auth.BasicHttpAuthenticationHandler;
23  
24  import java.net.URI;
25  
26  /**
27   * Serves asynchronous implementations of the JiraRestClient.
28   *
29   * @since v2.0
30   */
31  public class AsynchronousJiraRestClientFactory implements JiraRestClientFactory {
32  
33  	@Override
34  	public JiraRestClient create(final URI serverUri, final AuthenticationHandler authenticationHandler) {
35  		final DisposableHttpClient httpClient = new AsynchronousHttpClientFactory()
36  				.createClient(serverUri, authenticationHandler);
37  		return new AsynchronousJiraRestClient(serverUri, httpClient);
38  	}
39  
40  	@Override
41  	public JiraRestClient createWithBasicHttpAuthentication(final URI serverUri, final String username, final String password) {
42  		return create(serverUri, new BasicHttpAuthenticationHandler(username, password));
43  	}
44  
45  	@Override
46  	public JiraRestClient create(final URI serverUri, final HttpClient httpClient) {
47  		final DisposableHttpClient disposableHttpClient = new AsynchronousHttpClientFactory().createClient(httpClient);
48  		return new AsynchronousJiraRestClient(serverUri, disposableHttpClient);
49  	}
50  }