Java tutorial
/* * The MIT License * * Copyright 2014 Security Tools SDK for Java. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ package securitytools.veracode; import java.io.Closeable; import java.io.IOException; import java.security.NoSuchAlgorithmException; import java.util.concurrent.Future; import org.apache.http.HttpHost; import org.apache.http.auth.AuthScope; import org.apache.http.client.AuthCache; import org.apache.http.client.CredentialsProvider; import org.apache.http.client.protocol.HttpClientContext; import org.apache.http.impl.auth.BasicScheme; import org.apache.http.impl.client.BasicAuthCache; import org.apache.http.impl.client.BasicCredentialsProvider; import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; import securitytools.common.ClientConfiguration; import securitytools.common.http.HttpClientFactory; import securitytools.veracode.model.applist.ApplicationList; /** * * * @author Adam Parsons * @version 0.0.1, 05/25/14 * @since 1.0.0 */ public class VeracodeAsyncClient implements VeracodeAsync, Closeable { private static final HttpHost TARGET = new HttpHost("analysiscenter.veracode.com", 443, "https"); private final ClientConfiguration clientConfiguration; private final CloseableHttpAsyncClient client; private final HttpClientContext context; /** * Constructs a new asynchronous VeracodeClient using the specified * configuration. * * @param credentials Credentials used to access Veracode services. * @param clientConfiguration Client configuration for options such as proxy * settings, user-agent header, and network timeouts. */ public VeracodeAsyncClient(VeracodeCredentials credentials, ClientConfiguration clientConfiguration) { this.clientConfiguration = clientConfiguration; CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); credentialsProvider.setCredentials(new AuthScope(TARGET), credentials); AuthCache authCache = new BasicAuthCache(); authCache.put(TARGET, new BasicScheme()); context = HttpClientContext.create(); context.setCredentialsProvider(credentialsProvider); context.setAuthCache(authCache); try { client = HttpClientFactory.buildAsync(clientConfiguration); } catch (NoSuchAlgorithmException nsae) { throw new VeracodeClientException(nsae.getMessage(), nsae); } } @Override public void close() throws IOException { if (client != null) { client.close(); } } @Override public Future<ApplicationList> getApplicationList() throws VeracodeClientException, VeracodeServiceException { throw new UnsupportedOperationException("Not supported yet."); } }