Changeset 5242 for branches/OKBJavaConnector/HLOKBWebClient/src
- Timestamp:
- 01/08/11 12:21:05 (14 years ago)
- Location:
- branches/OKBJavaConnector/HLOKBWebClient/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/OKBJavaConnector/HLOKBWebClient/src/main/java/at/hl/okb/wsclient/OKBServiceClient.java
r5233 r5242 3 3 import static at.hl.okb.wsclient.Utilities.createNameFilter; 4 4 5 import java.security.KeyManagementException; 6 import java.security.NoSuchAlgorithmException; 7 import java.util.ArrayList; 8 import java.util.HashMap; 9 import java.util.List; 10 import java.util.Map; 11 12 import javax.net.ssl.HttpsURLConnection; 13 import javax.net.ssl.SSLContext; 14 import javax.net.ssl.TrustManager; 15 import javax.net.ssl.X509TrustManager; 5 import java.util.Iterator; 16 6 17 7 import at.hl.wsclient.okb.Algorithm; 18 import at.hl.wsclient.okb.AlgorithmParameter; 19 import at.hl.wsclient.okb.ArrayOfAlgorithm; 20 import at.hl.wsclient.okb.ArrayOfAlgorithmParameter; 21 import at.hl.wsclient.okb.ArrayOfProblem; 8 import at.hl.wsclient.okb.AlgorithmClass; 22 9 import at.hl.wsclient.okb.IOKBService; 10 import at.hl.wsclient.okb.NamedOKBItem; 23 11 import at.hl.wsclient.okb.OKBService; 24 12 import at.hl.wsclient.okb.ObjectFactory; 25 13 import at.hl.wsclient.okb.Platform; 26 14 import at.hl.wsclient.okb.Problem; 15 import at.hl.wsclient.okb.ProblemClass; 27 16 28 17 import com.google.common.collect.Iterables; … … 31 20 OKBService srv = null; 32 21 IOKBService port = null; 33 34 // hack for allowing self signed certificates 35 static { 36 // Create a trust manager that does not validate certificate chains 37 TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() { 38 public java.security.cert.X509Certificate[] getAcceptedIssuers() { 39 return new java.security.cert.X509Certificate[] {}; 40 } 41 42 public void checkClientTrusted( 43 java.security.cert.X509Certificate[] certs, String authType) { 44 } 45 46 public void checkServerTrusted( 47 java.security.cert.X509Certificate[] certs, String authType) { 48 } 49 } }; 50 51 SSLContext sc; 52 try { 53 sc = SSLContext.getInstance("SSL"); 54 sc.init(null, trustAllCerts, new java.security.SecureRandom()); 55 HttpsURLConnection 56 .setDefaultSSLSocketFactory(sc.getSocketFactory()); 57 } catch (NoSuchAlgorithmException e) { 58 throw new RuntimeException(e); 59 } catch (KeyManagementException e) { 60 throw new RuntimeException(e); 61 } 62 63 } 22 ObjectFactory factory = new ObjectFactory(); 64 23 65 24 public OKBServiceClient() { … … 71 30 Platform returnValue = Iterables.find( 72 31 port.getPlatforms().getPlatform(), 73 createNameFilter(platformName)); 74 if (returnValue == null) 75 createPlatform(platformName); 32 createNameFilter(platformName), null); 76 33 77 returnValue = Iterables.find(port.getPlatforms().getPlatform(), 78 createNameFilter(platformName)); 34 return returnValue.getId(); 35 } 36 37 public Long getProblemClassId(String problemClass) { 38 ProblemClass returnValue = Iterables.find(port.getProblemClasses() 39 .getProblemClass(), createNameFilter(problemClass), null); 40 79 41 return returnValue.getId(); 80 42 81 43 } 82 44 83 private void createPlatform(String name) { 45 public Long getAlgorithmClassId(String algorithmClassName) { 46 AlgorithmClass returnValue = Iterables.find(port.getAlgorithmClasses() 47 .getAlgorithmClass(), createNameFilter(algorithmClassName), 48 null); 84 49 85 ObjectFactory factory = new ObjectFactory(); 86 Platform platform = factory.createPlatform(); 87 88 platform.setName(factory.createNamedOKBItemName(name)); 89 port.addPlatform(platform); 90 } 91 92 public Long getAlgorithmId(String algorithmName) { 93 Long algorithmId = null; 94 95 ArrayOfAlgorithm allAlgorithms = port.getAlgorithms(); 96 for (Algorithm algo : allAlgorithms.getAlgorithm()) { 97 if (algo.getName().getValue() == algorithmName) { 98 algorithmId = algo.getId(); 99 } 100 } 101 return algorithmId; 102 } 103 104 public Long getProblemId(String problemName) { 105 Long problemId = null; 106 107 ArrayOfProblem allProblems = port.getProblems(); 108 for (Problem problem : allProblems.getProblem()) { 109 if (problem.getName().getValue() == problemName) { 110 problemId = problem.getId(); 111 } 112 } 113 return problemId; 114 } 115 116 public void checkAlgoParamsExists(Long algorithmId, 117 Map<String, Object> ecjAlgoParams) { 118 119 List<String> missingParams = new ArrayList<String>(); 120 121 ArrayOfAlgorithmParameter hlAlgoParams = port 122 .getAlgorithmParameters(algorithmId); 123 Map<String, Object> hlAlgoParamMap = new HashMap<String, Object>(); 124 125 for (AlgorithmParameter algoParam : hlAlgoParams 126 .getAlgorithmParameter()) { 127 hlAlgoParamMap.put(algoParam.getName().getValue(), null); // value 128 // hangs 129 // on 130 // Experiments 131 } 132 133 String[] ecjparamNames = (String[]) ecjAlgoParams.keySet().toArray(); 134 135 for (int i = 0; i < ecjparamNames.length; i++) { 136 if (!hlAlgoParamMap.containsKey(ecjparamNames[i])) { 137 missingParams.add(new String(ecjparamNames[i])); 138 } 139 } 50 return returnValue.getId(); 140 51 141 52 } 142 53 54 public Long getProblem(String problemName, Long problemClassId, 55 Long platformId) { 56 Problem problem = null; 57 Iterator<Problem> it = port.getProblems().getProblem().iterator(); 58 59 while (it.hasNext() && problem == null) { 60 Problem tmpProblem = it.next(); 61 if (platformId.equals(tmpProblem.getPlatformId()) 62 && problemName.equals(tmpProblem.getName().getValue()) 63 && problemClassId.equals(tmpProblem.getProblemClassId())) { 64 65 66 67 problem = tmpProblem; 68 } 69 } 70 return problem.getId(); 71 } 72 73 74 public Long getAlgorithm(String algorithmName, Long algorithmClassId, 75 Long platformId) { 76 Algorithm algorithm = null; 77 Iterator<Algorithm> it = port.getAlgorithms().getAlgorithm().iterator(); 78 79 while (it.hasNext() && algorithm == null) { 80 Algorithm tmpAlgo = it.next(); 81 if (platformId.equals(tmpAlgo.getPlatformId()) 82 && algorithmName.equals(tmpAlgo.getName().getValue()) 83 && algorithmClassId.equals(tmpAlgo.getAlgorithmClassId())) { 84 algorithm = tmpAlgo; 85 } 86 } 87 return algorithm.getId(); 88 } 89 90 91 private <T extends NamedOKBItem> T createNamedOKBItem(Class<T> clazz, 92 String name) { 93 try { 94 T instance = clazz.newInstance(); 95 instance.setName(factory.createNamedOKBItemName(name)); 96 return instance; 97 } catch (IllegalAccessException ex) { 98 throw new IllegalArgumentException(ex); 99 } catch (InstantiationException ex) { 100 throw new IllegalArgumentException(ex); 101 } 102 } 103 143 104 } -
branches/OKBJavaConnector/HLOKBWebClient/src/main/java/at/hl/okb/wsclient/Utilities.java
r5229 r5242 2 2 3 3 import at.hl.wsclient.okb.NamedOKBItem; 4 import at.hl.wsclient.okb.Problem; 4 5 5 6 import com.google.common.base.Predicate; … … 22 23 } 23 24 25 26 private static class ProblemFilter implements Predicate<Problem> 27 { 28 private final String problemName; 29 private final String problemClass; 30 31 public ProblemFilter(String problemName, String problemClass) 32 { 33 this.problemClass = problemClass; 34 this.problemName = problemName; 35 } 36 37 @Override 38 public boolean apply(Problem input) { 39 // TODO Auto-generated method stub 40 return false; 41 } 42 } 43 44 24 45 public static Predicate<NamedOKBItem> createNameFilter(String name) 25 46 { -
branches/OKBJavaConnector/HLOKBWebClient/src/test/java/at/hl/okb/wsclient/OKBClientTest.java
r5229 r5242 1 1 package at.hl.okb.wsclient; 2 2 3 4 import junit.framework.Assert; 3 5 4 6 import org.junit.Test; … … 15 17 public void testGetPlatform() 16 18 { 17 client.getPlatformId("ECJ");19 Assert.assertNotNull(client.getPlatformId("ECJ")); 18 20 } 19 21 22 @Test 23 public void testGetProblemClass() 24 { 25 Assert.assertNotNull(client.getProblemClassId("ECJ")); 26 } 27 @Test 28 public void testGetAlgorithmClass() 29 { 30 Assert.assertNotNull(client.getAlgorithmClassId("ECJ")); 31 } 32 20 33 }
Note: See TracChangeset
for help on using the changeset viewer.