Example usage for com.amazonaws.services.route53.model RRType TXT

List of usage examples for com.amazonaws.services.route53.model RRType TXT

Introduction

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

Prototype

RRType TXT

To view the source code for com.amazonaws.services.route53.model RRType TXT.

Click Source Link

Usage

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

License:Apache License

public void populateServiceMetadata(final ServletConfig config, String serviceName) {
    logger.debug("init(): TXT record will be created for this service regarding its port and context path.");
    String contextPath = config.getServletContext().getContextPath();
    String port = Appctx.getBean("TOMCAT_PORT");
    String master_passwd = Appctx.getBean("DB_PASSWORD");

    final String fqdn = (String) ConfigurationUtil.getConfiguration(Arrays.asList(new String[] { "FQDN" }));
    final String domain = (String) ConfigurationUtil
            .getConfiguration(Arrays.asList(new String[] { "FQDN_DOMAIN" }));
    String txtRecordValue = ":" + port + contextPath;
    String baseDNSServerURL = "http://localhost:" + port + "/DNS53Server/2012-02-29/";

    logger.debug("Tomcat port = " + port + "; FQDN = " + fqdn + "; domain = " + domain + "; TXT Record Value = "
            + txtRecordValue + "; BaseDNSServerUrl = " + baseDNSServerURL);

    DNS53Client client = new DNS53Client(baseDNSServerURL + "hostedzone", baseDNSServerURL + "change", "admin",
            master_passwd);/*from  w w  w. j  ava 2  s.c  o  m*/

    logger.debug("Service name = " + serviceName);
    String recordName = serviceName + "-" + fqdn;
    logger.debug("TXT Record Name: " + recordName);

    logger.debug("init(): Calling ListHostedZones to find the target zone!");
    ListHostedZonesRequest lhzReq = new ListHostedZonesRequest();
    lhzReq.setMaxItems("1");

    ListHostedZonesResult lhzResult = client.listHostedZones(lhzReq);

    HostedZone zone = null;
    List<HostedZone> zones = lhzResult.getHostedZones();
    if (zones != null && zones.size() > 0) {
        for (HostedZone hz : zones) {
            if (hz.getName().equals(domain + ".") || hz.getName().equals(domain)) {
                zone = hz;
            }
        }
    } else {
        logger.error(
                "BaseAsyncServlet encountered an error while it was trying to find the target hosted zone.");
        throw ErrorResponse.InternalFailure();
    }

    if (zone == null) {
        logger.error("BaseAsyncServlet could not find any zone for this TopStackWeb instance.");
        throw ErrorResponse.InternalFailure();
    }

    // TODO (optional) check for the CNAME record for this service before proceeding

    logger.debug("init(): Creating a new TXT record for " + recordName + " with \"" + txtRecordValue
            + "\" as its value!");
    String zoneId = zone.getId();
    ChangeResourceRecordSetsRequest crrsReq = new ChangeResourceRecordSetsRequest();
    crrsReq.setHostedZoneId(zoneId);
    ChangeBatch cb = new ChangeBatch();
    cb.setComment(
            "BaseAsyncServlet => init(): Registering " + serviceName + " service for Transcend TopStack.");
    Collection<Change> changes = new LinkedList<Change>();
    Change change = new Change();
    change.setAction(ChangeAction.CREATE);
    ResourceRecordSet rrSet = new ResourceRecordSet();
    rrSet.setName(recordName);
    rrSet.setTTL(900L);
    rrSet.setType(RRType.TXT);
    Collection<ResourceRecord> rr = new LinkedList<ResourceRecord>();
    ResourceRecord record = new ResourceRecord();
    record.setValue(txtRecordValue);
    rr.add(record);
    rrSet.setResourceRecords(rr);
    change.setResourceRecordSet(rrSet);
    changes.add(change);
    cb.setChanges(changes);
    crrsReq.setChangeBatch(cb);
    ChangeResourceRecordSetsResult result = client.changeResourceRecordSets(crrsReq);
    logger.debug("Result for the last ChangeResourceRecordSets request: " + result.toString());
}

From source file:org.ofbiz.tenant.amazonaws.util.AwsUtil.java

License:Apache License

/**
 * get resource record type/*w  w  w.  j av  a 2s.  co m*/
 * @param value
 * @return
 * @throws GeneralException
 */
public static RRType getRRType(String value) throws GeneralException {
    RRType rrType = null;
    if ("A".equals(value)) {
        rrType = RRType.A;
    } else if ("CNAME".equals(value)) {
        rrType = RRType.CNAME;
    } else if ("MX".equals(value)) {
        rrType = RRType.MX;
    } else if ("AAAA".equals(value)) {
        rrType = RRType.AAAA;
    } else if ("TXT".equals(value)) {
        rrType = RRType.TXT;
    } else if ("PTR".equals(value)) {
        rrType = RRType.PTR;
    } else if ("SRV".equals(value)) {
        rrType = RRType.SRV;
    } else if ("SPF".equals(value)) {
        rrType = RRType.SPF;
    } else if ("NS".equals(value)) {
        rrType = RRType.NS;
    } else if ("SOA".equals(value)) {
        rrType = RRType.SOA;
    } else {
        throw new GeneralException(
                "The type need to be one of: A, CNAME, MX, AAAA, TXT, PTR, SRV, SPF, NS, SOA");
    }
    return rrType;
}