Example usage for com.amazonaws.services.route53.model GetHostedZoneResult setDelegationSet

List of usage examples for com.amazonaws.services.route53.model GetHostedZoneResult setDelegationSet

Introduction

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

Prototype


public void setDelegationSet(DelegationSet delegationSet) 

Source Link

Document

A complex type that lists the Amazon Route 53 name servers for the specified hosted zone.

Usage

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

License:Apache License

public GetHostedZoneResult getHostedZone(GetHostedZoneRequest req)
        throws AmazonServiceException, AmazonClientException {
    Client c = Client.create();//from   w w w  .jav a2 s  . co m
    WebResource r = c.resource(this.serverURL);
    ClientResponse response = r.path(req.getId()).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);
    }

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

    GetHostedZoneResult result = new GetHostedZoneResult();
    if (interResult.getHostedZone() != null) {
        HostedZone hz = new HostedZone();
        hz.setCallerReference(interResult.getHostedZone().getCallerReference());
        hz.setId(interResult.getHostedZone().getId());
        hz.setName(interResult.getHostedZone().getName());
        hz.setResourceRecordSetCount(interResult.getHostedZone().getResourceRecordSetCount());
        if (interResult.getHostedZone().getConfig() != null) {
            HostedZoneConfig config = new HostedZoneConfig();
            config.setComment(interResult.getHostedZone().getConfig().getComment());
            hz.setConfig(config);
        }
        result.setHostedZone(hz);
    }
    if (interResult.getDelegationSet() != null) {
        DelegationSetPOJO ds = interResult.getDelegationSet();
        DelegationSet ds_ = new DelegationSet();
        if (ds.getNameServers() != null) {
            ds_.setNameServers(ds.getNameServers());
        }
        result.setDelegationSet(ds_);
    }
    return result;
}

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

License:Apache License

private GetHostedZoneResult getHostedZone(Session sess, GetHostedZoneRequest request) throws ErrorResponse {
    String zoneId = request.getId();
    logger.debug("GetHosteZone target: " + zoneId);
    GetHostedZoneResult result = new GetHostedZoneResult();
    AccessMySQL sqlaccess = AccessMySQL.getInstance();
    String[] responseCont = sqlaccess.getHostedZone(zoneId);
    if (responseCont[1] == null) {
        throw DNS53Faults.NoSuchHostedZone(zoneId);
    }//from w  w  w. j  a va 2s .c  o  m
    HostedZone hz = new HostedZone();
    hz.setId(responseCont[0]);
    hz.setName(responseCont[1]);
    hz.setCallerReference(responseCont[2]);
    HostedZoneConfig config = new HostedZoneConfig();
    config.setComment(responseCont[3]);
    hz.setConfig(config);
    result.setHostedZone(hz);

    DelegationSet delegationSet = new DelegationSet();
    Collection<String> nameServers = new LinkedList<String>();
    List<DNS53ResourceRecord> nsRecords = sqlaccess.listResourceRecords(sess, request.getId(), null, null, "NS",
            null, -1, -1);
    for (DNS53ResourceRecord ns : nsRecords) {
        String nameserver = ns.getRdata();
        nameserver = nameserver.substring(0, nameserver.length() - 1);
        nameServers.add(nameserver);
    }
    delegationSet.setNameServers(nameServers);
    result.setDelegationSet(delegationSet);
    logger.debug("Returning the result: " + result.toString());
    return result;
}