diff --git a/README.md b/README.md index 34304326..08fc3ea0 100644 --- a/README.md +++ b/README.md @@ -196,7 +196,7 @@ FlightOfferSearch[] flightOffersSearches = amadeus.shopping.flightOffersSearch.p // Retrieve a flight order FlightOrder order = amadeus.booking.flightOrder("eJzTd9f3NjIJdzUGAAp%2fAiY=").get(); // Cancel a flight order -FlightOrder order = amadeus.booking.flightOrder("eJzTd9f3NjIJdzUGAAp%2fAiY=").delete(); +Response order = amadeus.booking.flightOrder("eJzTd9f3NjIJdzUGAAp%2fAiY=").delete(); // Flight Offers price FlightPrice[] flightPricing = amadeus.shopping.flightOffersSearch.pricing.post( diff --git a/src/main/java/com/amadeus/Response.java b/src/main/java/com/amadeus/Response.java index a99965be..ce817a97 100644 --- a/src/main/java/com/amadeus/Response.java +++ b/src/main/java/com/amadeus/Response.java @@ -1,6 +1,5 @@ package com.amadeus; -import com.amadeus.Constants; import com.amadeus.exceptions.AuthenticationException; import com.amadeus.exceptions.ClientException; import com.amadeus.exceptions.NotFoundException; @@ -61,7 +60,9 @@ protected Response(Request request) { // Tries to parse the raw response from the request. protected void parse(HTTPClient client) { parseStatusCode(); - parseData(client); + if (this.statusCode != 204) { + parseData(client); + } } // Detects of any exceptions have occured and throws the appropriate exceptions. @@ -75,6 +76,8 @@ protected void detectError(HTTPClient client) throws ResponseException { exception = new AuthenticationException(this); } else if (statusCode >= 400) { exception = new ClientException(this); + } else if (statusCode == 204) { + return; } else if (!parsed) { exception = new ParserException(this); } diff --git a/src/main/java/com/amadeus/booking/FlightOrder.java b/src/main/java/com/amadeus/booking/FlightOrder.java index 8065f7d5..b236a5e4 100644 --- a/src/main/java/com/amadeus/booking/FlightOrder.java +++ b/src/main/java/com/amadeus/booking/FlightOrder.java @@ -53,7 +53,7 @@ public com.amadeus.resources.FlightOrder get(Params params) throws ResponseExcep String path = String.format("/v1/booking/flight-orders/%s", flightOfferId); Response response = client.get(path, params); return (com.amadeus.resources.FlightOrder) Resource.fromObject( - response, com.amadeus.resources.FlightOrder.class); + response, com.amadeus.resources.FlightOrder.class); } /** @@ -72,7 +72,7 @@ public com.amadeus.resources.FlightOrder get() throws ResponseException { *
* *- * FlightOrder order = amadeus.booking.flightOrder.( + * Response order = amadeus.booking.flightOrder.( * "eJzTd9f3NjIJdzUGAAp%2fAiY=").delete(); ** @param params the parameters to send to the API @@ -80,18 +80,17 @@ public com.amadeus.resources.FlightOrder get() throws ResponseException { * @throws ResponseException when an exception occurs */ - public com.amadeus.resources.FlightOrder delete(Params params) throws ResponseException { + public Response delete(Params params) throws ResponseException { String path = String.format("/v1/booking/flight-orders/%s", flightOfferId); Response response = client.delete(path, params); - return (com.amadeus.resources.FlightOrder) Resource.fromObject( - response, com.amadeus.resources.FlightOrder.class); + return response; } - + /** * Convenience method for calling
delete
without any parameters.
* @see com.amadeus.booking.FlightOrder#delete()
*/
- public com.amadeus.resources.FlightOrder delete() throws ResponseException {
+ public Response delete() throws ResponseException {
return delete(null);
}
-}
+}
\ No newline at end of file
diff --git a/src/test/java/com/amadeus/ResponseTest.java b/src/test/java/com/amadeus/ResponseTest.java
index 7035937f..c265bb31 100644
--- a/src/test/java/com/amadeus/ResponseTest.java
+++ b/src/test/java/com/amadeus/ResponseTest.java
@@ -107,6 +107,22 @@ public class ResponseTest {
assertNull(response.getData());
}
+ @Test public void testNoContent() throws IOException {
+ when(connection.getResponseCode()).thenReturn(204);
+ when(connection.getHeaderField("Content-Type")).thenReturn(
+ "application/json");
+ when(connection.getInputStream()).thenReturn(
+ new ByteArrayInputStream("".getBytes()));
+
+ response.parse(client);
+
+ assertEquals(response.getStatusCode(), 204);
+ assertEquals(response.getBody(), null);
+ assertFalse(response.isParsed());
+ assertNull(response.getResult());
+ assertNull(response.getData());
+ }
+
@Test public void testEmptyConnection() throws IOException {
InputStream stream = mock(ByteArrayInputStream.class);
when(connection.getResponseCode()).thenThrow(new IOException());
@@ -212,6 +228,16 @@ public void detectParserException() throws ResponseException, IOException {
response.detectError(client);
}
+ @Test public void detectNoExceptionNoContent() throws ResponseException, IOException {
+ when(connection.getResponseCode()).thenReturn(204);
+ when(connection.getHeaderField("Content-Type")).thenReturn(
+ "application/json");
+ when(connection.getInputStream()).thenReturn(
+ new ByteArrayInputStream("{}".getBytes()));
+ response.parse(client);
+ response.detectError(client);
+ }
+
@Test public void testToString() {
assertTrue(response.toString().startsWith("Response("));
}