|  1 |     | 
     | 
  |  2 |     | 
     | 
  |  3 |     | 
     | 
  |  4 |     | 
     | 
  |  5 |     | 
     | 
  |  6 |     | 
     | 
  |  7 |     | 
     | 
  |  8 |     | 
     | 
  |  9 |     | 
     | 
  |  10 |     | 
     | 
  |  11 |     | 
     | 
  |  12 |     | 
     | 
  |  13 |     | 
     | 
  |  14 |     | 
     | 
  |  15 |     | 
     | 
  |  16 |     | 
     | 
  |  17 |     | 
   package org.kuali.rice.ksb.messaging.web;  | 
  |  18 |     | 
     | 
  |  19 |     | 
   import org.apache.struts.action.ActionForm;  | 
  |  20 |     | 
   import org.apache.struts.action.ActionForward;  | 
  |  21 |     | 
   import org.apache.struts.action.ActionMapping;  | 
  |  22 |     | 
   import org.apache.struts.action.ActionMessages;  | 
  |  23 |     | 
   import org.kuali.rice.core.api.config.property.ConfigContext;  | 
  |  24 |     | 
   import org.kuali.rice.core.util.RiceUtilities;  | 
  |  25 |     | 
   import org.kuali.rice.ksb.messaging.RemoteResourceServiceLocator;  | 
  |  26 |     | 
   import org.kuali.rice.ksb.messaging.RemotedServiceHolder;  | 
  |  27 |     | 
   import org.kuali.rice.ksb.messaging.RemotedServiceRegistry;  | 
  |  28 |     | 
   import org.kuali.rice.ksb.messaging.ServerSideRemotedServiceHolder;  | 
  |  29 |     | 
   import org.kuali.rice.ksb.messaging.ServiceInfo;  | 
  |  30 |     | 
   import org.kuali.rice.ksb.messaging.resourceloader.KSBResourceLoaderFactory;  | 
  |  31 |     | 
   import org.kuali.rice.ksb.messaging.service.ServiceRegistry;  | 
  |  32 |     | 
   import org.kuali.rice.ksb.service.KSBServiceLocator;  | 
  |  33 |     | 
   import org.kuali.rice.ksb.util.KSBConstants;  | 
  |  34 |     | 
     | 
  |  35 |     | 
   import javax.servlet.ServletException;  | 
  |  36 |     | 
   import javax.servlet.http.HttpServletRequest;  | 
  |  37 |     | 
   import javax.servlet.http.HttpServletResponse;  | 
  |  38 |     | 
   import javax.xml.namespace.QName;  | 
  |  39 |     | 
   import java.io.IOException;  | 
  |  40 |     | 
   import java.util.ArrayList;  | 
  |  41 |     | 
   import java.util.List;  | 
  |  42 |     | 
   import java.util.Map;  | 
  |  43 |     | 
     | 
  |  44 |     | 
     | 
  |  45 |     | 
     | 
  |  46 |     | 
     | 
  |  47 |     | 
     | 
  |  48 |     | 
     | 
  |  49 |     | 
     | 
  |  50 |    0 |    public class ServiceRegistryAction extends KSBAction { | 
  |  51 |     | 
     | 
  |  52 |     | 
       public ActionForward start(ActionMapping mapping, ActionForm form, HttpServletRequest request,  | 
  |  53 |     | 
               HttpServletResponse response) throws IOException, ServletException { | 
  |  54 |    0 |            return mapping.findForward("basic"); | 
  |  55 |     | 
       }  | 
  |  56 |     | 
     | 
  |  57 |     | 
       public ActionForward refreshServiceRegistry(ActionMapping mapping, ActionForm form, HttpServletRequest request,  | 
  |  58 |     | 
               HttpServletResponse response) throws IOException, ServletException { | 
  |  59 |     | 
             | 
  |  60 |    0 |            KSBServiceLocator.getServiceDeployer().refresh();  | 
  |  61 |    0 |            KSBResourceLoaderFactory.getRemoteResourceLocator().refresh();  | 
  |  62 |    0 |            return mapping.findForward("basic"); | 
  |  63 |     | 
       }  | 
  |  64 |     | 
         | 
  |  65 |     | 
             | 
  |  66 |     | 
     | 
  |  67 |     | 
     | 
  |  68 |     | 
       public ActionForward deleteLocalhostEntries(ActionMapping mapping, ActionForm form, HttpServletRequest request,  | 
  |  69 |     | 
                   HttpServletResponse response) throws IOException, ServletException { | 
  |  70 |    0 |                ServiceRegistry registry = KSBServiceLocator.getServiceRegistry();  | 
  |  71 |    0 |            registry.removeLocallyPublishedServices("localhost",null); | 
  |  72 |    0 |                    return mapping.findForward("basic"); | 
  |  73 |     | 
       }  | 
  |  74 |     | 
     | 
  |  75 |     | 
     | 
  |  76 |     | 
       public ActionMessages establishRequiredState(HttpServletRequest request, ActionForm actionForm) throws Exception { | 
  |  77 |    0 |            ServiceRegistryForm form = (ServiceRegistryForm)actionForm;  | 
  |  78 |    0 |            form.setMyIpAddress(RiceUtilities.getIpNumber());  | 
  |  79 |    0 |            form.setMyServiceNamespace(ConfigContext.getCurrentContextConfig().getProperty(KSBConstants.Config.SERVICE_NAMESPACE));  | 
  |  80 |    0 |            form.setDevMode(ConfigContext.getCurrentContextConfig().getDevMode());  | 
  |  81 |    0 |            RemotedServiceRegistry registry = KSBServiceLocator.getServiceDeployer();  | 
  |  82 |    0 |            RemoteResourceServiceLocator remoteLocator = KSBResourceLoaderFactory.getRemoteResourceLocator();  | 
  |  83 |    0 |            form.setPublishedServices(getPublishedServices(registry));  | 
  |  84 |    0 |            form.setPublishedTempServices(getPublishedTempServices(registry));  | 
  |  85 |    0 |            form.setGlobalRegistryServices(getGlobalRegistryServices(remoteLocator));  | 
  |  86 |     | 
     | 
  |  87 |    0 |            return null;  | 
  |  88 |     | 
       }  | 
  |  89 |     | 
     | 
  |  90 |     | 
       private List<ServiceInfo> getPublishedServices(RemotedServiceRegistry registry) { | 
  |  91 |    0 |            Map<QName, ServerSideRemotedServiceHolder> publishedServiceHolders = registry.getPublishedServices();  | 
  |  92 |    0 |            List<ServiceInfo> publishedServices = new ArrayList<ServiceInfo>();  | 
  |  93 |    0 |            for (ServerSideRemotedServiceHolder holder : publishedServiceHolders.values()) { | 
  |  94 |    0 |                publishedServices.add(holder.getServiceInfo());  | 
  |  95 |     | 
           }  | 
  |  96 |    0 |            return publishedServices;  | 
  |  97 |     | 
       }  | 
  |  98 |     | 
     | 
  |  99 |     | 
       private List<ServiceInfo> getPublishedTempServices(RemotedServiceRegistry registry) { | 
  |  100 |    0 |            Map<QName, ServerSideRemotedServiceHolder> publishedTempServiceHolders = registry.getPublishedTempServices();  | 
  |  101 |    0 |            List<ServiceInfo> publishedTempServices = new ArrayList<ServiceInfo>();  | 
  |  102 |    0 |            for (ServerSideRemotedServiceHolder holder : publishedTempServiceHolders.values()) { | 
  |  103 |    0 |                publishedTempServices.add(holder.getServiceInfo());  | 
  |  104 |     | 
           }  | 
  |  105 |    0 |            return publishedTempServices;  | 
  |  106 |     | 
       }  | 
  |  107 |     | 
     | 
  |  108 |     | 
       private List<ServiceInfo> getGlobalRegistryServices(RemoteResourceServiceLocator remoteLocator) { | 
  |  109 |    0 |            Map<QName, List<RemotedServiceHolder>> clients = remoteLocator.getClients();  | 
  |  110 |    0 |            List<ServiceInfo> globalRegistryServices = new ArrayList<ServiceInfo>();  | 
  |  111 |    0 |            for (List<RemotedServiceHolder> client : clients.values()) { | 
  |  112 |    0 |                for (RemotedServiceHolder holder : client) { | 
  |  113 |    0 |                    globalRegistryServices.add(holder.getServiceInfo());  | 
  |  114 |     | 
               }  | 
  |  115 |     | 
           }  | 
  |  116 |    0 |            return globalRegistryServices;  | 
  |  117 |     | 
       }  | 
  |  118 |     | 
     | 
  |  119 |     | 
   }  |