/*
 * ******************************************************************************
 *   Copyright 2014-2015 Spectra Logic Corporation. All Rights Reserved.
 *   Licensed under the Apache License, Version 2.0 (the "License"). You may not use
 *   this file except in compliance with the License. A copy of the License is located at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 *   or in the "license" file accompanying this file.
 *   This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
 *   CONDITIONS OF ANY KIND, either express or implied. See the License for the
 *   specific language governing permissions and limitations under the License.
 * ****************************************************************************
 */

package com.spectralogic.ds3client.samples;

import com.spectralogic.ds3client.Ds3Client;
import com.spectralogic.ds3client.Ds3ClientBuilder;
import com.spectralogic.ds3client.commands.GetServiceRequest;
import com.spectralogic.ds3client.commands.GetServiceResponse;
import com.spectralogic.ds3client.models.Ds3Bucket;
import com.spectralogic.ds3client.models.Credentials;

import java.io.IOException;
import java.security.SignatureException;

public class Ds3ServiceListExample {

    public static void main(final String args[]) throws IOException, SignatureException {

        // Get a client builder and then build a client instance.  This is the main entry point to the SDK.
        try (final Ds3Client client = Ds3ClientBuilder.create("ds3Endpoint:8080",
                new Credentials("accessKey", "secretKey")).withHttps(false).build()) {

            // Tell the client to get us a list of all buckets, this is called a service list.
            final GetServiceResponse response = client.getService(new GetServiceRequest());

            // Iterate through all the buckets and print them to the console.
            for (final Ds3Bucket bucket : response.getListAllMyBucketsResult().getBuckets()) {
                System.out.println(bucket.getName());
            }
        }
    }
}

@@ -1124,16 +1124,85 @@
 entials;
+%0Aimport com.spectralogic.ds3client.networking.FailedRequestException;
 %0A%0Aimport
@@ -1263,16 +1263,54 @@
 ception;
+%0Aimport java.net.UnknownHostException;
 %0A%0Apublic
@@ -2143,22 +2143,853 @@
   %7D%0A        
-%7D
+// Catch unknown host exceptions.    %0A        %7D catch (final UnknownHostException e) %7B%0A        %09%0A        %09System.out.println(%22Invalid Endpoint Server Name or IP Address%22);%0A        %09%0A        // Catch failed requests with unexpected status codes.%0A        %7D catch (final FailedRequestException e) %7B%0A        %09%0A        %09// If this is invalid authorization.%0A        %09if (e.getStatusCode() == 403) %7B%0A        %09%09%0A        %09%09System.out.println(%22Invalid Access ID or Secret Key%22);%0A        %09%0A        %09// Else unexpected status code.%0A        %09%7D else %7B%0A        %09%09%0A        %09%09System.out.println(%22BlackPearl return an unexpected status code we did not expect%22);%0A                // e.getStatusCode() can be used to get the status code BlackPearl returned for more accurate error handling and detection%0A        %09%09%0A        %09%7D%0A                %0A        %7D 
 %0A    %7D%0A%7D%0A

Add catch for bad host or credentials (take 2)