@@ -90,9 +90,9 @@ public String getApiUrl() {
9090 for (GatewayTypeMapping mapping : mappings ) {
9191 apiConfigAdapter .registerSubtype ((Class )mapping .getApiType (), mapping .getName ());
9292 }
93-
93+ //2014-09-12T03:00:17Z
9494 GSON = new GsonBuilder ()
95- .setDateFormat ("yyyy-MM-dd'T'HH:mm:ss'Z'" )
95+ .setDateFormat ("yyyy-MM-dd'T'HH:mm:ss.SSS 'Z'" )
9696 .excludeFieldsWithoutExposeAnnotation ()
9797 .registerTypeAdapterFactory (apiConfigAdapter )
9898 .setFieldNamingPolicy (FieldNamingPolicy .IDENTITY )
@@ -332,12 +332,44 @@ private BillForwardResponse makeURLConnectionRequest(RequestMethod method, Strin
332332 }
333333 }
334334
335- public <T > APIResponse <T > request (RequestMethod method , String url , T obj , Type responseType ) throws AuthenticationException ,
336- InvalidRequestException ,
337- APIConnectionException ,
338- CardException ,
339- APIException {
340335
336+
337+ public <TRequest , TResponse > TResponse requestUntyped (RequestMethod method , String url , TRequest obj , Type responseType ) throws AuthenticationException ,
338+ InvalidRequestException ,
339+ APIConnectionException ,
340+ CardException ,
341+ APIException {
342+ url = String .format ("%s/%s" , apiUrl , url );
343+ String originalDNSCacheTTL = null ;
344+ Boolean allowedToSetTTL = true ;
345+ try {
346+ originalDNSCacheTTL = java .security .Security .getProperty (DNS_CACHE_TTL_PROPERTY_NAME );
347+ // disable DNS cache
348+ java .security .Security .setProperty (DNS_CACHE_TTL_PROPERTY_NAME , "0" );
349+ } catch (SecurityException se ) {
350+ allowedToSetTTL = false ;
351+ }
352+
353+ try {
354+ return _requestUntyped (responseType , method , url , obj , apiKey );
355+ } finally {
356+ if (allowedToSetTTL ) {
357+ if (originalDNSCacheTTL == null ) {
358+ // value unspecified by implementation
359+ // DNS_CACHE_TTL_PROPERTY_NAME of -1 = cache forever
360+ java .security .Security .setProperty (DNS_CACHE_TTL_PROPERTY_NAME , "-1" );
361+ } else {
362+ java .security .Security .setProperty (DNS_CACHE_TTL_PROPERTY_NAME , originalDNSCacheTTL );
363+ }
364+ }
365+ }
366+ }
367+
368+ public <T > APIResponse <T > request (RequestMethod method , String url , T obj , Type responseType ) throws AuthenticationException ,
369+ InvalidRequestException ,
370+ APIConnectionException ,
371+ CardException ,
372+ APIException {
341373 url = String .format ("%s/%s" , apiUrl , url );
342374 String originalDNSCacheTTL = null ;
343375 Boolean allowedToSetTTL = true ;
@@ -364,6 +396,36 @@ public <T> APIResponse<T> request(RequestMethod method, String url, T obj, Type
364396 }
365397 }
366398
399+
400+ protected <TRequest , TResponse > TResponse _requestUntyped (Type responseType , RequestMethod method , String url , TRequest obj , String apiKey ) throws AuthenticationException ,
401+ InvalidRequestException , APIConnectionException , CardException ,
402+ APIException {
403+ if ((apiKey == null || apiKey .length () == 0 ) && (apiKey == null || apiKey .length () == 0 )) {
404+ throw new AuthenticationException (
405+ "No API key provided. (HINT: set your API key using 'BillForward.apiKey = <API-KEY>'. "
406+ + "You can generate API keys from the BillForward web interface. "
407+ + "See https://BillForward.com/api for details or email support@BillForward.com if you have questions." );
408+ }
409+
410+ String query = "" ;
411+ if (obj != null ) {
412+ query = GSON .toJson (obj );
413+ }
414+
415+ BillForwardResponse response = makeURLConnectionRequest (method , url , query , apiKey );
416+ int rCode = response .getResponseCode ();
417+ String rBody = response .getResponseBody ();
418+ if (rCode < 200 || rCode >= 300 ) {
419+ handleAPIError (rBody , rCode );
420+ }
421+
422+
423+ TResponse acc = GSON .fromJson (rBody , responseType );
424+ return acc ;
425+ }
426+
427+
428+
367429 protected <T > APIResponse <T > _request (Type responseType , RequestMethod method , String url , T obj , String apiKey ) throws AuthenticationException ,
368430 InvalidRequestException , APIConnectionException , CardException ,
369431 APIException {
0 commit comments