airavata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lah...@apache.org
Subject svn commit: r1382945 - in /incubator/airavata/trunk/modules/commons/registry-api/src/main/java/org/apache/airavata/registry/api: AiravataRegistry2.java util/RegistryUtils.java
Date Mon, 10 Sep 2012 15:33:50 GMT
Author: lahiru
Date: Mon Sep 10 15:33:49 2012
New Revision: 1382945

URL: http://svn.apache.org/viewvc?rev=1382945&view=rev
Log:
adding Util method to registry.

Added:
    incubator/airavata/trunk/modules/commons/registry-api/src/main/java/org/apache/airavata/registry/api/util/RegistryUtils.java
Modified:
    incubator/airavata/trunk/modules/commons/registry-api/src/main/java/org/apache/airavata/registry/api/AiravataRegistry2.java

Modified: incubator/airavata/trunk/modules/commons/registry-api/src/main/java/org/apache/airavata/registry/api/AiravataRegistry2.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/commons/registry-api/src/main/java/org/apache/airavata/registry/api/AiravataRegistry2.java?rev=1382945&r1=1382944&r2=1382945&view=diff
==============================================================================
--- incubator/airavata/trunk/modules/commons/registry-api/src/main/java/org/apache/airavata/registry/api/AiravataRegistry2.java
(original)
+++ incubator/airavata/trunk/modules/commons/registry-api/src/main/java/org/apache/airavata/registry/api/AiravataRegistry2.java
Mon Sep 10 15:33:49 2012
@@ -52,5 +52,7 @@ public abstract class AiravataRegistry2 
 	public void setUser(AiravataUser user) {
 		this.user = user;
 	}
+
+    public abstract void closeConnection();
 	
 }

Added: incubator/airavata/trunk/modules/commons/registry-api/src/main/java/org/apache/airavata/registry/api/util/RegistryUtils.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/commons/registry-api/src/main/java/org/apache/airavata/registry/api/util/RegistryUtils.java?rev=1382945&view=auto
==============================================================================
--- incubator/airavata/trunk/modules/commons/registry-api/src/main/java/org/apache/airavata/registry/api/util/RegistryUtils.java
(added)
+++ incubator/airavata/trunk/modules/commons/registry-api/src/main/java/org/apache/airavata/registry/api/util/RegistryUtils.java
Mon Sep 10 15:33:49 2012
@@ -0,0 +1,129 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+*/
+package org.apache.airavata.registry.api.util;
+
+import org.apache.airavata.common.exception.AiravataConfigurationException;
+import org.apache.airavata.common.registry.api.exception.RegistryException;
+import org.apache.airavata.registry.api.AiravataRegistry2;
+import org.apache.airavata.registry.api.AiravataRegistryFactory;
+import org.apache.airavata.registry.api.AiravataUser;
+import org.apache.airavata.registry.api.Gateway;
+import org.apache.airavata.registry.api.exception.RegistryAccessorInstantiateException;
+import org.apache.airavata.registry.api.exception.RegistryAccessorInvalidException;
+import org.apache.airavata.registry.api.exception.RegistryAccessorNotFoundException;
+import org.apache.airavata.registry.api.exception.RegistryAccessorUndefinedException;
+import org.apache.airavata.registry.api.impl.AiravataJCRRegistry;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.jcr.Repository;
+import javax.jcr.RepositoryException;
+import java.io.IOException;
+import java.net.*;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+public class RegistryUtils {
+    private static final Logger log = LoggerFactory.getLogger(RegistryUtils.class);
+
+    public static final String GATEWAY_ID = "gateway.id";
+
+    public static final String REGISTRY_USER = "registry.user";
+
+    public static final String REPOSITORY_PROPERTIES = "repository.properties";
+
+    public static String validateAxisService(String urlString)throws RegistryException {
+        if(!urlString.endsWith("?wsdl")){
+            urlString = urlString + "?wsdl";
+        }
+        try {
+            URL url = new URL(urlString);
+            URLConnection conn = url.openConnection();
+            conn.connect();
+        } catch (MalformedURLException e) {
+            // the URL is not in a valid form
+            throw new RegistryException("Given Axis2 Service URL : " + urlString + " is Invalid",e);
+        } catch (IOException e) {
+            // the connection couldn't be established
+            throw new RegistryException("Given Axis2 Service URL : " + urlString + " is Invalid",e);
+        }
+        return  urlString;
+    }
+    public static String validateURL(String urlString)throws RegistryException{
+        try {
+            URL url = new URL(urlString);
+            URLConnection conn = url.openConnection();
+            conn.connect();
+        } catch (MalformedURLException e) {
+            // the URL is not in a valid form
+            throw new RegistryException("Given URL: " + urlString + " is Invalid",e);
+        } catch (IOException e) {
+            // the connection couldn't be established
+            throw new RegistryException("Given URL: " + urlString + " is Invalid",e);
+        }
+        return  urlString;
+    }
+    public static boolean validateRegistryCredentials(String userName,String password,String
url)throws RegistryException{
+        HashMap<String, String> map = new HashMap<String, String>();
+        map.put("org.apache.jackrabbit.repository.uri", url);
+        try {
+            AiravataJCRRegistry airavataJCRRegistry = new AiravataJCRRegistry(new URI(url),
"org.apache.jackrabbit.rmi.repository.RmiRepositoryFactory", userName, password, map);
+            airavataJCRRegistry.saveGFacDescriptor("dummy");
+//            airavataJCRRegistry.deleteGFacDescriptor("dummy");
+        } catch (Exception e) {
+            throw new RegistryException("Check the properties file for JCR Registry Configuration",e);
+        }
+        return true;
+    }
+
+    public static AiravataRegistry2 getRegistryFromConfig(URL url) {
+        String username = "";
+        Properties properties = new Properties();
+        AiravataRegistry2 registry = null;
+        try {
+            properties.load(url.openStream());
+            if (properties.get(REGISTRY_USER) != null) {
+                username = (String) properties.get(REGISTRY_USER);
+            }
+        } catch (MalformedURLException e) {
+            e.printStackTrace();
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+        try {
+            registry = AiravataRegistryFactory.getRegistry(new Gateway((String) properties.get(GATEWAY_ID)),
+                    new AiravataUser(username));
+        } catch (AiravataConfigurationException e) {
+            log.error("Error initializing AiravataRegistry2");
+        } catch (RegistryAccessorNotFoundException e) {
+            log.error("Error initializing AiravataRegistry2");
+        } catch (RegistryAccessorInstantiateException e) {
+            log.error("Error initializing AiravataRegistry2");
+        } catch (RegistryAccessorInvalidException e) {
+            log.error("Error initializing AiravataRegistry2");
+        } catch (RegistryAccessorUndefinedException e) {
+            log.error("Error initializing AiravataRegistry2");
+        }
+        return registry;
+    }
+}



Mime
View raw message