Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OKBJavaConnector/AdministrationService/src/administrationservice/Main.java @ 9674

Last change on this file since 9674 was 6157, checked in by bfarka, 14 years ago

added ecj and custom statistics to communicate with the okb services #1441

File size: 4.3 KB
Line 
1/*
2 * To change this template, choose Tools | Templates
3 * and open the template in the editor.
4 */
5
6package administrationservice;
7
8import com.heuristiclab.services.administration.AdministrationService;
9import com.heuristiclab.services.administration.Algorithm;
10import com.heuristiclab.services.administration.ArrayOfAlgorithm;
11import com.heuristiclab.services.administration.ArrayOfPlatform;
12import com.heuristiclab.services.administration.IAdministrationService;
13import com.heuristiclab.services.administration.ObjectFactory;
14import com.heuristiclab.services.administration.Platform;
15import java.net.MalformedURLException;
16import java.net.URL;
17import java.security.KeyManagementException;
18import java.security.NoSuchAlgorithmException;
19import java.util.logging.Level;
20import java.util.logging.Logger;
21import javax.net.ssl.HttpsURLConnection;
22import javax.net.ssl.SSLContext;
23import javax.net.ssl.TrustManager;
24import javax.net.ssl.X509TrustManager;
25import javax.xml.bind.JAXBElement;
26
27/**
28 *
29 * @author MartinH
30 */
31public class Main {
32
33
34      static {
35    // Create a trust manager that does not validate certificate chains
36    TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
37      public java.security.cert.X509Certificate[] getAcceptedIssuers() {
38        return new java.security.cert.X509Certificate[] {};
39      }
40
41      public void checkClientTrusted(
42          java.security.cert.X509Certificate[] certs, String authType) {
43      }
44
45      public void checkServerTrusted(
46          java.security.cert.X509Certificate[] certs, String authType) {
47      }
48    } };
49
50    SSLContext sc;
51    try {
52      sc = SSLContext.getInstance("SSL");
53      sc.init(null, trustAllCerts, new java.security.SecureRandom());
54      HttpsURLConnection
55          .setDefaultSSLSocketFactory(sc.getSocketFactory());
56    } catch (NoSuchAlgorithmException e) {
57      throw new RuntimeException(e);
58    } catch (KeyManagementException e) {
59      throw new RuntimeException(e);
60    }
61
62  }
63
64  public void GetAlgorithmsTest(IAdministrationService port) {
65
66    ArrayOfAlgorithm algos = port.getAlgorithms();
67
68
69    for (Algorithm algo : algos.getAlgorithm()) {
70      System.out.println("algo ClassId:=" + algo.getAlgorithmClassId());
71      System.out.println("algo Id:=" + algo.getId());
72      System.out.println("algo PlattformId:=" + algo.getPlatformId());
73      System.out.println("algo Class:=" + algo.getClass());
74      System.out.println("algo Description:="
75          + algo.getDescription().getValue());
76      System.out.println("algo Name:=" + algo.getName().getValue());
77    }
78    //assertTrue("No Algorithms found!", algos.getAlgorithm().size() > 0);
79  }
80
81  public void GetPlatformsTest(IAdministrationService port) {
82
83    ArrayOfPlatform algos = port.getPlatforms();
84
85    for (Platform platform : algos.getPlatform()) {
86      System.out.println("platform Id:=" + platform.getId());
87      System.out.println("platform Class:=" + platform.getClass());
88      System.out.println("platform Description:="
89          + platform.getDescription().getValue());
90      System.out.println("platform Name:=" + platform.getName().getValue());
91    }
92    //assertTrue("No Platforms found!", algos.getPlatform().size() > 0);
93  }
94
95  public void AddPlatformsTest(IAdministrationService port) {
96                Long retval = 0L;
97                ObjectFactory fac = new ObjectFactory();
98                Platform p = fac.createPlatform();
99                p.setName(fac.createNamedOKBItemName("ECJ"));
100                p.setDescription(fac.createNamedOKBItemDescription("A Java-based Evolutionary Computation Research System"));
101
102
103                try {
104                    retval = port.addPlatform(p);
105                } catch (Exception e) {
106                    e.printStackTrace();
107                }
108
109                System.out.println("adding of Platform "+(retval>0?"sucessful":"failed"));
110  }
111
112
113    /**
114     * @param args the command line arguments
115     */
116    public static void main(String[] args) {
117        try {
118            Main test = new Main();
119            AdministrationService srv = new AdministrationService(new URL("https://services.heuristiclab.com/OKB.SPR.Java-3.3/AdministrationService.svc?wsdl"));
120            IAdministrationService port = srv.getAdministrationService();
121            test.GetAlgorithmsTest(port);
122            test.AddPlatformsTest(port);
123            test.GetPlatformsTest(port);
124        } catch (MalformedURLException ex) {
125            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
126        }
127    }
128
129}
Note: See TracBrowser for help on using the repository browser.