Coverage Report - org.kuali.rice.ksb.messaging.web.ServiceRegistryAction
 
Classes in this File Line Coverage Branch Coverage Complexity
ServiceRegistryAction
0%
0/29
0%
0/6
1.5
 
 1  
 /*
 2  
  * Copyright 2006-2011 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  * http://www.opensource.org/licenses/ecl2.php
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 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.CoreConfigHelper;
 24  
 import org.kuali.rice.core.api.config.property.ConfigContext;
 25  
 import org.kuali.rice.core.api.util.RiceUtilities;
 26  
 import org.kuali.rice.ksb.api.KsbApiServiceLocator;
 27  
 import org.kuali.rice.ksb.api.bus.Endpoint;
 28  
 import org.kuali.rice.ksb.api.bus.ServiceBus;
 29  
 import org.kuali.rice.ksb.api.bus.ServiceConfiguration;
 30  
 import org.kuali.rice.ksb.api.registry.ServiceInfo;
 31  
 import org.kuali.rice.ksb.api.registry.ServiceRegistry;
 32  
 
 33  
 import javax.servlet.ServletException;
 34  
 import javax.servlet.http.HttpServletRequest;
 35  
 import javax.servlet.http.HttpServletResponse;
 36  
 import javax.xml.namespace.QName;
 37  
 import java.io.IOException;
 38  
 import java.util.ArrayList;
 39  
 import java.util.List;
 40  
 import java.util.Map;
 41  
 
 42  
 
 43  
 /**
 44  
  * Struts action for interacting with the queue of messages.
 45  
  *
 46  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 47  
  */
 48  0
 public class ServiceRegistryAction extends KSBAction {
 49  
 
 50  
     public ActionForward start(ActionMapping mapping, ActionForm form, HttpServletRequest request,
 51  
             HttpServletResponse response) throws IOException, ServletException {
 52  0
         return mapping.findForward("basic");
 53  
     }
 54  
 
 55  
     public ActionForward refreshServiceRegistry(ActionMapping mapping, ActionForm form, HttpServletRequest request,
 56  
             HttpServletResponse response) throws IOException, ServletException {
 57  
             // TODO is this what really constitutes a "refresh" of the service registry?
 58  0
             KsbApiServiceLocator.getServiceBus().synchronize();
 59  0
             return mapping.findForward("basic");
 60  
     }
 61  
     
 62  
         /**
 63  
      * Enable deletion of localhost service registry entries.
 64  
      */
 65  
     public ActionForward deleteLocalhostEntries(ActionMapping mapping, ActionForm form, HttpServletRequest request,
 66  
                 HttpServletResponse response) throws IOException, ServletException {
 67  0
             ServiceRegistry serviceRegistry = KsbApiServiceLocator.getServiceRegistry();
 68  0
             List<ServiceInfo> serviceInfos = serviceRegistry.getAllOnlineServices();
 69  0
             List<String> serviceEndpointsToDelete = new ArrayList<String>();
 70  0
             for (ServiceInfo serviceInfo : serviceInfos) {
 71  0
                     if (serviceInfo.getServerIpAddress().equals("localhost")) {
 72  0
                             serviceEndpointsToDelete.add(serviceInfo.getServiceId());
 73  
                     }
 74  
             }
 75  0
             serviceRegistry.removeServiceEndpoints(serviceEndpointsToDelete);
 76  0
             KsbApiServiceLocator.getServiceBus().synchronize();
 77  0
                 return mapping.findForward("basic");
 78  
     }
 79  
 
 80  
 
 81  
     public ActionMessages establishRequiredState(HttpServletRequest request, ActionForm actionForm) throws Exception {
 82  0
         ServiceRegistryForm form = (ServiceRegistryForm)actionForm;
 83  0
         form.setMyIpAddress(RiceUtilities.getIpNumber());
 84  0
         form.setMyApplicationId(CoreConfigHelper.getApplicationId());
 85  0
         form.setDevMode(ConfigContext.getCurrentContextConfig().getDevMode());
 86  0
         ServiceBus serviceBus = KsbApiServiceLocator.getServiceBus();
 87  0
         form.setMyInstanceId(serviceBus.getInstanceId());
 88  0
         form.setPublishedServices(getPublishedServices(serviceBus));
 89  0
         ServiceRegistry serviceRegistry = KsbApiServiceLocator.getServiceRegistry();
 90  0
         form.setGlobalRegistryServices(getGlobalRegistryServices(serviceRegistry));
 91  
 
 92  0
         return null;
 93  
     }
 94  
 
 95  
     private List<ServiceConfiguration> getPublishedServices(ServiceBus serviceBus) {
 96  0
             Map<QName, Endpoint> localEndpoints = serviceBus.getLocalEndpoints();
 97  0
             List<ServiceConfiguration> publishedServices = new ArrayList<ServiceConfiguration>();
 98  0
             for (Endpoint endpoint : localEndpoints.values()) {
 99  0
                     publishedServices.add(endpoint.getServiceConfiguration());
 100  
             }
 101  0
             return publishedServices;
 102  
     }
 103  
 
 104  
     private List<ServiceInfo> getGlobalRegistryServices(ServiceRegistry serviceRegistry) {
 105  0
             return serviceRegistry.getAllServices();
 106  
     }
 107  
 
 108  
 }