dynect: cleaner approach to sending non-standard Content-Type on GET

This commit is contained in:
adriancole 2013-03-03 20:18:34 -08:00
parent 4f2c64681a
commit fad291a29f
12 changed files with 116 additions and 87 deletions

View File

@ -25,13 +25,13 @@ import javax.ws.rs.Consumes;
import javax.ws.rs.GET; import javax.ws.rs.GET;
import javax.ws.rs.Path; import javax.ws.rs.Path;
import javax.ws.rs.PathParam; import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import org.jclouds.Fallbacks.NullOnNotFoundOr404; import org.jclouds.Fallbacks.NullOnNotFoundOr404;
import org.jclouds.dynect.v3.domain.Job; import org.jclouds.dynect.v3.domain.Job;
import org.jclouds.dynect.v3.features.RecordAsyncApi; import org.jclouds.dynect.v3.features.RecordAsyncApi;
import org.jclouds.dynect.v3.features.SessionAsyncApi; import org.jclouds.dynect.v3.features.SessionAsyncApi;
import org.jclouds.dynect.v3.features.ZoneAsyncApi; import org.jclouds.dynect.v3.features.ZoneAsyncApi;
import org.jclouds.dynect.v3.filters.AlwaysAddContentType;
import org.jclouds.dynect.v3.filters.SessionManager; import org.jclouds.dynect.v3.filters.SessionManager;
import org.jclouds.rest.annotations.Delegate; import org.jclouds.rest.annotations.Delegate;
import org.jclouds.rest.annotations.Fallback; import org.jclouds.rest.annotations.Fallback;
@ -55,8 +55,7 @@ public interface DynECTAsyncApi {
@Named("GetJob") @Named("GetJob")
@GET @GET
@Path("/Job/{jobId}") @Path("/Job/{jobId}")
@Produces(APPLICATION_JSON) @RequestFilters({ AlwaysAddContentType.class, SessionManager.class })
@RequestFilters(SessionManager.class)
@Headers(keys = "API-Version", values = "{jclouds.api-version}") @Headers(keys = "API-Version", values = "{jclouds.api-version}")
@Fallback(NullOnNotFoundOr404.class) @Fallback(NullOnNotFoundOr404.class)
@Consumes(APPLICATION_JSON) @Consumes(APPLICATION_JSON)

View File

@ -19,7 +19,6 @@
package org.jclouds.dynect.v3.features; package org.jclouds.dynect.v3.features;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
import static org.jclouds.http.Uris.uriBuilder; import static org.jclouds.http.Uris.uriBuilder;
import java.net.URI; import java.net.URI;
@ -29,7 +28,6 @@ import javax.inject.Named;
import javax.ws.rs.GET; import javax.ws.rs.GET;
import javax.ws.rs.Path; import javax.ws.rs.Path;
import javax.ws.rs.PathParam; import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import org.jclouds.Fallbacks.NullOnNotFoundOr404; import org.jclouds.Fallbacks.NullOnNotFoundOr404;
import org.jclouds.dynect.v3.DynECTExceptions.JobStillRunningException; import org.jclouds.dynect.v3.DynECTExceptions.JobStillRunningException;
@ -44,6 +42,7 @@ import org.jclouds.dynect.v3.domain.rdata.NSData;
import org.jclouds.dynect.v3.domain.rdata.PTRData; import org.jclouds.dynect.v3.domain.rdata.PTRData;
import org.jclouds.dynect.v3.domain.rdata.SRVData; import org.jclouds.dynect.v3.domain.rdata.SRVData;
import org.jclouds.dynect.v3.domain.rdata.TXTData; import org.jclouds.dynect.v3.domain.rdata.TXTData;
import org.jclouds.dynect.v3.filters.AlwaysAddContentType;
import org.jclouds.dynect.v3.filters.SessionManager; import org.jclouds.dynect.v3.filters.SessionManager;
import org.jclouds.dynect.v3.functions.ToRecordIds; import org.jclouds.dynect.v3.functions.ToRecordIds;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
@ -66,10 +65,8 @@ import com.google.common.util.concurrent.ListenableFuture;
* href="https://manage.dynect.net/help/docs/api2/rest/resources/AllRecord.html">doc</a> * href="https://manage.dynect.net/help/docs/api2/rest/resources/AllRecord.html">doc</a>
* @author Adrian Cole * @author Adrian Cole
*/ */
// required for all calls
@Produces(APPLICATION_JSON)
@Headers(keys = "API-Version", values = "{jclouds.api-version}") @Headers(keys = "API-Version", values = "{jclouds.api-version}")
@RequestFilters(SessionManager.class) @RequestFilters({ AlwaysAddContentType.class, SessionManager.class })
public interface RecordAsyncApi { public interface RecordAsyncApi {
/** /**

View File

@ -18,22 +18,21 @@
*/ */
package org.jclouds.dynect.v3.features; package org.jclouds.dynect.v3.features;
import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
import javax.inject.Named; import javax.inject.Named;
import javax.ws.rs.DELETE; import javax.ws.rs.DELETE;
import javax.ws.rs.GET; import javax.ws.rs.GET;
import javax.ws.rs.HeaderParam; import javax.ws.rs.HeaderParam;
import javax.ws.rs.POST; import javax.ws.rs.POST;
import javax.ws.rs.Path; import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import org.jclouds.dynect.v3.DynECTFallbacks.FalseOn400; import org.jclouds.dynect.v3.DynECTFallbacks.FalseOn400;
import org.jclouds.dynect.v3.domain.Session; import org.jclouds.dynect.v3.domain.Session;
import org.jclouds.dynect.v3.domain.SessionCredentials; import org.jclouds.dynect.v3.domain.SessionCredentials;
import org.jclouds.dynect.v3.filters.AlwaysAddContentType;
import org.jclouds.rest.annotations.BinderParam; import org.jclouds.rest.annotations.BinderParam;
import org.jclouds.rest.annotations.Fallback; import org.jclouds.rest.annotations.Fallback;
import org.jclouds.rest.annotations.Headers; import org.jclouds.rest.annotations.Headers;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.SelectJson; import org.jclouds.rest.annotations.SelectJson;
import org.jclouds.rest.binders.BindToJsonPayload; import org.jclouds.rest.binders.BindToJsonPayload;
@ -47,10 +46,9 @@ import com.google.common.util.concurrent.ListenableFuture;
* @see <a href="https://manage.dynect.net/help/docs/api2/rest/" /> * @see <a href="https://manage.dynect.net/help/docs/api2/rest/" />
* @author Adrian Cole * @author Adrian Cole
*/ */
// required for all calls
@Produces(APPLICATION_JSON)
@Headers(keys = "API-Version", values = "{jclouds.api-version}") @Headers(keys = "API-Version", values = "{jclouds.api-version}")
@Path("/Session") @Path("/Session")
@RequestFilters(AlwaysAddContentType.class)
public interface SessionAsyncApi { public interface SessionAsyncApi {
/** /**

View File

@ -31,12 +31,13 @@ import javax.ws.rs.PathParam;
import javax.ws.rs.Produces; import javax.ws.rs.Produces;
import org.jclouds.Fallbacks.NullOnNotFoundOr404; import org.jclouds.Fallbacks.NullOnNotFoundOr404;
import org.jclouds.dynect.v3.DynECTExceptions.TargetExistsException;
import org.jclouds.dynect.v3.DynECTExceptions.JobStillRunningException; import org.jclouds.dynect.v3.DynECTExceptions.JobStillRunningException;
import org.jclouds.dynect.v3.DynECTExceptions.TargetExistsException;
import org.jclouds.dynect.v3.domain.CreatePrimaryZone; import org.jclouds.dynect.v3.domain.CreatePrimaryZone;
import org.jclouds.dynect.v3.domain.CreatePrimaryZone.ToFQDN; import org.jclouds.dynect.v3.domain.CreatePrimaryZone.ToFQDN;
import org.jclouds.dynect.v3.domain.Job; import org.jclouds.dynect.v3.domain.Job;
import org.jclouds.dynect.v3.domain.Zone; import org.jclouds.dynect.v3.domain.Zone;
import org.jclouds.dynect.v3.filters.AlwaysAddContentType;
import org.jclouds.dynect.v3.filters.SessionManager; import org.jclouds.dynect.v3.filters.SessionManager;
import org.jclouds.dynect.v3.functions.ExtractZoneNames; import org.jclouds.dynect.v3.functions.ExtractZoneNames;
import org.jclouds.rest.annotations.BinderParam; import org.jclouds.rest.annotations.BinderParam;
@ -60,10 +61,8 @@ import com.google.common.util.concurrent.ListenableFuture;
* href="https://manage.dynect.net/help/docs/api2/rest/resources/Zone.html">doc</a> * href="https://manage.dynect.net/help/docs/api2/rest/resources/Zone.html">doc</a>
* @author Adrian Cole * @author Adrian Cole
*/ */
// required for all calls
@Produces(APPLICATION_JSON)
@Headers(keys = "API-Version", values = "{jclouds.api-version}") @Headers(keys = "API-Version", values = "{jclouds.api-version}")
@RequestFilters(SessionManager.class) @RequestFilters({ AlwaysAddContentType.class, SessionManager.class })
public interface ZoneAsyncApi { public interface ZoneAsyncApi {
/** /**
@ -102,6 +101,7 @@ public interface ZoneAsyncApi {
*/ */
@Named("CreatePrimaryZone") @Named("CreatePrimaryZone")
@POST @POST
@Produces(APPLICATION_JSON)
@Payload("%7B\"rname\":\"{contact}\",\"serial_style\":\"increment\",\"ttl\":3600%7D") @Payload("%7B\"rname\":\"{contact}\",\"serial_style\":\"increment\",\"ttl\":3600%7D")
@Path("/Zone/{fqdn}") @Path("/Zone/{fqdn}")
@SelectJson("data") @SelectJson("data")
@ -132,8 +132,9 @@ public interface ZoneAsyncApi {
*/ */
@Named("PublishZone") @Named("PublishZone")
@PUT @PUT
@Payload("{\"publish\":true}")
@Path("/Zone/{fqdn}") @Path("/Zone/{fqdn}")
@Produces(APPLICATION_JSON)
@Payload("{\"publish\":true}")
@SelectJson("data") @SelectJson("data")
ListenableFuture<Zone> publish(@PathParam("fqdn") String fqdn) throws JobStillRunningException; ListenableFuture<Zone> publish(@PathParam("fqdn") String fqdn) throws JobStillRunningException;
@ -143,6 +144,7 @@ public interface ZoneAsyncApi {
@Named("FreezeZone") @Named("FreezeZone")
@PUT @PUT
@Path("/Zone/{fqdn}") @Path("/Zone/{fqdn}")
@Produces(APPLICATION_JSON)
@Payload("{\"freeze\":true}") @Payload("{\"freeze\":true}")
@Consumes(APPLICATION_JSON) @Consumes(APPLICATION_JSON)
ListenableFuture<Job> freeze(@PathParam("fqdn") String fqdn) throws JobStillRunningException; ListenableFuture<Job> freeze(@PathParam("fqdn") String fqdn) throws JobStillRunningException;
@ -153,6 +155,7 @@ public interface ZoneAsyncApi {
@Named("ThawZone") @Named("ThawZone")
@PUT @PUT
@Path("/Zone/{fqdn}") @Path("/Zone/{fqdn}")
@Produces(APPLICATION_JSON)
@Payload("{\"thaw\":true}") @Payload("{\"thaw\":true}")
@Consumes(APPLICATION_JSON) @Consumes(APPLICATION_JSON)
ListenableFuture<Job> thaw(@PathParam("fqdn") String fqdn) throws JobStillRunningException; ListenableFuture<Job> thaw(@PathParam("fqdn") String fqdn) throws JobStillRunningException;

View File

@ -0,0 +1,42 @@
/**
* 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.dynect.v3.filters;
import static com.google.common.net.HttpHeaders.CONTENT_TYPE;
import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
import static org.jclouds.http.HttpRequest.NON_PAYLOAD_METHODS;
import org.jclouds.http.HttpException;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpRequestFilter;
/**
*
* DynECT requires Content-Type even on GET requests.
*
* @author Adrian Cole
*/
public final class AlwaysAddContentType implements HttpRequestFilter {
@Override
public HttpRequest filter(HttpRequest request) throws HttpException {
if (NON_PAYLOAD_METHODS.contains(request.getMethod()))
return request.toBuilder().replaceHeader(CONTENT_TYPE, APPLICATION_JSON).build();
return request;
}
}

View File

@ -56,7 +56,7 @@ public class GetJobRedirectionRetryHandler extends RedirectionRetryHandler {
if (location != null && location.indexOf("Job") != -1) { if (location != null && location.indexOf("Job") != -1) {
HttpRequest getRequest = command.getCurrentRequest().toBuilder() HttpRequest getRequest = command.getCurrentRequest().toBuilder()
.method("GET") .method("GET")
.payload(emptyPayload).build(); .payload((Payload) null).build();
command.setCurrentRequest(getRequest); command.setCurrentRequest(getRequest);
} }
return super.shouldRetryRequest(command, response); return super.shouldRetryRequest(command, response);

View File

@ -19,17 +19,16 @@
package org.jclouds.dynect.v3; package org.jclouds.dynect.v3;
import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor; import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor;
import static org.jclouds.Constants.PROPERTY_CONNECTION_TIMEOUT;
import static org.jclouds.Constants.PROPERTY_MAX_RETRIES; import static org.jclouds.Constants.PROPERTY_MAX_RETRIES;
import static org.jclouds.Constants.PROPERTY_SO_TIMEOUT;
import java.io.IOException; import java.io.IOException;
import java.util.Properties; import java.util.Properties;
import java.util.Set;
import org.jclouds.ContextBuilder; import org.jclouds.ContextBuilder;
import org.jclouds.concurrent.config.ExecutorServiceModule; import org.jclouds.concurrent.config.ExecutorServiceModule;
import org.jclouds.dynect.v3.DynECTExceptions.TargetExistsException;
import org.jclouds.dynect.v3.DynECTExceptions.JobStillRunningException; import org.jclouds.dynect.v3.DynECTExceptions.JobStillRunningException;
import org.jclouds.dynect.v3.DynECTExceptions.TargetExistsException;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
@ -44,17 +43,17 @@ import com.google.mockwebserver.MockWebServer;
@Test(singleThreaded = true) @Test(singleThreaded = true)
public class DynectApiMockTest { public class DynectApiMockTest {
private static final Set<Module> modules = ImmutableSet.<Module> of(
new ExecutorServiceModule(sameThreadExecutor(), sameThreadExecutor()));
static DynECTApi mockDynectApi(String uri) { static DynECTApi mockDynectApi(String uri) {
Properties overrides = new Properties(); Properties overrides = new Properties();
overrides.setProperty(PROPERTY_CONNECTION_TIMEOUT, "1000");
// prevent expect-100 bug http://code.google.com/p/mockwebserver/issues/detail?id=6
overrides.setProperty(PROPERTY_SO_TIMEOUT, "0");
overrides.setProperty(PROPERTY_MAX_RETRIES, "1"); overrides.setProperty(PROPERTY_MAX_RETRIES, "1");
return ContextBuilder.newBuilder("dynect") return ContextBuilder.newBuilder("dynect")
.credentials("jclouds:joe", "letmein") .credentials("jclouds:joe", "letmein")
.endpoint(uri) .endpoint(uri)
.overrides(overrides) .overrides(overrides)
.modules(ImmutableSet.<Module> of(new ExecutorServiceModule(sameThreadExecutor(), sameThreadExecutor()))) .modules(modules)
.build(DynECTApiMetadata.CONTEXT_TOKEN).getApi(); .build(DynECTApiMetadata.CONTEXT_TOKEN).getApi();
} }

View File

@ -18,6 +18,7 @@
*/ */
package org.jclouds.dynect.v3.features; package org.jclouds.dynect.v3.features;
import static com.google.common.net.HttpHeaders.CONTENT_TYPE;
import static javax.ws.rs.core.MediaType.APPLICATION_JSON; import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
import static org.jclouds.dynect.v3.domain.RecordId.recordIdBuilder; import static org.jclouds.dynect.v3.domain.RecordId.recordIdBuilder;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
@ -49,8 +50,8 @@ public class RecordApiExpectTest extends BaseDynECTApiExpectTest {
HttpRequest getSOA = HttpRequest.builder().method("GET") HttpRequest getSOA = HttpRequest.builder().method("GET")
.endpoint("https://api2.dynect.net/REST/SOARecord/adrianc.zone.dynecttest.jclouds.org/adrianc.zone.dynecttest.jclouds.org/50976579") .endpoint("https://api2.dynect.net/REST/SOARecord/adrianc.zone.dynecttest.jclouds.org/adrianc.zone.dynecttest.jclouds.org/50976579")
.addHeader("API-Version", "3.3.8") .addHeader("API-Version", "3.3.8")
.addHeader("Auth-Token", authToken) .addHeader(CONTENT_TYPE, APPLICATION_JSON)
.payload(emptyJsonPayload()).build(); .addHeader("Auth-Token", authToken).build();
HttpResponse soaResponse = HttpResponse.builder().statusCode(200) HttpResponse soaResponse = HttpResponse.builder().statusCode(200)
.payload(payloadFromResourceWithContentType("/get_record_soa.json", APPLICATION_JSON)).build(); .payload(payloadFromResourceWithContentType("/get_record_soa.json", APPLICATION_JSON)).build();
@ -75,8 +76,8 @@ public class RecordApiExpectTest extends BaseDynECTApiExpectTest {
HttpRequest getAAAA = HttpRequest.builder().method("GET") HttpRequest getAAAA = HttpRequest.builder().method("GET")
.endpoint("https://api2.dynect.net/REST/AAAARecord/adrianc.zone.dynecttest.jclouds.org/adrianc.zone.dynecttest.jclouds.org/50976579") .endpoint("https://api2.dynect.net/REST/AAAARecord/adrianc.zone.dynecttest.jclouds.org/adrianc.zone.dynecttest.jclouds.org/50976579")
.addHeader("API-Version", "3.3.8") .addHeader("API-Version", "3.3.8")
.addHeader("Auth-Token", authToken) .addHeader(CONTENT_TYPE, APPLICATION_JSON)
.payload(emptyJsonPayload()).build(); .addHeader("Auth-Token", authToken).build();
HttpResponse aaaaResponse = HttpResponse.builder().statusCode(200) HttpResponse aaaaResponse = HttpResponse.builder().statusCode(200)
.payload(payloadFromResourceWithContentType("/get_record_aaaa.json", APPLICATION_JSON)).build(); .payload(payloadFromResourceWithContentType("/get_record_aaaa.json", APPLICATION_JSON)).build();
@ -101,8 +102,8 @@ public class RecordApiExpectTest extends BaseDynECTApiExpectTest {
HttpRequest getA = HttpRequest.builder().method("GET") HttpRequest getA = HttpRequest.builder().method("GET")
.endpoint("https://api2.dynect.net/REST/ARecord/adrianc.zone.dynecttest.jclouds.org/adrianc.zone.dynecttest.jclouds.org/50976579") .endpoint("https://api2.dynect.net/REST/ARecord/adrianc.zone.dynecttest.jclouds.org/adrianc.zone.dynecttest.jclouds.org/50976579")
.addHeader("API-Version", "3.3.8") .addHeader("API-Version", "3.3.8")
.addHeader("Auth-Token", authToken) .addHeader(CONTENT_TYPE, APPLICATION_JSON)
.payload(emptyJsonPayload()).build(); .addHeader("Auth-Token", authToken).build();
HttpResponse aResponse = HttpResponse.builder().statusCode(200) HttpResponse aResponse = HttpResponse.builder().statusCode(200)
.payload(payloadFromResourceWithContentType("/get_record_a.json", APPLICATION_JSON)).build(); .payload(payloadFromResourceWithContentType("/get_record_a.json", APPLICATION_JSON)).build();
@ -127,8 +128,8 @@ public class RecordApiExpectTest extends BaseDynECTApiExpectTest {
HttpRequest getCNAME = HttpRequest.builder().method("GET") HttpRequest getCNAME = HttpRequest.builder().method("GET")
.endpoint("https://api2.dynect.net/REST/CNAMERecord/adrianc.zone.dynecttest.jclouds.org/adrianc.zone.dynecttest.jclouds.org/50976579") .endpoint("https://api2.dynect.net/REST/CNAMERecord/adrianc.zone.dynecttest.jclouds.org/adrianc.zone.dynecttest.jclouds.org/50976579")
.addHeader("API-Version", "3.3.8") .addHeader("API-Version", "3.3.8")
.addHeader("Auth-Token", authToken) .addHeader(CONTENT_TYPE, APPLICATION_JSON)
.payload(emptyJsonPayload()).build(); .addHeader("Auth-Token", authToken).build();
HttpResponse cnameResponse = HttpResponse.builder().statusCode(200) HttpResponse cnameResponse = HttpResponse.builder().statusCode(200)
.payload(payloadFromResourceWithContentType("/get_record_cname.json", APPLICATION_JSON)).build(); .payload(payloadFromResourceWithContentType("/get_record_cname.json", APPLICATION_JSON)).build();
@ -153,8 +154,8 @@ public class RecordApiExpectTest extends BaseDynECTApiExpectTest {
HttpRequest getMX = HttpRequest.builder().method("GET") HttpRequest getMX = HttpRequest.builder().method("GET")
.endpoint("https://api2.dynect.net/REST/MXRecord/adrianc.zone.dynecttest.jclouds.org/adrianc.zone.dynecttest.jclouds.org/50976579") .endpoint("https://api2.dynect.net/REST/MXRecord/adrianc.zone.dynecttest.jclouds.org/adrianc.zone.dynecttest.jclouds.org/50976579")
.addHeader("API-Version", "3.3.8") .addHeader("API-Version", "3.3.8")
.addHeader("Auth-Token", authToken) .addHeader(CONTENT_TYPE, APPLICATION_JSON)
.payload(emptyJsonPayload()).build(); .addHeader("Auth-Token", authToken).build();
HttpResponse mxResponse = HttpResponse.builder().statusCode(200) HttpResponse mxResponse = HttpResponse.builder().statusCode(200)
.payload(payloadFromResourceWithContentType("/get_record_mx.json", APPLICATION_JSON)).build(); .payload(payloadFromResourceWithContentType("/get_record_mx.json", APPLICATION_JSON)).build();
@ -179,8 +180,8 @@ public class RecordApiExpectTest extends BaseDynECTApiExpectTest {
HttpRequest getNS = HttpRequest.builder().method("GET") HttpRequest getNS = HttpRequest.builder().method("GET")
.endpoint("https://api2.dynect.net/REST/NSRecord/adrianc.zone.dynecttest.jclouds.org/adrianc.zone.dynecttest.jclouds.org/50976579") .endpoint("https://api2.dynect.net/REST/NSRecord/adrianc.zone.dynecttest.jclouds.org/adrianc.zone.dynecttest.jclouds.org/50976579")
.addHeader("API-Version", "3.3.8") .addHeader("API-Version", "3.3.8")
.addHeader("Auth-Token", authToken) .addHeader(CONTENT_TYPE, APPLICATION_JSON)
.payload(emptyJsonPayload()).build(); .addHeader("Auth-Token", authToken).build();
HttpResponse nsResponse = HttpResponse.builder().statusCode(200) HttpResponse nsResponse = HttpResponse.builder().statusCode(200)
.payload(payloadFromResourceWithContentType("/get_record_ns.json", APPLICATION_JSON)).build(); .payload(payloadFromResourceWithContentType("/get_record_ns.json", APPLICATION_JSON)).build();
@ -205,8 +206,8 @@ public class RecordApiExpectTest extends BaseDynECTApiExpectTest {
HttpRequest getPTR = HttpRequest.builder().method("GET") HttpRequest getPTR = HttpRequest.builder().method("GET")
.endpoint("https://api2.dynect.net/REST/PTRRecord/adrianc.zone.dynecttest.jclouds.org/adrianc.zone.dynecttest.jclouds.org/50976579") .endpoint("https://api2.dynect.net/REST/PTRRecord/adrianc.zone.dynecttest.jclouds.org/adrianc.zone.dynecttest.jclouds.org/50976579")
.addHeader("API-Version", "3.3.8") .addHeader("API-Version", "3.3.8")
.addHeader("Auth-Token", authToken) .addHeader(CONTENT_TYPE, APPLICATION_JSON)
.payload(emptyJsonPayload()).build(); .addHeader("Auth-Token", authToken).build();
HttpResponse ptrResponse = HttpResponse.builder().statusCode(200) HttpResponse ptrResponse = HttpResponse.builder().statusCode(200)
.payload(payloadFromResourceWithContentType("/get_record_ptr.json", APPLICATION_JSON)).build(); .payload(payloadFromResourceWithContentType("/get_record_ptr.json", APPLICATION_JSON)).build();
@ -242,8 +243,8 @@ public class RecordApiExpectTest extends BaseDynECTApiExpectTest {
HttpRequest getSRV = HttpRequest.builder().method("GET") HttpRequest getSRV = HttpRequest.builder().method("GET")
.endpoint("https://api2.dynect.net/REST/SRVRecord/adrianc.zone.dynecttest.jclouds.org/adrianc.zone.dynecttest.jclouds.org/50976579") .endpoint("https://api2.dynect.net/REST/SRVRecord/adrianc.zone.dynecttest.jclouds.org/adrianc.zone.dynecttest.jclouds.org/50976579")
.addHeader("API-Version", "3.3.8") .addHeader("API-Version", "3.3.8")
.addHeader("Auth-Token", authToken) .addHeader(CONTENT_TYPE, APPLICATION_JSON)
.payload(emptyJsonPayload()).build(); .addHeader("Auth-Token", authToken).build();
HttpResponse srvResponse = HttpResponse.builder().statusCode(200) HttpResponse srvResponse = HttpResponse.builder().statusCode(200)
.payload(payloadFromResourceWithContentType("/get_record_srv.json", APPLICATION_JSON)).build(); .payload(payloadFromResourceWithContentType("/get_record_srv.json", APPLICATION_JSON)).build();
@ -263,8 +264,8 @@ public class RecordApiExpectTest extends BaseDynECTApiExpectTest {
HttpRequest getTXT = HttpRequest.builder().method("GET") HttpRequest getTXT = HttpRequest.builder().method("GET")
.endpoint("https://api2.dynect.net/REST/TXTRecord/adrianc.zone.dynecttest.jclouds.org/adrianc.zone.dynecttest.jclouds.org/50976579") .endpoint("https://api2.dynect.net/REST/TXTRecord/adrianc.zone.dynecttest.jclouds.org/adrianc.zone.dynecttest.jclouds.org/50976579")
.addHeader("API-Version", "3.3.8") .addHeader("API-Version", "3.3.8")
.addHeader("Auth-Token", authToken) .addHeader(CONTENT_TYPE, APPLICATION_JSON)
.payload(emptyJsonPayload()).build(); .addHeader("Auth-Token", authToken).build();
HttpResponse txtResponse = HttpResponse.builder().statusCode(200) HttpResponse txtResponse = HttpResponse.builder().statusCode(200)
.payload(payloadFromResourceWithContentType("/get_record_txt.json", APPLICATION_JSON)).build(); .payload(payloadFromResourceWithContentType("/get_record_txt.json", APPLICATION_JSON)).build();
@ -289,8 +290,8 @@ public class RecordApiExpectTest extends BaseDynECTApiExpectTest {
HttpRequest list = HttpRequest.builder().method("GET") HttpRequest list = HttpRequest.builder().method("GET")
.endpoint("https://api2.dynect.net/REST/AllRecord/adrianc.zone.dynecttest.jclouds.org") .endpoint("https://api2.dynect.net/REST/AllRecord/adrianc.zone.dynecttest.jclouds.org")
.addHeader("API-Version", "3.3.8") .addHeader("API-Version", "3.3.8")
.addHeader("Auth-Token", authToken) .addHeader(CONTENT_TYPE, APPLICATION_JSON)
.payload(emptyJsonPayload()).build(); .addHeader("Auth-Token", authToken).build();
HttpResponse listResponse = HttpResponse.builder().statusCode(200) HttpResponse listResponse = HttpResponse.builder().statusCode(200)
.payload(payloadFromResourceWithContentType("/list_records.json", APPLICATION_JSON)).build(); .payload(payloadFromResourceWithContentType("/list_records.json", APPLICATION_JSON)).build();

View File

@ -18,6 +18,7 @@
*/ */
package org.jclouds.dynect.v3.features; package org.jclouds.dynect.v3.features;
import static com.google.common.net.HttpHeaders.CONTENT_TYPE;
import static javax.ws.rs.core.MediaType.APPLICATION_JSON; import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertFalse;
@ -49,9 +50,8 @@ public class SessionApiExpectTest extends BaseDynECTApiExpectTest {
HttpRequest isValid = HttpRequest.builder().method("GET") HttpRequest isValid = HttpRequest.builder().method("GET")
.endpoint("https://api2.dynect.net/REST/Session") .endpoint("https://api2.dynect.net/REST/Session")
.addHeader("API-Version", "3.3.8") .addHeader("API-Version", "3.3.8")
.addHeader("Auth-Token", authToken) .addHeader(CONTENT_TYPE, APPLICATION_JSON)
.payload(emptyJsonPayload()) .addHeader("Auth-Token", authToken).build();
.build();
HttpResponse validResponse = HttpResponse.builder().statusCode(200) HttpResponse validResponse = HttpResponse.builder().statusCode(200)
.payload(payloadFromResourceWithContentType("/session_valid.json", APPLICATION_JSON)).build(); .payload(payloadFromResourceWithContentType("/session_valid.json", APPLICATION_JSON)).build();
@ -72,9 +72,8 @@ public class SessionApiExpectTest extends BaseDynECTApiExpectTest {
HttpRequest logout = HttpRequest.builder().method("DELETE") HttpRequest logout = HttpRequest.builder().method("DELETE")
.endpoint("https://api2.dynect.net/REST/Session") .endpoint("https://api2.dynect.net/REST/Session")
.addHeader("API-Version", "3.3.8") .addHeader("API-Version", "3.3.8")
.addHeader("Auth-Token", authToken) .addHeader(CONTENT_TYPE, APPLICATION_JSON)
.payload(emptyJsonPayload()) .addHeader("Auth-Token", authToken).build();
.build();
HttpResponse logoutResponse = HttpResponse.builder().statusCode(200) HttpResponse logoutResponse = HttpResponse.builder().statusCode(200)
.payload(payloadFromResourceWithContentType("/logout.json", APPLICATION_JSON)).build(); .payload(payloadFromResourceWithContentType("/logout.json", APPLICATION_JSON)).build();

View File

@ -19,6 +19,7 @@
package org.jclouds.dynect.v3.features; package org.jclouds.dynect.v3.features;
import static com.google.common.net.HttpHeaders.ACCEPT; import static com.google.common.net.HttpHeaders.ACCEPT;
import static com.google.common.net.HttpHeaders.CONTENT_TYPE;
import static javax.ws.rs.core.MediaType.APPLICATION_JSON; import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNull; import static org.testng.Assert.assertNull;
@ -42,9 +43,8 @@ public class ZoneApiExpectTest extends BaseDynECTApiExpectTest {
HttpRequest get = HttpRequest.builder().method("GET") HttpRequest get = HttpRequest.builder().method("GET")
.endpoint("https://api2.dynect.net/REST/Zone/jclouds.org") .endpoint("https://api2.dynect.net/REST/Zone/jclouds.org")
.addHeader("API-Version", "3.3.8") .addHeader("API-Version", "3.3.8")
.addHeader("Auth-Token", authToken) .addHeader(CONTENT_TYPE, APPLICATION_JSON)
.payload(emptyJsonPayload()) .addHeader("Auth-Token", authToken).build();
.build();
HttpResponse getResponse = HttpResponse.builder().statusCode(200) HttpResponse getResponse = HttpResponse.builder().statusCode(200)
.payload(payloadFromResourceWithContentType("/get_zone.json", APPLICATION_JSON)).build(); .payload(payloadFromResourceWithContentType("/get_zone.json", APPLICATION_JSON)).build();
@ -85,9 +85,8 @@ public class ZoneApiExpectTest extends BaseDynECTApiExpectTest {
HttpRequest list = HttpRequest.builder().method("GET") HttpRequest list = HttpRequest.builder().method("GET")
.endpoint("https://api2.dynect.net/REST/Zone") .endpoint("https://api2.dynect.net/REST/Zone")
.addHeader("API-Version", "3.3.8") .addHeader("API-Version", "3.3.8")
.addHeader("Auth-Token", authToken) .addHeader(CONTENT_TYPE, APPLICATION_JSON)
.payload(emptyJsonPayload()) .addHeader("Auth-Token", authToken).build();
.build();
HttpResponse listResponse = HttpResponse.builder().statusCode(200) HttpResponse listResponse = HttpResponse.builder().statusCode(200)
.payload(payloadFromResourceWithContentType("/list_zones.json", APPLICATION_JSON)).build(); .payload(payloadFromResourceWithContentType("/list_zones.json", APPLICATION_JSON)).build();
@ -102,9 +101,8 @@ public class ZoneApiExpectTest extends BaseDynECTApiExpectTest {
.endpoint("https://api2.dynect.net/REST/ZoneChanges/jclouds.org") .endpoint("https://api2.dynect.net/REST/ZoneChanges/jclouds.org")
.addHeader("API-Version", "3.3.8") .addHeader("API-Version", "3.3.8")
.addHeader(ACCEPT, APPLICATION_JSON) .addHeader(ACCEPT, APPLICATION_JSON)
.addHeader("Auth-Token", authToken) .addHeader(CONTENT_TYPE, APPLICATION_JSON)
.payload(emptyJsonPayload()) .addHeader("Auth-Token", authToken).build();
.build();
HttpResponse deleteChangesResponse = HttpResponse.builder().statusCode(200) HttpResponse deleteChangesResponse = HttpResponse.builder().statusCode(200)
.payload(payloadFromResourceWithContentType("/delete_zone_changes.json", APPLICATION_JSON)).build(); .payload(payloadFromResourceWithContentType("/delete_zone_changes.json", APPLICATION_JSON)).build();
@ -119,9 +117,8 @@ public class ZoneApiExpectTest extends BaseDynECTApiExpectTest {
.endpoint("https://api2.dynect.net/REST/Zone/jclouds.org") .endpoint("https://api2.dynect.net/REST/Zone/jclouds.org")
.addHeader("API-Version", "3.3.8") .addHeader("API-Version", "3.3.8")
.addHeader(ACCEPT, APPLICATION_JSON) .addHeader(ACCEPT, APPLICATION_JSON)
.addHeader("Auth-Token", authToken) .addHeader(CONTENT_TYPE, APPLICATION_JSON)
.payload(emptyJsonPayload()) .addHeader("Auth-Token", authToken).build();
.build();
HttpResponse deleteResponse = HttpResponse.builder().statusCode(200) HttpResponse deleteResponse = HttpResponse.builder().statusCode(200)
.payload(payloadFromResourceWithContentType("/delete_zone.json", APPLICATION_JSON)).build(); .payload(payloadFromResourceWithContentType("/delete_zone.json", APPLICATION_JSON)).build();

View File

@ -19,6 +19,7 @@
package org.jclouds.dynect.v3.handlers; package org.jclouds.dynect.v3.handlers;
import static com.google.common.net.HttpHeaders.ACCEPT; import static com.google.common.net.HttpHeaders.ACCEPT;
import static com.google.common.net.HttpHeaders.CONTENT_TYPE;
import static com.google.common.net.HttpHeaders.LOCATION; import static com.google.common.net.HttpHeaders.LOCATION;
import static javax.ws.rs.core.MediaType.APPLICATION_JSON; import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
@ -54,9 +55,8 @@ public class GetJobRedirectionRetryHandlerExpectTest extends BaseDynECTApiExpect
.endpoint("https://api2.dynect.net/REST/Job/1234") .endpoint("https://api2.dynect.net/REST/Job/1234")
.addHeader("API-Version", "3.3.8") .addHeader("API-Version", "3.3.8")
.addHeader(ACCEPT, APPLICATION_JSON) .addHeader(ACCEPT, APPLICATION_JSON)
.addHeader("Auth-Token", authToken) .addHeader(CONTENT_TYPE, APPLICATION_JSON)
.payload(emptyJsonPayload()) .addHeader("Auth-Token", authToken).build();
.build();
HttpResponse success = HttpResponse.builder().statusCode(200) HttpResponse success = HttpResponse.builder().statusCode(200)
.payload(payloadFromResourceWithContentType("/delete_zone.json", APPLICATION_JSON)).build(); .payload(payloadFromResourceWithContentType("/delete_zone.json", APPLICATION_JSON)).build();

View File

@ -57,12 +57,6 @@ public class BaseDynECTExpectTest<T> extends BaseRestApiExpectTest<T> {
} }
} }
public static Payload emptyJsonPayload() {
Payload p = Payloads.newByteArrayPayload(new byte[] {});
p.getContentMetadata().setContentType(APPLICATION_JSON);
return p;
}
public static Payload stringPayload(String json) { public static Payload stringPayload(String json) {
Payload p = Payloads.newPayload(json); Payload p = Payloads.newPayload(json);
p.getContentMetadata().setContentType(APPLICATION_JSON); p.getContentMetadata().setContentType(APPLICATION_JSON);