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

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

Introduction

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

Prototype

public CreateHostedZoneRequest() 

Source Link

Document

Default constructor for CreateHostedZoneRequest object.

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  om*/
    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));
    }//from   w  w w .  jav  a 2 s.c  o 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);
    }
}