1818import Energistics .Etp .v12 .Datatypes .*;
1919import Energistics .Etp .v12 .Datatypes .DataArrayTypes .DataArray ;
2020import Energistics .Etp .v12 .Datatypes .Object .ContextScopeKind ;
21- import Energistics .Etp .v12 .Protocol .DataArray .PutDataArrays ;
2221import Energistics .Etp .v12 .Protocol .DataArray .PutDataArraysResponse ;
22+ import Energistics .Etp .v12 .Protocol .Dataspace .GetDataspaces ;
2323import com .geosiris .etp .communication .ClientInfo ;
2424import com .geosiris .etp .communication .ConnectionType ;
2525import com .geosiris .etp .communication .ETPConnection ;
2626import com .geosiris .etp .communication .Message ;
2727import com .geosiris .etp .protocols .CommunicationProtocol ;
2828import com .geosiris .etp .protocols .ProtocolHandler ;
29- import com .geosiris .etp .protocols .handlers .generated .*;
29+ import com .geosiris .etp .protocols .handlers .generated .CoreHandler_DefaultPrinter ;
30+ import com .geosiris .etp .protocols .handlers .generated .DataArrayHandler_DefaultPrinter ;
31+ import com .geosiris .etp .protocols .handlers .generated .DiscoveryHandler_DefaultPrinter ;
32+ import com .geosiris .etp .protocols .handlers .generated .StoreHandler_DefaultPrinter ;
3033import com .geosiris .etp .utils .ETPHelper ;
3134import com .geosiris .etp .utils .ETPHelperREST ;
3235import com .geosiris .etp .utils .ETPUri ;
4043import java .io .ObjectOutputStream ;
4144import java .util .*;
4245
46+ import static com .geosiris .etp .utils .ETPHelperREST .getResources ;
47+
4348public class Main {
4449 public static Logger logger = LogManager .getLogger (Main .class );
4550 public static String file1 = "<?xml version=\" 1.0\" encoding=\" UTF-8\" standalone=\" yes\" ?>"
@@ -66,9 +71,23 @@ public static void main(String[] args) throws Exception {
6671// test_big_messagePUTREST(args);
6772// test_get_big_data_array_REST(args);
6873// putDA_REST(args);
69- putDA_split (args );
74+ // putDA_split(args);
75+ test_external_server (args );
7076 }
7177
78+ public static void test_external_server (String [] args ) throws Exception {
79+ HashMap <String , String > map = new HashMap <>();
80+ map .put ("data-partition-id" , "osdu" );
81+
82+ ETPClient client = getClient (1 <<22 , args , map );
83+ logger .info (ETPHelper .sendGetRessources_pretty (client , 1 , ContextScopeKind .sourcesOrSelf , 5000 ));
84+ // long msg_id = client.send(new GetDataspaces());
85+ // for(Message msg: client.getEtpClientSession().waitForResponse(msg_id, 5000)){
86+ // logger.info(msg);
87+ // }
88+
89+ client .closeClient ();
90+ }
7291
7392 public static void putDA_REST (String [] args ) throws Exception {
7493 AnyArray aa_points = ETPHelper .constructArray (List .of (0 ,1 ,2 ,3 ,4 ,5 ));
@@ -106,10 +125,8 @@ public static void putDA_split(String[] args) throws Exception {
106125 logger .info ("{}" , ETPHelperREST .getMultipleDataArrays (args [0 ], uri , List .of (pathInRes )));
107126 }
108127
109-
110-
111128 public static void test_get_resources (String [] args ) throws Exception {
112- logger .info (ETPHelperREST . getResources (args [0 ], new ETPUri ("volve-eqn-plus" ).toString (), ContextScopeKind .self ));
129+ logger .info (getResources (args [0 ], new ETPUri ("volve-eqn-plus" ).toString (), ContextScopeKind .self ));
113130 }
114131
115132 public static void test_get_dataspaces (String [] args ) throws Exception {
@@ -356,10 +373,15 @@ public static ETPClient getClient(String[] args){
356373 }
357374
358375 public static ETPClient getClient (Integer maxMsgSize , String [] args ){
376+ return getClient (maxMsgSize , args , new HashMap <>());
377+ }
378+
379+ public static ETPClient getClient (Integer maxMsgSize , String [] args , Map <String , String > headers ){
380+ ETPClient etpClient = null ;
359381 logger .info ("Usage : java -jar myfile.jar [SERVER_URL] [LOGIN] [PASSWORD]" );
360382
361383 HttpURI etpServerUri = null ;
362- String login = "" ;
384+ String loginOrToken = "" ;
363385 String password = "" ;
364386
365387 if (args .length > 0 ) {
@@ -371,7 +393,7 @@ public static ETPClient getClient(Integer maxMsgSize, String[] args){
371393 }
372394 if (args .length > 1 ) {
373395 try {
374- login = args [1 ];
396+ loginOrToken = args [1 ];
375397 } catch (Exception e ) {
376398 e .printStackTrace ();
377399 }
@@ -382,9 +404,20 @@ public static ETPClient getClient(Integer maxMsgSize, String[] args){
382404 } catch (Exception e ) {
383405 e .printStackTrace ();
384406 }
407+ etpClient = ETPClient .getInstanceWithAuth_Basic (etpServerUri , getConnection (etpServerUri ), 2000 , loginOrToken , password , maxMsgSize , headers );
408+ }else {
409+ etpClient = ETPClient .getInstanceWithAuth_Token (etpServerUri , getConnection (etpServerUri ), 2000 , loginOrToken , maxMsgSize , headers );
385410 }
411+
412+ logger .info (etpServerUri );
413+
414+ return etpClient ;
415+ }
416+
417+ public static ETPConnection getConnection (HttpURI etpServerUri ){
386418 Map <CharSequence , DataValue > mapCaps = new HashMap <>();
387419
420+
388421 ServerCapabilities caps = new ServerCapabilities ();
389422 caps .setEndpointCapabilities (mapCaps );
390423
@@ -400,12 +433,7 @@ public static ETPClient getClient(Integer maxMsgSize, String[] args){
400433// .setContactInformation(Contact.newBuilder().setContactEmail("").setContactName("Val").setContactPhone("").build())
401434// .build();
402435
403- ETPConnection etpConnection = new ETPConnection (ConnectionType .CLIENT , caps , clientInfo , protocolHandlers );
404-
405- ETPClient etpClient = ETPClient .getInstanceWithAuth_Basic (etpServerUri , etpConnection , 2000 , login , password , maxMsgSize );
406- logger .info (etpServerUri );
407-
408- return etpClient ;
436+ return new ETPConnection (ConnectionType .CLIENT , caps , clientInfo , protocolHandlers );
409437 }
410438
411439 public static void etpClientTest2 (String args []) {
0 commit comments