Example usage for com.amazonaws.services.route53.model ListHostedZonesResult ListHostedZonesResult

List of usage examples for com.amazonaws.services.route53.model ListHostedZonesResult ListHostedZonesResult

Introduction

In this page you can find the example usage for com.amazonaws.services.route53.model ListHostedZonesResult ListHostedZonesResult.

Prototype

ListHostedZonesResult

Source Link

Usage

From source file:com.msi.dns53.client.DNS53Client.java

License:Apache License

public ListHostedZonesResult listHostedZones(ListHostedZonesRequest req)
        throws AmazonServiceException, AmazonClientException {
    Client c = Client.create();//from   www  .j av  a  2 s. c  om
    WebResource r = c.resource(this.serverURL);
    MultivaluedMap<String, String> paramMap = new MultivaluedMapImpl();
    if (req.getMarker() != null) {
        paramMap.add("marker", req.getMarker());
    }
    if (req.getMaxItems() != null) {
        paramMap.add("maxitems", req.getMaxItems());
    }

    ClientResponse response = r.queryParams(paramMap).type(MediaType.APPLICATION_XML_TYPE)
            .accept(MediaType.TEXT_XML)
            .header("X-Amzn-Authorization",
                    "AWS3 AWSAccessKeyId=" + this.accessKey + "," + "Algorithm=HmacSHA256,"
                            + "SignedHeaders=Host;X-Amz-Date," + "Signature=THISISANEXAMPLESIGNATURE=")
            .get(ClientResponse.class);

    String resultXml = response.getEntity(String.class);
    if (response.getStatus() != 200) {
        exceptionMapper(response, resultXml);
    }

    ListHostedZonesResponsePOJO interResult = null;
    try {
        StringReader reader = new StringReader(resultXml);
        JAXBContext context = JAXBContext.newInstance(ListHostedZonesResponsePOJO.class);
        Unmarshaller unmarshaller = context.createUnmarshaller();
        interResult = (ListHostedZonesResponsePOJO) unmarshaller.unmarshal(reader);
    } catch (JAXBException e) {
        e.printStackTrace();
        return null;
    }
    if (interResult == null) {
        return null;
    }

    ListHostedZonesResult result = new ListHostedZonesResult();
    if (interResult.getHostedZones() != null) {
        Collection<HostedZone> hzs = new LinkedList<HostedZone>();
        for (HostedZonePOJO hz : interResult.getHostedZones()) {
            HostedZone temp = new HostedZone();
            temp.setCallerReference(hz.getCallerReference());
            temp.setId(hz.getId());
            temp.setName(hz.getName());
            temp.setResourceRecordSetCount(hz.getResourceRecordSetCount());
            if (hz.getConfig() != null) {
                HostedZoneConfig config = new HostedZoneConfig();
                if (hz.getConfig().getComment() != null) {
                    config.setComment(hz.getConfig().getComment());
                }
                temp.setConfig(config);
            }
            hzs.add(temp);
        }
        result.setHostedZones(hzs);
    }
    if (interResult.getMarker() != null) {
        result.setMarker(interResult.getMarker());
    }
    if (interResult.getMaxItems() != null) {
        result.setMaxItems(interResult.getMaxItems());
    }
    if (interResult.getNextMarker() != null) {
        result.setNextMarker(interResult.getNextMarker());
    }
    return result;
}

From source file:com.msi.dns53.server.AccessMySQL.java

License:Apache License

/**
 * Returns hashmap of <KEY: zoneID, VALUE: String[] of ID, name, caller
 * reference, and comment>/*from  ww w  .  jav  a 2s . c  om*/
 *
 * @param marker_tableName
 *            table name of the marker
 * @param maxItems
 *            number of items returned when the actual number of list
 *            exceeds maxItems
 * @return Hashmap of <KEY: zoneID, VALUE: String[] of ID, name, caller
 *         reference, and comment>
 * @throws InternalErrorException
 */
@Override
public ListHostedZonesResult listHostedZones(String marker, int maxItems, long accId) throws ErrorResponse {
    ListHostedZonesResult result = new ListHostedZonesResult();
    Collection<HostedZone> hostedZones = new LinkedList<HostedZone>();
    int lim = maxItems;
    try {
        ResultSet rs = null;
        String query = null;
        Statement stmt = this.sqlConnection.createStatement();
        if (marker == null) {
            logger.debug("No marker is given.");
            query = "SELECT * FROM msi.zones WHERE accountId = " + accId + ";";

        } else {
            logger.debug("Marker is assigned.");
            query = "SELECT * FROM msi.zones WHERE accountId = " + accId + " AND ID >= \'" + marker + "\';";
        }

        rs = stmt.executeQuery(query);
        while (lim != 0 && rs.next()) {
            HostedZone hz = new HostedZone(rs.getString("ID"), rs.getString("name"),
                    rs.getString("callerReference"));
            HostedZoneConfig config = new HostedZoneConfig();
            config.setComment(rs.getString("comment"));
            hz.setConfig(config);
            --lim;
            hostedZones.add(hz);
        }

        if (marker != null && hostedZones.size() == 0) {
            // TODO throw an exception for marker not existing (test against
            // AWS to see which exception is being returned)
        }

        boolean truncated = rs.next();

        logger.debug("Relative Limit = " + lim + "; MaxItems = " + maxItems);
        logger.debug("Truncated = " + truncated);

        if (lim == 0 && truncated) {
            truncated = true;
        }

        result.setHostedZones(hostedZones);
        result.setMaxItems(String.valueOf(maxItems));
        result.setIsTruncated(truncated);
        if (truncated) {
            result.setNextMarker(rs.getString("ID"));
        }

    } catch (SQLException e) {
        System.err.println("Failed to get zone informations for listHostedZone request.");
        e.printStackTrace();
        throw DNS53Faults.InternalError();
    }
    logger.debug("Returning " + hostedZones.size() + " hosted zones information.");
    return result;
}

From source file:com.netflix.edda.EddaRoute53Client.java

License:Apache License

public ListHostedZonesResult listHostedZones(ListHostedZonesRequest request) {
    TypeReference<List<HostedZone>> ref = new TypeReference<List<HostedZone>>() {
    };/*from w  w w  .  j ava 2  s .c  o m*/
    String url = config.url() + "/api/v2/aws/hostedZones;_expand";
    try {
        List<HostedZone> hostedZones = parse(ref, doGet(url));
        return new ListHostedZonesResult().withHostedZones(hostedZones);
    } catch (IOException e) {
        throw new AmazonClientException("Faled to parse " + url, e);
    }
}

From source file:org.lendingclub.mercator.aws.Route53Scanner.java

License:Apache License

@Override
protected void doScan() {

    ListHostedZonesRequest request = new ListHostedZonesRequest();
    ListHostedZonesResult result = new ListHostedZonesResult();

    do {/*from   w  ww . j  a  v  a2 s  .  co  m*/
        result = getClient().listHostedZones(request);
        for (HostedZone zone : result.getHostedZones()) {
            scanHostedZoneById(zone.getId());
        }
        request.setMarker(result.getMarker());
    } while (result.isTruncated());

}