Example usage for com.amazonaws.services.route53.model CreateHostedZoneRequest getHostedZoneConfig

List of usage examples for com.amazonaws.services.route53.model CreateHostedZoneRequest getHostedZoneConfig

Introduction

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

Prototype


public HostedZoneConfig getHostedZoneConfig() 

Source Link

Document

(Optional) A complex type that contains the following optional values:

  • For public and private hosted zones, an optional comment

  • For private hosted zones, an optional PrivateZone element

If you don't specify a comment or the PrivateZone element, omit HostedZoneConfig and the other elements.

Usage

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

License:Apache License

public CreateHostedZoneResult createHostedZone(CreateHostedZoneRequest req)
        throws AmazonServiceException, AmazonClientException {
    Client c = Client.create();//from  ww w. j a v  a2 s. c om
    WebResource r = c.resource(this.serverURL);

    String entity = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
            + "<CreateHostedZoneRequest xmlns=\"https://route53.amazonaws.com/doc/2012-02-29/\">" + "<Name>"
            + req.getName() + "</Name>" + "<CallerReference>" + req.getCallerReference() + "</CallerReference>";
    if (req.getHostedZoneConfig() != null && req.getHostedZoneConfig().getComment() != null) {
        entity += "<HostedZoneConfig>" + "<Comment>" + req.getHostedZoneConfig().getComment() + "</Comment>"
                + "</HostedZoneConfig>";
    }
    entity += "</CreateHostedZoneRequest>";

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

    String resultXml = response.getEntity(String.class);
    if (response.getStatus() > 299 || response.getStatus() < 200) {
        exceptionMapper(response, resultXml);
    }

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

    CreateHostedZoneResult result = new CreateHostedZoneResult();
    if (interResult.getHostedZone() != null) {
        HostedZone hostedZone = new HostedZone();
        hostedZone.setId(interResult.getHostedZone().getId());
        hostedZone.setName(interResult.getHostedZone().getName());
        hostedZone.setCallerReference(interResult.getHostedZone().getCallerReference());
        if (interResult.getHostedZone().getConfig() != null) {
            HostedZoneConfig config = new HostedZoneConfig();
            config.setComment(interResult.getHostedZone().getConfig().getComment());
            hostedZone.setConfig(config);
        }
        result.setHostedZone(hostedZone);
    }
    if (interResult.getChangeInfo() != null) {
        ChangeInfo changeInfo = new ChangeInfo();
        changeInfo.setId(interResult.getChangeInfo().getId());
        changeInfo.setStatus(interResult.getChangeInfo().getStatus());
        changeInfo.setSubmittedAt(interResult.getChangeInfo().getSubmittedAt());
        changeInfo.setComment(interResult.getChangeInfo().getComment());
        result.setChangeInfo(changeInfo);
    }
    if (interResult.getDelegationSet() != null) {
        DelegationSet dSet = new DelegationSet();
        dSet.setNameServers(interResult.getDelegationSet().getNameServers());
        result.setDelegationSet(dSet);
    }
    return result;
}

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

License:Apache License

private CreateHostedZoneResult createHostedZone(Session session, CreateHostedZoneRequest request)
        throws ErrorResponse {
    CreateHostedZoneResult result = new CreateHostedZoneResult();
    Date submittedAt = new Date();
    AccessMySQL sqlaccess = AccessMySQL.getInstance();

    String name = request.getName();
    try {//  w  ww. ja  v a2  s  .  c  om
        new java.net.URI("http://" + name);
    } catch (URISyntaxException e) {
        throw DNS53Faults.InvalidDomainName();
    }

    String comment = null;
    if (request.getHostedZoneConfig() != null) {
        comment = request.getHostedZoneConfig().getComment();
    }
    List<String> zoneInfo = sqlaccess.createHostedZone(session, name, request.getCallerReference(), comment,
            this.getAccountId());
    String zoneId = zoneInfo.get(0);
    if (zoneId.equals("DUPLICATE_REFERENCE")) {
        throw DNS53Faults.HostedZoneAlreadyExists();
    } else if (zoneId.equals("DUPLICATE_NAME")) {
        throw DNS53Faults.DelegationSetNotAvailable();
    } else {
        String status = DNS53Constants.PENDING;
        String tableName = zoneInfo.get(1);
        String changeID = RequestHandler.writeChange(sqlaccess, status, submittedAt.toString(), tableName,
                "CREATE");

        HostedZone hz = new HostedZone(zoneId, request.getName(), request.getCallerReference());
        hz.setConfig(request.getHostedZoneConfig());
        result.setHostedZone(hz);

        ChangeInfo ci = new ChangeInfo(changeID, status, submittedAt);
        result.setChangeInfo(ci);

        List<String> nameServers = new LinkedList<String>();
        for (int i = 2; i < zoneInfo.size(); ++i) {
            nameServers.add(zoneInfo.get(i));
        }
        DelegationSet ds = new DelegationSet(nameServers);
        result.setDelegationSet(ds);
    }
    return result;
}