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

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

Introduction

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

Prototype


public void setHostedZoneConfig(HostedZoneConfig hostedZoneConfig) 

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.server.query.CreateHostedZone.java

License:Apache License

public CreateHostedZoneRequest unmarshall(HttpServletRequest req)
        throws IOException, ParserConfigurationException, SAXException {
    final CreateHostedZoneRequest request = new CreateHostedZoneRequest();

    StringBuilder stringBuilder = new StringBuilder(1000);
    Scanner scanner = new Scanner(req.getInputStream());
    while (scanner.hasNextLine()) {
        stringBuilder.append(scanner.nextLine());
    }//from   w w  w.  j  a  v  a2  s  .  c  o m
    String body = stringBuilder.toString();
    logger.debug("XML Body Content: " + body);

    DefaultHandler handler = new DefaultHandler() {
        private boolean createHostedZoneRequest = false;
        private boolean hostedZoneConfig = false;
        private CharArrayWriter contents = new CharArrayWriter();

        public void startElement(String uri, String localName, String nodeName, Attributes attributes)
                throws SAXException {
            contents.reset();
            if (!uri.equals(DNS53Constants.XMLNS_VALUE)) {
                throw DNS53Faults.InvalidInput("The XML you provided did not have the correct namespace.");
            }
            if (nodeName.equals(DNS53Constants.CREATEHOSTEDZONEREQUEST)) {
                createHostedZoneRequest = true;
            }
            if (nodeName.equals(DNS53Constants.HOSTEDZONECONFIG)) {
                hostedZoneConfig = true;
            }
        }

        public void endElement(String uri, String localName, String nodeName) throws SAXException {
            if (createHostedZoneRequest && localName.equals(DNS53Constants.CREATEHOSTEDZONEREQUEST)) {
                createHostedZoneRequest = false;
            }
            if (createHostedZoneRequest && hostedZoneConfig
                    && localName.equals(DNS53Constants.HOSTEDZONECONFIG)) {
                hostedZoneConfig = false;
            }
            if (createHostedZoneRequest && localName.equals(DNS53Constants.NAME)) {
                request.setName(contents.toString());
            }
            if (createHostedZoneRequest && localName.equals(DNS53Constants.CALLERREFERENCE)) {
                request.setCallerReference(contents.toString());
            }
            if (createHostedZoneRequest && hostedZoneConfig && localName.equals(DNS53Constants.COMMENT)) {
                HostedZoneConfig config = new HostedZoneConfig();
                config.setComment(contents.toString());
                request.setHostedZoneConfig(config);
            }
        }

        public void characters(char ch[], int start, int length) throws SAXException {
            this.contents.write(ch, start, length);
        }
    };

    XMLReader xr = XMLReaderFactory.createXMLReader();
    xr.setContentHandler(handler);
    xr.parse(new InputSource(new StringReader(body)));

    logger.debug("Unmarshalling complete: " + request.toString());
    return request;
}

From source file:jp.classmethod.aws.gradle.route53.CreateHostedZoneTask.java

License:Apache License

@TaskAction
public void createHostedZone() throws UnknownHostException {
    // to enable conventionMappings feature
    String hostedZoneName = getHostedZoneName();
    String callerReference = getCallerReference() != null ? getCallerReference()
            : InetAddress.getLocalHost().getHostName();
    String comment = getComment();

    AmazonRoute53PluginExtension ext = getProject().getExtensions()
            .getByType(AmazonRoute53PluginExtension.class);
    AmazonRoute53 route53 = ext.getClient();

    getLogger().info("callerRef = {}", callerReference);

    CreateHostedZoneRequest req = new CreateHostedZoneRequest().withName(hostedZoneName)
            .withCallerReference(callerReference);
    if (comment != null) {
        req.setHostedZoneConfig(new HostedZoneConfig().withComment(comment));
    }/*  w w w.j  a va 2 s  .co m*/

    try {
        createHostedZoneResult = route53.createHostedZone(req);
        nameServers = createHostedZoneResult.getDelegationSet().getNameServers();
        hostedZoneId = createHostedZoneResult.getHostedZone().getId();
        getLogger().info("HostedZone {} ({} - {})  is created.", hostedZoneId, hostedZoneName, callerReference);
        nameServers.forEach(it -> {
            getLogger().info("  NS {}", it);
        });
    } catch (HostedZoneAlreadyExistsException e) {
        getLogger().error("HostedZone {} - {} is already created.", hostedZoneName, callerReference);
    }
}