2424import com .google .gson .internal .LazilyParsedNumber ;
2525import com .ibm .cloud .sdk .core .http .HttpConfigOptions ;
2626import com .ibm .cloud .sdk .core .http .HttpMediaType ;
27+ import com .ibm .cloud .sdk .core .http .Response ;
2728import com .ibm .cloud .sdk .core .security .Authenticator ;
2829import com .ibm .cloud .sdk .core .security .BasicAuthenticator ;
2930import com .ibm .cloud .sdk .core .security .BearerTokenAuthenticator ;
3738import com .ibm .watson .discovery .query .Operator ;
3839import com .ibm .watson .discovery .v1 .model .*;
3940import com .ibm .watson .discovery .v1 .model .NormalizationOperation .Operation ;
41+
42+ import java .awt .*;
4043import java .io .ByteArrayInputStream ;
4144import java .io .FileInputStream ;
4245import java .io .FileNotFoundException ;
@@ -2134,7 +2137,21 @@ private Configuration createTestConfig() {
21342137 }
21352138
21362139 private Collection createCollection (CreateCollectionOptions createOptions ) {
2137- Collection createResponse = discovery .createCollection (createOptions ).execute ().getResult ();
2140+
2141+ Collection createResponse = null ;
2142+ try {
2143+ // In a successful case, you can grab the ID with the following code.
2144+ Response <Collection > collectionResponse = discovery .createCollection (createOptions ).execute ();
2145+ createResponse = collectionResponse .getResult ();
2146+
2147+ String transactionId = collectionResponse .getHeaders ().values ("x-global-transaction-id" ).get (0 );
2148+ System .out .println ("x-global-transcation-id: " +transactionId );
2149+ } catch (ServiceResponseException e ) {
2150+ // This is how you get the ID from a failed request.
2151+ // Make sure to use the ServiceResponseException class or one of its subclasses!
2152+ String transactionId = e .getHeaders ().values ("x-global-transaction-id" ).get (0 );
2153+ System .out .println ("x-global-transcation-id: " +transactionId );
2154+ }
21382155 collectionIds .add (createResponse .getCollectionId ());
21392156 return createResponse ;
21402157 }
@@ -2179,7 +2196,7 @@ private DocumentAccepted createTestDocument(String json, String filename, String
21792196 DocumentAccepted createResponse = discovery .addDocument (builder .build ()).execute ().getResult ();
21802197 WaitFor .Condition documentAccepted =
21812198 new WaitForDocumentAccepted (environmentId , collectionId , createResponse .getDocumentId ());
2182- WaitFor .waitFor (documentAccepted , 5 , TimeUnit .SECONDS , 500 );
2199+ WaitFor .waitFor (documentAccepted , 10 , TimeUnit .SECONDS , 500 );
21832200 return createResponse ;
21842201 }
21852202
@@ -2205,7 +2222,7 @@ private synchronized String setupTestDocuments() {
22052222
22062223 WaitFor .Condition collectionAvailable =
22072224 new WaitForCollectionAvailable (environmentId , collectionId );
2208- WaitFor .waitFor (collectionAvailable , 5 , TimeUnit .SECONDS , 500 );
2225+ WaitFor .waitFor (collectionAvailable , 10 , TimeUnit .SECONDS , 500 );
22092226
22102227 return collectionId ;
22112228 }
0 commit comments