[6062] | 1 | /* |
---|
| 2 | * To change this template, choose Tools | Templates |
---|
| 3 | * and open the template in the editor. |
---|
| 4 | */ |
---|
| 5 | |
---|
| 6 | package administrationservice; |
---|
| 7 | |
---|
| 8 | import com.heuristiclab.services.administration.AdministrationService; |
---|
| 9 | import com.heuristiclab.services.administration.Algorithm; |
---|
| 10 | import com.heuristiclab.services.administration.ArrayOfAlgorithm; |
---|
| 11 | import com.heuristiclab.services.administration.ArrayOfPlatform; |
---|
| 12 | import com.heuristiclab.services.administration.IAdministrationService; |
---|
[6085] | 13 | import com.heuristiclab.services.administration.ObjectFactory; |
---|
[6062] | 14 | import com.heuristiclab.services.administration.Platform; |
---|
| 15 | import java.net.MalformedURLException; |
---|
| 16 | import java.net.URL; |
---|
| 17 | import java.security.KeyManagementException; |
---|
| 18 | import java.security.NoSuchAlgorithmException; |
---|
| 19 | import java.util.logging.Level; |
---|
| 20 | import java.util.logging.Logger; |
---|
| 21 | import javax.net.ssl.HttpsURLConnection; |
---|
| 22 | import javax.net.ssl.SSLContext; |
---|
| 23 | import javax.net.ssl.TrustManager; |
---|
| 24 | import javax.net.ssl.X509TrustManager; |
---|
[6085] | 25 | import javax.xml.bind.JAXBElement; |
---|
[6062] | 26 | |
---|
| 27 | /** |
---|
| 28 | * |
---|
| 29 | * @author MartinH |
---|
| 30 | */ |
---|
| 31 | public 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 | |
---|
[6085] | 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")); |
---|
[6062] | 101 | |
---|
[6085] | 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 | |
---|
[6062] | 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); |
---|
[6085] | 122 | test.AddPlatformsTest(port); |
---|
[6062] | 123 | test.GetPlatformsTest(port); |
---|
| 124 | } catch (MalformedURLException ex) { |
---|
| 125 | Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); |
---|
| 126 | } |
---|
| 127 | } |
---|
| 128 | |
---|
| 129 | } |
---|