@@ -25,13 +25,13 @@ of this software and associated documentation files (the "Software"), to deal
2525package de .tu_dortmund .ub .data .dswarm ;
2626
2727import java .io .File ;
28- import java .io .StringWriter ;
2928import java .util .Properties ;
3029import java .util .concurrent .Callable ;
3130
3231import javax .json .Json ;
3332import javax .json .JsonReader ;
3433
34+ import de .tu_dortmund .ub .data .util .TPUUtil ;
3535import org .apache .commons .io .IOUtils ;
3636import org .apache .http .HttpEntity ;
3737import org .apache .http .client .methods .CloseableHttpResponse ;
@@ -43,7 +43,6 @@ of this software and associated documentation files (the "Software"), to deal
4343import org .apache .http .entity .mime .content .StringBody ;
4444import org .apache .http .impl .client .CloseableHttpClient ;
4545import org .apache .http .impl .client .HttpClients ;
46- import org .apache .http .util .EntityUtils ;
4746import org .slf4j .Logger ;
4847import org .slf4j .LoggerFactory ;
4948
@@ -95,9 +94,6 @@ public String call() {
9594 final String dataModelID = this .dataModelID ;
9695 final String updateResourceID = resourceID ;
9796
98- // init process values
99- final String message = null ;
100-
10197 try {
10298 // build a InputDataModel for the resource
10399 final String name = String .format ("resource for project '%s'" , resource );
@@ -129,14 +125,18 @@ public String call() {
129125
130126 // no need to clean up resources or datamodels anymore
131127
128+ LOG .info (String .format ("[%s] Finished 'Ingest (Task)' no. '%d' ..." , serviceName , cnt ));
129+
130+ return null ;
132131 } catch (final Exception e ) {
133132
134- LOG . error ( String .format ("[%s] Processing resource '%s' failed with a %s" , serviceName , resource , e . getClass (). getSimpleName ()), e );
135- }
133+ final String message = String .format ("[%s] Processing resource '%s' failed with a %s" , serviceName , resource ,
134+ e . getClass (). getSimpleName ());
136135
137- LOG .info ( String . format ( "[%s] Finished 'Ingest (Task)' no. '%d' ..." , serviceName , cnt ) );
136+ LOG .error ( message , e );
138137
139- return message ;
138+ throw new RuntimeException (message , e );
139+ }
140140 }
141141
142142 /**
@@ -178,6 +178,10 @@ private String updateDataModelContent(final String inputDataModelID, final Strin
178178 default : {
179179
180180 LOG .error (message );
181+
182+ final String response = TPUUtil .getResponseMessage (httpResponse );
183+
184+ throw new Exception ("something went wrong at data model export: " + message + " " + response );
181185 }
182186 }
183187 }
@@ -227,36 +231,30 @@ private String uploadFileAndUpdateResource(final String resourceUUID, final Stri
227231 try (final CloseableHttpResponse httpResponse = httpclient .execute (httpPut )) {
228232
229233 final int statusCode = httpResponse .getStatusLine ().getStatusCode ();
230- final HttpEntity httpEntity = httpResponse .getEntity ();
231234
232235 final String message = String .format ("[%s] %d : %s" , serviceName , statusCode , httpResponse .getStatusLine ()
233236 .getReasonPhrase ());
234237
238+ final String response = TPUUtil .getResponseMessage (httpResponse );
239+
235240 switch (statusCode ) {
236241
237242 case 200 : {
238243
239244 LOG .info (message );
240- final StringWriter writer = new StringWriter ();
241- IOUtils .copy (httpEntity .getContent (), writer , APIStatics .UTF_8 );
242- final String responseJson = writer .toString ();
243- writer .flush ();
244- writer .close ();
245245
246- LOG .debug (String .format ("[%s] responseJson : %s" , serviceName , responseJson ));
246+ LOG .debug (String .format ("[%s] responseJson : %s" , serviceName , response ));
247247
248- return responseJson ;
248+ return response ;
249249 }
250250 default : {
251251
252252 LOG .error (message );
253+
254+ throw new Exception ("something went wrong at data model export: " + message + " " + response );
253255 }
254256 }
255-
256- EntityUtils .consume (httpEntity );
257257 }
258258 }
259-
260- return null ;
261259 }
262260}
0 commit comments