mirror of https://github.com/apache/jclouds.git
refactored out common id parsing logic in ultradns
This commit is contained in:
parent
4267c55745
commit
e3f51bd030
|
@ -35,7 +35,7 @@ import org.jclouds.ultradns.ws.binders.ZoneAndResourceRecordToXML;
|
|||
import org.jclouds.ultradns.ws.domain.ResourceRecord;
|
||||
import org.jclouds.ultradns.ws.domain.ResourceRecordMetadata;
|
||||
import org.jclouds.ultradns.ws.filters.SOAPWrapWithPasswordAuth;
|
||||
import org.jclouds.ultradns.ws.xml.GuidHandler;
|
||||
import org.jclouds.ultradns.ws.xml.IDHandler;
|
||||
import org.jclouds.ultradns.ws.xml.ResourceRecordListHandler;
|
||||
|
||||
import com.google.common.collect.FluentIterable;
|
||||
|
@ -56,7 +56,7 @@ public interface ResourceRecordAsyncApi {
|
|||
*/
|
||||
@Named("createResourceRecord")
|
||||
@POST
|
||||
@XMLResponseParser(GuidHandler.class)
|
||||
@XMLResponseParser(IDHandler.Guid.class)
|
||||
@MapBinder(ZoneAndResourceRecordToXML.class)
|
||||
ListenableFuture<String> create(@PayloadParam("resourceRecord") ResourceRecord toCreate)
|
||||
throws ResourceAlreadyExistsException;
|
||||
|
|
|
@ -33,8 +33,7 @@ import org.jclouds.ultradns.ws.UltraDNSWSExceptions.ResourceAlreadyExistsExcepti
|
|||
import org.jclouds.ultradns.ws.domain.ResourceRecord;
|
||||
import org.jclouds.ultradns.ws.domain.RoundRobinPool;
|
||||
import org.jclouds.ultradns.ws.filters.SOAPWrapWithPasswordAuth;
|
||||
import org.jclouds.ultradns.ws.xml.GuidHandler;
|
||||
import org.jclouds.ultradns.ws.xml.RRPoolIDHandler;
|
||||
import org.jclouds.ultradns.ws.xml.IDHandler;
|
||||
import org.jclouds.ultradns.ws.xml.ResourceRecordListHandler;
|
||||
import org.jclouds.ultradns.ws.xml.RoundRobinPoolListHandler;
|
||||
|
||||
|
@ -75,7 +74,7 @@ public interface RoundRobinPoolAsyncApi {
|
|||
*/
|
||||
@Named("addRRLBPool")
|
||||
@POST
|
||||
@XMLResponseParser(RRPoolIDHandler.class)
|
||||
@XMLResponseParser(IDHandler.RRPool.class)
|
||||
@Payload("<v01:addRRLBPool><transactionID /><zoneName>{zoneName}</zoneName><hostName>{hostName}</hostName><description>{description}</description><poolRecordType>1</poolRecordType><rrGUID /></v01:addRRLBPool>")
|
||||
ListenableFuture<String> createAPoolForHostname(@PayloadParam("description") String name,
|
||||
@PayloadParam("hostName") String hostname) throws ResourceAlreadyExistsException;
|
||||
|
@ -85,7 +84,7 @@ public interface RoundRobinPoolAsyncApi {
|
|||
*/
|
||||
@Named("addRecordToRRPool")
|
||||
@POST
|
||||
@XMLResponseParser(GuidHandler.class)
|
||||
@XMLResponseParser(IDHandler.Guid.class)
|
||||
@Payload("<v01:addRecordToRRPool><transactionID /><roundRobinRecord lbPoolID=\"{lbPoolID}\" info1Value=\"{address}\" ZoneName=\"{zoneName}\" Type=\"1\" TTL=\"{ttl}\"/></v01:addRecordToRRPool>")
|
||||
ListenableFuture<String> addARecordWithAddressAndTTL(@PayloadParam("lbPoolID") String lbPoolID,
|
||||
@PayloadParam("address") String ipv4Address, @PayloadParam("ttl") int ttl)
|
||||
|
@ -115,7 +114,7 @@ public interface RoundRobinPoolAsyncApi {
|
|||
*/
|
||||
@Named("addRRLBPool")
|
||||
@POST
|
||||
@XMLResponseParser(RRPoolIDHandler.class)
|
||||
@XMLResponseParser(IDHandler.RRPool.class)
|
||||
@Payload("<v01:addRRLBPool><transactionID /><zoneName>{zoneName}</zoneName><hostName>{hostName}</hostName><description>{description}</description><poolRecordType>28</poolRecordType><rrGUID /></v01:addRRLBPool>")
|
||||
ListenableFuture<String> createAAAAPoolForHostname(@PayloadParam("description") String name,
|
||||
@PayloadParam("hostName") String hostname) throws ResourceAlreadyExistsException;
|
||||
|
@ -125,7 +124,7 @@ public interface RoundRobinPoolAsyncApi {
|
|||
*/
|
||||
@Named("addRecordToRRPool")
|
||||
@POST
|
||||
@XMLResponseParser(GuidHandler.class)
|
||||
@XMLResponseParser(IDHandler.Guid.class)
|
||||
@Payload("<v01:addRecordToRRPool><transactionID /><roundRobinRecord lbPoolID=\"{lbPoolID}\" info1Value=\"{address}\" ZoneName=\"{zoneName}\" Type=\"28\" TTL=\"{ttl}\"/></v01:addRecordToRRPool>")
|
||||
ListenableFuture<String> addAAAARecordWithAddressAndTTL(@PayloadParam("lbPoolID") String lbPoolID,
|
||||
@PayloadParam("address") String ipv6Address, @PayloadParam("ttl") int ttl)
|
||||
|
|
|
@ -31,7 +31,7 @@ import org.jclouds.rest.annotations.VirtualHost;
|
|||
import org.jclouds.rest.annotations.XMLResponseParser;
|
||||
import org.jclouds.ultradns.ws.domain.Task;
|
||||
import org.jclouds.ultradns.ws.filters.SOAPWrapWithPasswordAuth;
|
||||
import org.jclouds.ultradns.ws.xml.GuidHandler;
|
||||
import org.jclouds.ultradns.ws.xml.IDHandler;
|
||||
import org.jclouds.ultradns.ws.xml.TaskHandler;
|
||||
import org.jclouds.ultradns.ws.xml.TaskListHandler;
|
||||
|
||||
|
@ -52,7 +52,7 @@ public interface TaskAsyncApi {
|
|||
*/
|
||||
@Named("runTest")
|
||||
@POST
|
||||
@XMLResponseParser(GuidHandler.class)
|
||||
@XMLResponseParser(IDHandler.Guid.class)
|
||||
@Payload("<v01:runTest><value>{value}</value></v01:runTest>")
|
||||
ListenableFuture<String> runTest(@PayloadParam("value") String value);
|
||||
|
||||
|
|
|
@ -23,33 +23,53 @@ import static org.jclouds.util.SaxUtils.currentOrNull;
|
|||
import static org.jclouds.util.SaxUtils.equalsOrSuffix;
|
||||
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.xml.sax.Attributes;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class GuidHandler extends ParseSax.HandlerForGeneratedRequestWithResult<String> {
|
||||
public abstract class IDHandler extends ParseSax.HandlerForGeneratedRequestWithResult<String> {
|
||||
|
||||
public static class Guid extends IDHandler {
|
||||
public Guid() {
|
||||
super("guid");
|
||||
}
|
||||
}
|
||||
|
||||
public static class RRPool extends IDHandler {
|
||||
public RRPool() {
|
||||
super("RRPoolID");
|
||||
}
|
||||
}
|
||||
|
||||
public static class TCPool extends IDHandler {
|
||||
public TCPool() {
|
||||
super("TCPoolID");
|
||||
}
|
||||
}
|
||||
|
||||
private String idElement;
|
||||
|
||||
private StringBuilder currentText = new StringBuilder();
|
||||
private String guid = null;
|
||||
private String id = null;
|
||||
|
||||
private IDHandler(String idElement) {
|
||||
this.idElement = checkNotNull(idElement, "idElement");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getResult() {
|
||||
try {
|
||||
return checkNotNull(guid, "guid not present in the response");
|
||||
return checkNotNull(id, "%s not present in the response", idElement);
|
||||
} finally {
|
||||
guid = null;
|
||||
id = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startElement(String url, String name, String qName, Attributes attributes) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endElement(String uri, String name, String qName) {
|
||||
if (equalsOrSuffix(qName, "guid")) {
|
||||
guid = currentOrNull(currentText);
|
||||
if (equalsOrSuffix(qName, idElement)) {
|
||||
id = currentOrNull(currentText);
|
||||
}
|
||||
currentText = new StringBuilder();
|
||||
}
|
|
@ -1,61 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.ultradns.ws.xml;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static org.jclouds.util.SaxUtils.currentOrNull;
|
||||
import static org.jclouds.util.SaxUtils.equalsOrSuffix;
|
||||
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.xml.sax.Attributes;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class RRPoolIDHandler extends ParseSax.HandlerForGeneratedRequestWithResult<String> {
|
||||
private StringBuilder currentText = new StringBuilder();
|
||||
private String rrPoolID = null;
|
||||
|
||||
@Override
|
||||
public String getResult() {
|
||||
try {
|
||||
return checkNotNull(rrPoolID, "RRPoolId not present in the response");
|
||||
} finally {
|
||||
rrPoolID = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startElement(String url, String name, String qName, Attributes attributes) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endElement(String uri, String name, String qName) {
|
||||
if (equalsOrSuffix(qName, "RRPoolID")) {
|
||||
rrPoolID = currentOrNull(currentText);
|
||||
}
|
||||
currentText = new StringBuilder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void characters(char ch[], int start, int length) {
|
||||
currentText.append(ch, start, length);
|
||||
}
|
||||
}
|
|
@ -23,7 +23,7 @@ import static org.testng.Assert.assertEquals;
|
|||
import java.io.InputStream;
|
||||
|
||||
import org.jclouds.http.functions.BaseHandlerTest;
|
||||
import org.jclouds.ultradns.ws.xml.GuidHandler;
|
||||
import org.jclouds.ultradns.ws.xml.IDHandler;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
|
@ -35,7 +35,7 @@ public class RunTestResponseTest extends BaseHandlerTest {
|
|||
public void test() {
|
||||
InputStream is = getClass().getResourceAsStream("/taskid.xml");
|
||||
|
||||
GuidHandler handler = injector.getInstance(GuidHandler.class);
|
||||
IDHandler.Guid handler = injector.getInstance(IDHandler.Guid.class);
|
||||
assertEquals(factory.create(handler).parse(is), "8d7a1725-4f4a-4b70-affa-f01dcce1526e");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue