| 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 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 | |
|
| 46 | |
|
| 47 | |
|
| 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 | |
|
| 59 | 0 | KsbApiServiceLocator.getServiceBus().synchronize(); |
| 60 | 0 | return mapping.findForward("basic"); |
| 61 | |
} |
| 62 | |
|
| 63 | |
|
| 64 | |
|
| 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 | |
} |