2121import org .apache .http .client .methods .HttpDelete ;
2222import org .apache .http .client .methods .HttpGet ;
2323import org .apache .http .client .methods .HttpPost ;
24+ import org .apache .http .client .methods .HttpPut ;
2425import org .apache .http .entity .BufferedHttpEntity ;
2526import org .apache .http .entity .ContentType ;
2627import org .apache .http .entity .StringEntity ;
3334/**
3435 * ResponseHandler Clase mediante la cual se hacen las peticiones y
3536 * des-serializaciones de respuestas.
37+ *
3638 * @param <T> IResponse subclasses
3739 * @author Juan Gamez
3840 * @version 0.0.0.1
@@ -46,11 +48,12 @@ public abstract class ResponseHandler<T> {
4648
4749 /**
4850 * Este método realiza un HTTP POST con la configuracion enviada.
49- * @param url String url o host.
50- * @param path String path
51- * @param headers Map String String con headers.
52- * @param jsonBody String body
53- * @param configHTTP RequestConfig objeto de configuración.
51+ *
52+ * @param url String url o host.
53+ * @param path String path
54+ * @param headers Map String String con headers.
55+ * @param jsonBody String body
56+ * @param configHTTP RequestConfig objeto de configuración.
5457 * @param contentClass Clase de respuesta esperada.
5558 * @return T
5659 */
@@ -117,12 +120,14 @@ public T postHTTPJson(String url, String path, Map<String, String> headers, Stri
117120 }
118121
119122 /**
120- * Este método realiza un HTTP POST (modo Multipart form data) con la configuracion enviada.
121- * @param url String url o host.
122- * @param path String path.
123- * @param headers Map String String con headers.
124- * @param body String formato Multipart con body a enviar.
125- * @param configHTTP RequestConfig objeto de configuración.
123+ * Este método realiza un HTTP POST (modo Multipart form data) con la
124+ * configuracion enviada.
125+ *
126+ * @param url String url o host.
127+ * @param path String path.
128+ * @param headers Map String String con headers.
129+ * @param body String formato Multipart con body a enviar.
130+ * @param configHTTP RequestConfig objeto de configuración.
126131 * @param contentClass Clase esperada de respuesta.
127132 * @return T
128133 */
@@ -150,7 +155,7 @@ public T postHTTPMultipart(String url, String path, Map<String, String> headers,
150155 Future <HttpResponse > future = client .execute (request , null );
151156 HttpResponse response = future .get (MAX_EXECUTION_TIME , TimeUnit .MINUTES );
152157 if (response .getStatusLine () != null
153- && response .getStatusLine ().getStatusCode () < HttpStatus .SC_INTERNAL_SERVER_ERROR ) {
158+ && response .getStatusLine ().getStatusCode () < HttpStatus .SC_INTERNAL_SERVER_ERROR ) {
154159 HttpEntity responseEntity = response .getEntity ();
155160 String responseBody = new String ();
156161 if (responseEntity != null ) {
@@ -159,13 +164,15 @@ public T postHTTPMultipart(String url, String path, Map<String, String> headers,
159164 } else {
160165 throw new GeneralException (
161166 response .getStatusLine () != null
162- ? response .getStatusLine ().getStatusCode () : HttpStatus .SC_UNPROCESSABLE_ENTITY ,
167+ ? response .getStatusLine ().getStatusCode ()
168+ : HttpStatus .SC_UNPROCESSABLE_ENTITY ,
163169 "Can´t get body from the request made." );
164170 }
165171 } else {
166172 throw new GeneralException (
167173 response .getStatusLine () != null
168- ? response .getStatusLine ().getStatusCode () : HttpStatus .SC_INTERNAL_SERVER_ERROR ,
174+ ? response .getStatusLine ().getStatusCode ()
175+ : HttpStatus .SC_INTERNAL_SERVER_ERROR ,
169176 "Error > 500 calling the service." );
170177 }
171178 } catch (IllegalArgumentException e ) {
@@ -195,10 +202,11 @@ public T postHTTPMultipart(String url, String path, Map<String, String> headers,
195202
196203 /**
197204 * Este método realiza un HTTP GET con la configuracion enviada.
198- * @param url String url o host.
199- * @param path String path.
200- * @param headers Map String String con headers.
201- * @param configHTTP RequestConfig objeto de configuración.
205+ *
206+ * @param url String url o host.
207+ * @param path String path.
208+ * @param headers Map String String con headers.
209+ * @param configHTTP RequestConfig objeto de configuración.
202210 * @param contentClass Clase esperada de respuesta.
203211 * @return T
204212 */
@@ -219,7 +227,7 @@ public T getHTTP(String url, String path, Map<String, String> headers, RequestCo
219227 Future <HttpResponse > future = client .execute (request , null );
220228 HttpResponse response = future .get (MAX_EXECUTION_TIME , TimeUnit .MINUTES );
221229 if (response .getStatusLine () != null
222- && response .getStatusLine ().getStatusCode () < HttpStatus .SC_INTERNAL_SERVER_ERROR ) {
230+ && response .getStatusLine ().getStatusCode () < HttpStatus .SC_INTERNAL_SERVER_ERROR ) {
223231 HttpEntity responseEntity = response .getEntity ();
224232 String responseBody = new String ();
225233 if (responseEntity != null ) {
@@ -228,13 +236,15 @@ public T getHTTP(String url, String path, Map<String, String> headers, RequestCo
228236 } else {
229237 throw new GeneralException (
230238 response .getStatusLine () != null
231- ? response .getStatusLine ().getStatusCode () : HttpStatus .SC_UNPROCESSABLE_ENTITY ,
239+ ? response .getStatusLine ().getStatusCode ()
240+ : HttpStatus .SC_UNPROCESSABLE_ENTITY ,
232241 "Can´t get body from the request made." );
233242 }
234243 } else {
235244 throw new GeneralException (
236245 response .getStatusLine () != null
237- ? response .getStatusLine ().getStatusCode () : HttpStatus .SC_INTERNAL_SERVER_ERROR ,
246+ ? response .getStatusLine ().getStatusCode ()
247+ : HttpStatus .SC_INTERNAL_SERVER_ERROR ,
238248 "Error > 500 calling the service." );
239249 }
240250 } catch (IllegalArgumentException e ) {
@@ -264,10 +274,11 @@ public T getHTTP(String url, String path, Map<String, String> headers, RequestCo
264274
265275 /**
266276 * Este método realiza un HTTP DELTE con la configuracion enviada.
267- * @param url String url o host.
268- * @param path String path.
269- * @param headers Map String String con headers.
270- * @param configHTTP RequestConfig objeto de configuración.
277+ *
278+ * @param url String url o host.
279+ * @param path String path.
280+ * @param headers Map String String con headers.
281+ * @param configHTTP RequestConfig objeto de configuración.
271282 * @param contentClass Clase esperada de respuesta.
272283 * @return T
273284 */
@@ -288,7 +299,7 @@ public T deleteHTTP(String url, String path, Map<String, String> headers, Reques
288299 Future <HttpResponse > future = client .execute (request , null );
289300 HttpResponse response = future .get (MAX_EXECUTION_TIME , TimeUnit .MINUTES );
290301 if (response .getStatusLine () != null
291- && response .getStatusLine ().getStatusCode () < HttpStatus .SC_INTERNAL_SERVER_ERROR ) {
302+ && response .getStatusLine ().getStatusCode () < HttpStatus .SC_INTERNAL_SERVER_ERROR ) {
292303 HttpEntity responseEntity = response .getEntity ();
293304 String responseBody = new String ();
294305 if (responseEntity != null ) {
@@ -297,13 +308,15 @@ public T deleteHTTP(String url, String path, Map<String, String> headers, Reques
297308 } else {
298309 throw new GeneralException (
299310 response .getStatusLine () != null
300- ? response .getStatusLine ().getStatusCode () : HttpStatus .SC_UNPROCESSABLE_ENTITY ,
311+ ? response .getStatusLine ().getStatusCode ()
312+ : HttpStatus .SC_UNPROCESSABLE_ENTITY ,
301313 "Can´t get body from the request made." );
302314 }
303315 } else {
304316 throw new GeneralException (
305317 response .getStatusLine () != null
306- ? response .getStatusLine ().getStatusCode () : HttpStatus .SC_INTERNAL_SERVER_ERROR ,
318+ ? response .getStatusLine ().getStatusCode ()
319+ : HttpStatus .SC_INTERNAL_SERVER_ERROR ,
307320 "Error > 500 calling the service." );
308321 }
309322 } catch (IllegalArgumentException e ) {
@@ -333,11 +346,12 @@ public T deleteHTTP(String url, String path, Map<String, String> headers, Reques
333346
334347 /**
335348 * Este método realiza una deserializacion de un JSON al tipo de clase T.
349+ *
336350 * @param json String json.
337351 * @param contentClass Clase esperada de respuesta.
338352 * @return T
339353 * @throws JsonSyntaxException en caso de error.
340- * @throws ServicesException en caso de json vacío (Errores 404 o similar).
354+ * @throws ServicesException en caso de json vacío (Errores 404 o similar).
341355 */
342356 public T deserialize (String json , Class <T > contentClass ) throws JsonSyntaxException , ServicesException {
343357 if (json == null || json .isEmpty ()) {
0 commit comments