airavata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lah...@apache.org
Subject svn commit: r1179491 - /incubator/airavata/trunk/modules/gfac-axis2/src/main/java/org/apache/airavata/services/gfac/axis2/GFacService.java
Date Thu, 06 Oct 2011 03:19:46 GMT
Author: lahiru
Date: Thu Oct  6 03:19:46 2011
New Revision: 1179491

URL: http://svn.apache.org/viewvc?rev=1179491&view=rev
Log:
code cleanup and fixing https://issues.apache.org/jira/browse/AIRAVATA-127.

Modified:
    incubator/airavata/trunk/modules/gfac-axis2/src/main/java/org/apache/airavata/services/gfac/axis2/GFacService.java

Modified: incubator/airavata/trunk/modules/gfac-axis2/src/main/java/org/apache/airavata/services/gfac/axis2/GFacService.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/gfac-axis2/src/main/java/org/apache/airavata/services/gfac/axis2/GFacService.java?rev=1179491&r1=1179490&r2=1179491&view=diff
==============================================================================
--- incubator/airavata/trunk/modules/gfac-axis2/src/main/java/org/apache/airavata/services/gfac/axis2/GFacService.java
(original)
+++ incubator/airavata/trunk/modules/gfac-axis2/src/main/java/org/apache/airavata/services/gfac/axis2/GFacService.java
Thu Oct  6 03:19:46 2011
@@ -22,18 +22,16 @@
 package org.apache.airavata.services.gfac.axis2;
 
 import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
 import java.net.URL;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
+import java.util.*;
 
 import javax.jcr.Credentials;
 import javax.jcr.Repository;
 import javax.jcr.RepositoryFactory;
 import javax.jcr.SimpleCredentials;
 import javax.security.auth.login.Configuration;
+import javax.servlet.ServletContext;
 
 import org.apache.airavata.core.gfac.services.GenericService;
 import org.apache.airavata.registry.api.Registry;
@@ -43,15 +41,18 @@ import org.apache.airavata.services.gfac
 import org.apache.airavata.services.gfac.axis2.util.WSConstants;
 import org.apache.axis2.addressing.EndpointReference;
 import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.deployment.WarBasedAxisConfigurator;
 import org.apache.axis2.description.AxisService;
+import org.apache.axis2.description.TransportInDescription;
 import org.apache.axis2.engine.AxisConfiguration;
+import org.apache.axis2.engine.AxisConfigurator;
 import org.apache.axis2.engine.Phase;
 import org.apache.axis2.engine.ServiceLifeCycle;
 import org.apache.axis2.util.Utils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class GFacService extends Thread implements ServiceLifeCycle {
+public class GFacService implements ServiceLifeCycle {
     
     private static final Logger log = LoggerFactory.getLogger(GFacService.class);
 
@@ -70,6 +71,7 @@ public class GFacService extends Thread 
     public static GenericService service;
     public static final int GFAC_URL_UPDATE_INTERVAL = 1000 * 60 * 60 * 3;
     public ConfigurationContext context;
+    public GFacThread thread;
     public static final String GFAC_URL = "GFacURL";
 
     public void startUp(ConfigurationContext configctx, AxisService service){
@@ -94,6 +96,7 @@ public class GFacService extends Thread 
 
     private void initializeRepository(ConfigurationContext context) {
         Properties properties = new Properties();
+        String port = null;
         try {
             URL url = this.getClass().getClassLoader().getResource(REPOSITORY_PROPERTIES);
             properties.load(url.openStream());
@@ -106,14 +109,20 @@ public class GFacService extends Thread 
 
             Registry registry = new JCRRegistry(repository, credentials);
             String localAddress = Utils.getIpAddress(context.getAxisConfiguration());
-            String port = (String) context.getAxisConfiguration().getTransportsIn().get("http").getParameter("port").getValue();
+            TransportInDescription transportInDescription = context.getAxisConfiguration().getTransportsIn().get("http");
+            if(transportInDescription != null){
+                port = (String)transportInDescription.getParameter("port").getValue();
+            }else{
+                port = getTomcatPort(context);
+            }
             localAddress = "http://" + localAddress + ":" + port;
             localAddress = localAddress + "/" +
                     context.getContextRoot() + "/" + context.getServicePath() + "/" + WSConstants.GFAC_SERVICE_NAME;
             System.out.println(localAddress);
             context.setProperty(CONFIGURATION_CONTEXT_REGISTRY, registry);
-            context.setProperty(GFAC_URL,localAddress);
-            this.start();
+            context.setProperty(GFAC_URL, localAddress);
+            thread = new GFacThread(context);
+            thread.start();
         } catch (Exception e) {
             log.error(e.getMessage(), e);
         }
@@ -123,15 +132,62 @@ public class GFacService extends Thread 
         Registry registry = (JCRRegistry) configctx.getProperty(CONFIGURATION_CONTEXT_REGISTRY);
         String gfacURL = (String) configctx.getProperty(GFAC_URL);
         registry.deleteGFacDescriptor(gfacURL);
-            this.interrupt();
+            thread.interrupt();
         try {
-            this.join();
+            thread.join();
         } catch (InterruptedException e) {
             log.info("GFacURL update thread is interrupted");
         }
     }
 
-    public void run() {
+
+
+    private String getTomcatPort(ConfigurationContext context) {
+        String port = null;
+        try {
+            Object obj = getNextObject(getNextObject(getNextObject(context.getProperty("transport.http.servletContext").getClass(),"context"),"context"),"context");
+            Field field = obj.getClass().getSuperclass().getDeclaredField("listeners");
+            field.setAccessible(true);
+            ArrayList list = (ArrayList) field.get(obj);
+            for(int i=0;i<list.size();i++){
+                obj = list.get(i);
+                obj = getNextObject(obj,"connector");
+                field = obj.getClass().getDeclaredField("scheme");
+                field.setAccessible(true);
+                String scheme = (String)field.get(obj);
+                if("http".equals(scheme)){
+                    field = obj.getClass().getDeclaredField("port");
+                    field.setAccessible(true);
+                    port = Integer.toString(field.getInt(obj));
+                    break;
+                }
+            }
+        } catch (NoSuchFieldException e) {
+            e.printStackTrace();  //To change body of catch statement use File | Settings
| File Templates.
+        } catch (IllegalAccessException e) {
+            e.printStackTrace();  //To change body of catch statement use File | Settings
| File Templates.
+        }
+        return port;
+    }
+
+    private Object getNextObject(Object obj,String fieldName){
+        try {
+            Field field = obj.getClass().getDeclaredField(fieldName);
+            field.setAccessible(true);
+            return field.get(obj);
+        } catch (NoSuchFieldException e) {
+            e.printStackTrace();  //To change body of catch statement use File | Settings
| File Templates.
+        } catch (IllegalAccessException e) {
+            e.printStackTrace();  //To change body of catch statement use File | Settings
| File Templates.
+        }
+    }
+    class GFacThread extends Thread{
+        private ConfigurationContext context = null;
+
+        GFacThread(ConfigurationContext context){
+            this.context = context;
+        }
+        public void run() {
         try {
             while (true) {
                 Registry registry = (Registry) this.context.getProperty(CONFIGURATION_CONTEXT_REGISTRY);
@@ -144,4 +200,5 @@ public class GFacService extends Thread 
             log.info("GFacURL update thread is interrupted");
         }
     }
+    }
 }



Mime
View raw message