Example usage for com.amazonaws.services.route53.model HostedZoneConfig setComment

List of usage examples for com.amazonaws.services.route53.model HostedZoneConfig setComment

Introduction

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

Prototype


public void setComment(String comment) 

Source Link

Document

Any comments that you want to include about the hosted zone.

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 www. j ava 2  s  . co  m
    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.client.DNS53Client.java

License:Apache License

public GetHostedZoneResult getHostedZone(GetHostedZoneRequest req)
        throws AmazonServiceException, AmazonClientException {
    Client c = Client.create();/*ww w.  j  ava 2  s  . c  o  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.client.DNS53Client.java

License:Apache License

public ListHostedZonesResult listHostedZones(ListHostedZonesRequest req)
        throws AmazonServiceException, AmazonClientException {
    Client c = Client.create();//from   ww w. j a v a 2  s . c o m
    WebResource r = c.resource(this.serverURL);
    MultivaluedMap<String, String> paramMap = new MultivaluedMapImpl();
    if (req.getMarker() != null) {
        paramMap.add("marker", req.getMarker());
    }
    if (req.getMaxItems() != null) {
        paramMap.add("maxitems", req.getMaxItems());
    }

    ClientResponse response = r.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);
    }

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

    ListHostedZonesResult result = new ListHostedZonesResult();
    if (interResult.getHostedZones() != null) {
        Collection<HostedZone> hzs = new LinkedList<HostedZone>();
        for (HostedZonePOJO hz : interResult.getHostedZones()) {
            HostedZone temp = new HostedZone();
            temp.setCallerReference(hz.getCallerReference());
            temp.setId(hz.getId());
            temp.setName(hz.getName());
            temp.setResourceRecordSetCount(hz.getResourceRecordSetCount());
            if (hz.getConfig() != null) {
                HostedZoneConfig config = new HostedZoneConfig();
                if (hz.getConfig().getComment() != null) {
                    config.setComment(hz.getConfig().getComment());
                }
                temp.setConfig(config);
            }
            hzs.add(temp);
        }
        result.setHostedZones(hzs);
    }
    if (interResult.getMarker() != null) {
        result.setMarker(interResult.getMarker());
    }
    if (interResult.getMaxItems() != null) {
        result.setMaxItems(interResult.getMaxItems());
    }
    if (interResult.getNextMarker() != null) {
        result.setNextMarker(interResult.getNextMarker());
    }
    return result;
}

From source file:com.msi.dns53.server.AccessMySQL.java

License:Apache License

/**
 * Returns hashmap of <KEY: zoneID, VALUE: String[] of ID, name, caller
 * reference, and comment>/*from   w  ww.  j  a  v  a2s  .c  o  m*/
 *
 * @param marker_tableName
 *            table name of the marker
 * @param maxItems
 *            number of items returned when the actual number of list
 *            exceeds maxItems
 * @return Hashmap of <KEY: zoneID, VALUE: String[] of ID, name, caller
 *         reference, and comment>
 * @throws InternalErrorException
 */
@Override
public ListHostedZonesResult listHostedZones(String marker, int maxItems, long accId) throws ErrorResponse {
    ListHostedZonesResult result = new ListHostedZonesResult();
    Collection<HostedZone> hostedZones = new LinkedList<HostedZone>();
    int lim = maxItems;
    try {
        ResultSet rs = null;
        String query = null;
        Statement stmt = this.sqlConnection.createStatement();
        if (marker == null) {
            logger.debug("No marker is given.");
            query = "SELECT * FROM msi.zones WHERE accountId = " + accId + ";";

        } else {
            logger.debug("Marker is assigned.");
            query = "SELECT * FROM msi.zones WHERE accountId = " + accId + " AND ID >= \'" + marker + "\';";
        }

        rs = stmt.executeQuery(query);
        while (lim != 0 && rs.next()) {
            HostedZone hz = new HostedZone(rs.getString("ID"), rs.getString("name"),
                    rs.getString("callerReference"));
            HostedZoneConfig config = new HostedZoneConfig();
            config.setComment(rs.getString("comment"));
            hz.setConfig(config);
            --lim;
            hostedZones.add(hz);
        }

        if (marker != null && hostedZones.size() == 0) {
            // TODO throw an exception for marker not existing (test against
            // AWS to see which exception is being returned)
        }

        boolean truncated = rs.next();

        logger.debug("Relative Limit = " + lim + "; MaxItems = " + maxItems);
        logger.debug("Truncated = " + truncated);

        if (lim == 0 && truncated) {
            truncated = true;
        }

        result.setHostedZones(hostedZones);
        result.setMaxItems(String.valueOf(maxItems));
        result.setIsTruncated(truncated);
        if (truncated) {
            result.setNextMarker(rs.getString("ID"));
        }

    } catch (SQLException e) {
        System.err.println("Failed to get zone informations for listHostedZone request.");
        e.printStackTrace();
        throw DNS53Faults.InternalError();
    }
    logger.debug("Returning " + hostedZones.size() + " hosted zones information.");
    return result;
}

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());
    }// w w w .  ja v  a 2  s. co 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: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 ava  2  s.  com
    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;
}