Example usage for com.amazonaws.services.route53.model ListResourceRecordSetsRequest getStartRecordName

List of usage examples for com.amazonaws.services.route53.model ListResourceRecordSetsRequest getStartRecordName

Introduction

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

Prototype


public String getStartRecordName() 

Source Link

Document

The first name in the lexicographic ordering of resource record sets that you want to list.

Usage

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

License:Apache License

public ListResourceRecordSetsResult listResourceRecordSets(ListResourceRecordSetsRequest req)
        throws AmazonServiceException, AmazonClientException {
    Client c = Client.create();//  w w  w  .  ja v  a 2s .c  om
    WebResource r = c.resource(this.serverURL);
    MultivaluedMap<String, String> paramMap = new MultivaluedMapImpl();
    if (req.getStartRecordName() != null) {
        paramMap.add("name", req.getStartRecordName());
    }
    if (req.getStartRecordType() != null) {
        paramMap.add("type", req.getStartRecordType());
    }
    if (req.getStartRecordIdentifier() != null) {
        paramMap.add("identifier", req.getStartRecordIdentifier());
    }
    if (req.getMaxItems() != null) {
        paramMap.add("maxitems", req.getMaxItems());
    }

    ClientResponse response = r.path(req.getHostedZoneId() + "/rrset").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);
    }

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

    ListResourceRecordSetsResult result = new ListResourceRecordSetsResult();
    result.setMaxItems(interResult.getMaxItems());
    result.setIsTruncated(interResult.isTruncated());
    if (interResult.getResourceRecordSets() != null) {
        Collection<ResourceRecordSet> rrSets = new LinkedList<ResourceRecordSet>();
        for (ResourceRecordSetPOJO p : interResult.getResourceRecordSets()) {
            ResourceRecordSet temp = new ResourceRecordSet();
            temp.setName(p.getName());
            temp.setSetIdentifier(p.getSetIdentifier());
            temp.setTTL(p.getTTL());
            temp.setType(p.getType());
            temp.setWeight(p.getWeight());
            if (p.getResourceRecords() != null) {
                Collection<ResourceRecord> resourceRecords = new LinkedList<ResourceRecord>();
                for (ResourceRecordPOJO record : p.getResourceRecords()) {
                    ResourceRecord newRec = new ResourceRecord();
                    newRec.setValue(record.getValue());
                    resourceRecords.add(newRec);
                }
                temp.setResourceRecords(resourceRecords);
            }
            rrSets.add(temp);
        }
        result.setResourceRecordSets(rrSets);
    }

    return result;
}

From source file:com.msi.dns53.server.query.ListResourceRecordSets.java

License:Apache License

private ListResourceRecordSetsResult listResourceRecordSets(Session sess, ListResourceRecordSetsRequest request)
        throws ErrorResponse {
    ListResourceRecordSetsResult result = new ListResourceRecordSetsResult();
    AccessMySQL sqlaccess = AccessMySQL.getInstance();

    String tableName = sqlaccess.getTableName(request.getHostedZoneId(), this.getAccountId());
    if (tableName.equals("FAILED")) {
        throw DNS53Faults.NoSuchHostedZone(request.getHostedZoneId());
    }//w  ww .j ava2  s. c o m
    if (request.getStartRecordType() != null && request.getStartRecordName() == null) {
        throw DNS53Faults.InvalidInput();
    }
    logger.debug(
            "Table " + tableName + " is found for hosted zone with id, " + request.getHostedZoneId() + ".");

    String zoneName = sqlaccess.getZoneName(request.getHostedZoneId());
    logger.debug("Target hosted zone: " + zoneName);

    RequestHandler.checkType(request.getStartRecordType());
    List<DNS53ResourceRecord> records = sqlaccess.listResourceRecords(sess, request.getHostedZoneId(),
            request.getStartRecordName(), null, request.getStartRecordType(), null, -1, -1);
    logger.debug("There are " + records.size() + " resource record sets in this hosted zone.");

    int maxItems = -1;
    if (request.getMaxItems() != null) {
        try {
            maxItems = Integer.valueOf(request.getMaxItems());
        } catch (NumberFormatException e) {
            throw DNS53Faults.InvalidArgument("maxitems parameter must be an integer between 1 and 100.");
        }
    }
    if (maxItems == -1) {
        maxItems = 100; // default
    }
    boolean truncated = false;
    if (maxItems < records.size()) {
        truncated = true;
    }

    Collection<ResourceRecordSet> resourceRecordSets = new LinkedList<ResourceRecordSet>();
    /*
     * ResourceRecordSet ns = new ResourceRecordSet(); ns.setName(zoneName);
     * ns.setType("NS"); Collection<ResourceRecord> nsRecords = new
     * LinkedList<ResourceRecord>();
     */

    int i = 0;
    while (i < records.size() && i < maxItems) {
        DNS53ResourceRecord rec = records.get(i);
        ResourceRecordSet temp = new ResourceRecordSet();
        temp.setName(rec.getName());
        temp.setType(rec.getRdtype());
        temp.setTTL(Long.valueOf(rec.getTtl()));
        if (rec.getSid() != null) {
            temp.setSetIdentifier(rec.getSid());
        }
        if (rec.getWeight() != -1) {
            temp.setWeight(rec.getWeight());
        }
        Collection<ResourceRecord> resourceRecords = new LinkedList<ResourceRecord>();
        resourceRecords.add(new ResourceRecord().withValue(rec.getRdata()));
        temp.setResourceRecords(resourceRecords);
        resourceRecordSets.add(temp);

        ++i;
    }

    // now reduce the duplicates
    TreeMap<String, ResourceRecordSet> map = new TreeMap<String, ResourceRecordSet>();
    for (ResourceRecordSet rs : resourceRecordSets) {
        String key = rs.getName() + "::" + rs.getType();
        ResourceRecordSet temp = map.get(key);
        if (temp == null) {
            map.put(key, rs);
        } else {
            temp.getResourceRecords().add(new ResourceRecord(rs.getResourceRecords().get(0).getValue()));
        }
    }

    resourceRecordSets = map.values();

    result.setResourceRecordSets(resourceRecordSets);
    result.setIsTruncated(truncated);
    if (truncated) {
        result.setNextRecordName("UNIMPLEMENTED");
        result.setNextRecordType("UNIMPLEMENTED");
    }
    result.setMaxItems(String.valueOf(maxItems));

    return result;
}