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