Java 类com.amazonaws.services.route53.model.ListHostedZonesResult 实例源码

项目:TopStackDNS53    文件:ListHostedZones.java   
@Override
public String marshall(MarshallStruct<ListHostedZonesResult> input,
        HttpServletResponse resp) throws Exception {
    logger.debug("Marshalling the result into xml.");
    ListHostedZonesResult result = input.getMainObject();
    XMLNode response = new XMLNode(DNS53Constants.LISTHOSTEDZONESRESPONSE);
    response.addAttr(DNS53Constants.XMLNS, DNS53Constants.XMLNS_VALUE);
    if(result.getHostedZones() != null && result.getHostedZones().size() > 0){
        XMLNode hzs = QueryUtil.addNode(response, DNS53Constants.HOSTEDZONES);
        for(HostedZone hostedZone : result.getHostedZones()){
            DNS53QueryUtil.marshallHostedZone(hostedZone, hzs);
        }
    }
    QueryUtil.addNode(response, DNS53Constants.MARKER, result.getMarker());
    QueryUtil.addNode(response, DNS53Constants.ISTRUNCATED, result.getIsTruncated());
    QueryUtil.addNode(response, DNS53Constants.NEXTMARKER, result.getNextMarker());
    QueryUtil.addNode(response, DNS53Constants.MAXITEMS, result.getMaxItems());
    logger.debug("Returning the response xml to AbstractHeaderAction.");
    return response.toString();
}
项目:TopStackDNS53    文件:DNS53IntegrationTest.java   
@Test
public void listHostZones0() {
    ListHostedZonesRequest req = new ListHostedZonesRequest();
    ListHostedZonesResult result = customDNS53Client.listHostedZones(req);

    assertNotNull(result);
    assertNotNull(result.getHostedZones());
    assertEquals(1, result.getHostedZones().size());
    assertEquals(zoneName0, result.getHostedZones().get(0).getName());
    assertEquals(callerRef, result.getHostedZones().get(0)
            .getCallerReference());
    assertNotNull(result.getHostedZones().get(0).getConfig());
    assertEquals(comment, result.getHostedZones().get(0).getConfig()
            .getComment());
    // assertEquals(false, result.getIsTruncated());
    assertEquals(null, result.getMarker());
    assertEquals(null, result.getNextMarker());
    assertEquals("100", result.getMaxItems());

    System.out.println(result);
}
项目:TopStackDNS53    文件:DNS53IntegrationTest.java   
@Test
public void listHostZones1() {
    ListHostedZonesRequest req = new ListHostedZonesRequest();
    req.setMarker(this.getZoneId(this.zoneName0));
    ListHostedZonesResult result = customDNS53Client.listHostedZones(req);

    assertNotNull(result);
    assertNotNull(result.getHostedZones());
    assertEquals(1, result.getHostedZones().size());
    assertEquals(zoneName0, result.getHostedZones().get(0).getName());
    assertEquals(callerRef, result.getHostedZones().get(0)
            .getCallerReference());
    assertNotNull(result.getHostedZones().get(0).getConfig());
    assertEquals(comment, result.getHostedZones().get(0).getConfig()
            .getComment());
    // assertEquals(false, result.getIsTruncated());
    assertEquals(null, result.getMarker());
    assertEquals(null, result.getNextMarker());
    assertEquals("100", result.getMaxItems());

    System.out.println(result);
}
项目:ec2-util    文件:AwsRoute53Client.java   
public static String findHostedZoneForDomain(AmazonRoute53 route53, String domain) {
    ListHostedZonesResult listHostedZonesResult = route53.listHostedZones();
    List<HostedZone> hostedZones = listHostedZonesResult.getHostedZones();
    String hostedZoneId = null;
    for (HostedZone hostedZone : hostedZones) {
        if (isRootDomain(domain, hostedZone)) {
            hostedZoneId = hostedZone.getId();
            break;
        }
    }
    return hostedZoneId;
}
项目:TopStackDNS53    文件:ListHostedZones.java   
@Override
public ListHostedZonesResult process0(Session session,
        HttpServletRequest req, HttpServletResponse resp,
        Map<String, String[]> map) throws Exception {
    ListHostedZonesRequest request = unmarshall(req);
    return listHostedZones(request);
}
项目:TopStackDNS53    文件:ListHostedZones.java   
private ListHostedZonesResult listHostedZones(ListHostedZonesRequest request) throws ErrorResponse{
    String marker = request.getMarker();
    String maxI = request.getMaxItems();
    logger.debug("ListHostedZones request parameters { marker = " + marker + ", maxitems = " + maxI + " }");
    AccessMySQL sqlaccess = AccessMySQL.getInstance();

    if(marker != null && sqlaccess.getTableName(marker, this.getAccountId()).equals("FAILED")){
        logger.debug("User passed marker parameter, but no marker found in the server.");
        throw DNS53Faults.InvalidArgument("Marker parameter was passed, but it does not refer to any hosted zone.");
    }
    int maxItems = -1;
    try{
        if(maxI != null){
            maxItems = Integer.valueOf(request.getMaxItems());
        }
    }catch(NumberFormatException e){
        logger.debug("maxitems parameter is not parseable as an integer.");
        throw DNS53Faults.InvalidArgument("maxitems parameter must be an integer between 1 and 100.");
    }
    if(maxItems == -1){
        logger.debug("MaxItems is set to default value since user did not specify a value.");
        maxItems = 100;
    }

    ListHostedZonesResult result = sqlaccess.listHostedZones(request.getMarker(), maxItems, this.getAccountId());

    return result;
}
项目:TopStackDNS53    文件:DNS53IntegrationTest.java   
@Test
// (expected = NoSuchHostedZoneException.class)
public void listHostZones2() {
    ListHostedZonesRequest req = new ListHostedZonesRequest();
    req.setMarker("BOGUS_ZONE_ID");
    ListHostedZonesResult result = null;
    try {
        result = customDNS53Client.listHostedZones(req);
    } catch (AmazonServiceException e) {
        assertEquals("NoSuchHostedZone", e.getErrorCode());
    }
    System.out.println(result);
}
项目:TopStackDNS53    文件:DNS53MetadataUtil.java   
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);

    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());
}
项目:TopStackDNS53    文件:DNS53Client.java   
public ListHostedZonesResult listHostedZones(ListHostedZonesRequest req) throws AmazonServiceException, AmazonClientException{
    Client c = Client.create();
    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;
}
项目:TopStackDNS53    文件:AccessMySQL.java   
/**
 * Returns hashmap of <KEY: zoneID, VALUE: String[] of ID, name, caller
 * reference, and comment>
 *
 * @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;
}
项目:jwrapper-maven-plugin    文件:CarrotRoute53.java   
public HostedZone findZone(final String source) {

        final ListHostedZonesResult zoneResult = amazonClient.listHostedZones();

        final List<HostedZone> zoneList = zoneResult.getHostedZones();

        for (final HostedZone zone : zoneList) {

            final String name = zone.getName();

            if (source.endsWith(name)) {
                return zone;
            }

        }

        return null;

    }
项目:TopStackDNS53    文件:AccessDB.java   
public ListHostedZonesResult listHostedZones(String marker_tableName, int maxItems, long accId) throws ErrorResponse;