Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2012-2015 Amazon.com, Inc. or its affiliates. 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://aws.amazon.com/apache2.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.amazonaws.services.route53.internal;
 
Route 53 returns a portion of the URL resource path as the ID for a few elements, but when the service accepts those IDs, the resource path portion cannot be included, otherwise requests fail. This handler removes those partial resource path elements from IDs returned by Route 53.
 
 
     @Override
     public void afterResponse(Request<?> requestObject objTimingInfo timingInfo) {
         if (obj instanceof ChangeResourceRecordSetsResult) {
             ChangeResourceRecordSetsResult result = (ChangeResourceRecordSetsResult)obj;
             removePrefix(result.getChangeInfo());
         } else if (obj instanceof CreateHostedZoneResult) {
             CreateHostedZoneResult result = (CreateHostedZoneResult)obj;
             removePrefix(result.getChangeInfo());
             removePrefix(result.getHostedZone());
             removePrefix(result.getDelegationSet());
         } else if (obj instanceof DeleteHostedZoneResult) {
             DeleteHostedZoneResult result = (DeleteHostedZoneResult)obj;
             removePrefix(result.getChangeInfo());
         } else if (obj instanceof GetChangeResult) {
             GetChangeResult result = (GetChangeResult)obj;
             removePrefix(result.getChangeInfo());
         } else if (obj instanceof GetHostedZoneResult) {
             GetHostedZoneResult result = (GetHostedZoneResult)obj;
             removePrefix(result.getHostedZone());
         } else if (obj instanceof ListHostedZonesResult) {
             ListHostedZonesResult result = (ListHostedZonesResult)obj;
             for (HostedZone zone : result.getHostedZones()) removePrefix(zone);
         } else if (obj instanceof ListResourceRecordSetsResult) {
             ListResourceRecordSetsResult result = (ListResourceRecordSetsResult)obj;
             for (ResourceRecordSet rrset : result.getResourceRecordSets()) removePrefix(rrset);
         } else if (obj instanceof CreateHealthCheckResult) {
             CreateHealthCheckResult result = (CreateHealthCheckResult)obj;
             removePrefix(result.getHealthCheck());
         } else if (obj instanceof GetHealthCheckResult) {
             GetHealthCheckResult result = (GetHealthCheckResult)obj;
             removePrefix(result.getHealthCheck());
         } else if (obj instanceof ListHealthChecksResult) {
             ListHealthChecksResult result = (ListHealthChecksResult)obj;
             for (HealthCheck check : result.getHealthChecks()) removePrefix(check);
         } else if (obj instanceof CreateReusableDelegationSetResult) {
             CreateReusableDelegationSetResult result = (CreateReusableDelegationSetResultobj;
             removePrefix(result.getDelegationSet());
         } else if (obj instanceof GetHostedZoneResult) {
             GetHostedZoneResult result = (GetHostedZoneResultobj;
             removePrefix(result.getDelegationSet());
         } else if (obj instanceof GetReusableDelegationSetResult) {
             GetReusableDelegationSetResult result = (GetReusableDelegationSetResultobj;
             removePrefix(result.getDelegationSet());
         } else if (obj instanceof ListReusableDelegationSetsResult) {
             ListReusableDelegationSetsResult result = (ListReusableDelegationSetsResultobj;
             for (DelegationSet delegationSet : result.getDelegationSets())
                 removePrefix(delegationSet);
         }
     }
 
     private void removePrefix(ResourceRecordSet rrset) {
         if (rrset == nullreturn;
        removePrefix(rrset.getAliasTarget());
        rrset.setHealthCheckId(removePrefix(rrset.getHealthCheckId()));
        rrset.setSetIdentifier(removePrefix(rrset.getSetIdentifier()));
    }
    private void removePrefix(AliasTarget aliasTarget) {
        if (aliasTarget == nullreturn;
        aliasTarget.setHostedZoneId(removePrefix(aliasTarget.getHostedZoneId()));
    }
    private void removePrefix(ChangeInfo changeInfo) {
        if (changeInfo == nullreturn;
        if (changeInfo.getId() != null) {
            changeInfo.setId(removePrefix(changeInfo.getId()));
        }
    }
    private void removePrefix(HostedZone hostedZone) {
        if (hostedZone == nullreturn;
        if (hostedZone.getId() != null) {
            hostedZone.setId(removePrefix(hostedZone.getId()));
        }
    }
    private void removePrefix(HealthCheck healthCheck) {
        if (healthCheck == nullreturn;
        if (healthCheck.getId() != null) {
            healthCheck.setId(removePrefix(healthCheck.getId()));
        }
    }
    private void removePrefix(DelegationSet delegationSet) {
        if (delegationSet == nullreturn;
        if (delegationSet.getId() != null) {
            delegationSet.setId(removePrefix(delegationSet.getId()));
        }
    }
    private String removePrefix(String s) {
        if (s == nullreturn null;
        int lastIndex = s.lastIndexOf("/");
        if (lastIndex > 0) {
            return s.substring(lastIndex + 1);
        }
        return s;
    }
New to GrepCode? Check out our FAQ X