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 java.io.IOException;
 20  
 import java.util.ArrayList;
 21  
 import java.util.List;
 22  
 import java.util.Map;
 23  
 
 24  
 import javax.servlet.ServletException;
 25  
 import javax.servlet.http.HttpServletRequest;
 26  
 import javax.servlet.http.HttpServletResponse;
 27  
 import javax.xml.namespace.QName;
 28  
 
 29  
 import org.apache.struts.action.ActionForm;
 30  
 import org.apache.struts.action.ActionForward;
 31  
 import org.apache.struts.action.ActionMapping;
 32  
 import org.apache.struts.action.ActionMessages;
 33  
 import org.kuali.rice.core.api.config.CoreConfigHelper;
 34  
 import org.kuali.rice.core.api.config.property.ConfigContext;
 35  
 import org.kuali.rice.core.util.RiceUtilities;
 36  
 import org.kuali.rice.ksb.api.KsbApiServiceLocator;
 37  
 import org.kuali.rice.ksb.api.bus.Endpoint;
 38  
 import org.kuali.rice.ksb.api.bus.ServiceBus;
 39  
 import org.kuali.rice.ksb.api.bus.ServiceConfiguration;
 40  
 import org.kuali.rice.ksb.api.registry.ServiceInfo;
 41  
 import org.kuali.rice.ksb.api.registry.ServiceRegistry;
 42  
 
 43  
 
 44  
 /**
 45  
  * Struts action for interacting with the queue of messages.
 46  
  *
 47  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 48  
  */
 49  0
 public class ServiceRegistryAction extends KSBAction {
 50  
 
 51  
     public ActionForward start(ActionMapping mapping, ActionForm form, HttpServletRequest request,
 52  
             HttpServletResponse response) throws IOException, ServletException {
 53  0
         return mapping.findForward("basic");
 54  
     }
 55  
 
 56  
     public ActionForward refreshServiceRegistry(ActionMapping mapping, ActionForm form, HttpServletRequest request,
 57  
             HttpServletResponse response) throws IOException, ServletException {
 58  
             // TODO is this what really constitutes a "refresh" of the service registry?
 59  0
             KsbApiServiceLocator.getServiceBus().synchronize();
 60  0
             return mapping.findForward("basic");
 61  
     }
 62  
     
 63  
         /**
 64  
      * Enable deletion of localhost service registry entries.
 65  
      */
 66  
     public ActionForward deleteLocalhostEntries(ActionMapping mapping, ActionForm form, HttpServletRequest request,
 67  
                 HttpServletResponse response) throws IOException, ServletException {
 68  0
             ServiceRegistry serviceRegistry = KsbApiServiceLocator.getServiceRegistry();
 69  0
             List<ServiceInfo> serviceInfos = serviceRegistry.getAllOnlineServices();
 70  0
             List<String> serviceEndpointsToDelete = new ArrayList<String>();
 71  0
             for (ServiceInfo serviceInfo : serviceInfos) {
 72  0
                     if (serviceInfo.getServerIpAddress().equals("localhost")) {
 73  0
                             serviceEndpointsToDelete.add(serviceInfo.getServiceId());
 74  
                     }
 75  
             }
 76  0
             serviceRegistry.removeServiceEndpoints(serviceEndpointsToDelete);
 77  0
             KsbApiServiceLocator.getServiceBus().synchronize();
 78  0
                 return mapping.findForward("basic");
 79  
     }
 80  
 
 81  
 
 82  
     public ActionMessages establishRequiredState(HttpServletRequest request, ActionForm actionForm) throws Exception {
 83  0
         ServiceRegistryForm form = (ServiceRegistryForm)actionForm;
 84  0
         form.setMyIpAddress(RiceUtilities.getIpNumber());
 85  0
         form.setMyApplicationId(CoreConfigHelper.getApplicationId());
 86  0
         form.setDevMode(ConfigContext.getCurrentContextConfig().getDevMode());
 87  0
         ServiceBus serviceBus = KsbApiServiceLocator.getServiceBus();
 88  0
         form.setMyInstanceId(serviceBus.getInstanceId());
 89  0
         form.setPublishedServices(getPublishedServices(serviceBus));
 90  0
         ServiceRegistry serviceRegistry = KsbApiServiceLocator.getServiceRegistry();
 91  0
         form.setGlobalRegistryServices(getGlobalRegistryServices(serviceRegistry));
 92  
 
 93  0
         return null;
 94  
     }
 95  
 
 96  
     private List<ServiceConfiguration> getPublishedServices(ServiceBus serviceBus) {
 97  0
             Map<QName, Endpoint> localEndpoints = serviceBus.getLocalEndpoints();
 98  0
             List<ServiceConfiguration> publishedServices = new ArrayList<ServiceConfiguration>();
 99  0
             for (Endpoint endpoint : localEndpoints.values()) {
 100  0
                     publishedServices.add(endpoint.getServiceConfiguration());
 101  
             }
 102  0
             return publishedServices;
 103  
     }
 104  
 
 105  
     private List<ServiceInfo> getGlobalRegistryServices(ServiceRegistry serviceRegistry) {
 106  0
             return serviceRegistry.getAllServices();
 107  
     }
 108  
 
 109  
 }