1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
package org.kuali.rice.ksb.messaging.web; |
15 | |
|
16 | |
import java.io.IOException; |
17 | |
import java.util.ArrayList; |
18 | |
import java.util.List; |
19 | |
import java.util.Map; |
20 | |
|
21 | |
import javax.servlet.ServletException; |
22 | |
import javax.servlet.http.HttpServletRequest; |
23 | |
import javax.servlet.http.HttpServletResponse; |
24 | |
import javax.sql.DataSource; |
25 | |
import javax.xml.namespace.QName; |
26 | |
|
27 | |
import org.apache.struts.action.ActionForm; |
28 | |
import org.apache.struts.action.ActionForward; |
29 | |
import org.apache.struts.action.ActionMapping; |
30 | |
import org.apache.struts.action.ActionMessages; |
31 | |
import org.kuali.rice.core.config.ConfigContext; |
32 | |
import org.kuali.rice.core.util.RiceUtilities; |
33 | |
import org.kuali.rice.kew.service.KEWServiceLocator; |
34 | |
import org.kuali.rice.ksb.messaging.RemoteResourceServiceLocator; |
35 | |
import org.kuali.rice.ksb.messaging.RemotedServiceHolder; |
36 | |
import org.kuali.rice.ksb.messaging.RemotedServiceRegistry; |
37 | |
import org.kuali.rice.ksb.messaging.ServerSideRemotedServiceHolder; |
38 | |
import org.kuali.rice.ksb.messaging.ServiceInfo; |
39 | |
import org.kuali.rice.ksb.messaging.resourceloader.KSBResourceLoaderFactory; |
40 | |
import org.kuali.rice.ksb.service.KSBServiceLocator; |
41 | |
import org.kuali.rice.ksb.util.KSBConstants; |
42 | |
import org.springframework.jdbc.core.JdbcTemplate; |
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 | String sqlString = "delete from KRSB_SVC_DEF_T where SVC_URL like '%localhost%'"; |
71 | 0 | DataSource ds = (DataSource) KEWServiceLocator.getDataSource(); |
72 | 0 | JdbcTemplate t = new JdbcTemplate(ds); |
73 | 0 | final String sqlToExec = sqlString; |
74 | 0 | t.execute(sqlToExec); |
75 | 0 | return mapping.findForward("basic"); |
76 | |
} |
77 | |
|
78 | |
|
79 | |
public ActionMessages establishRequiredState(HttpServletRequest request, ActionForm actionForm) throws Exception { |
80 | 0 | ServiceRegistryForm form = (ServiceRegistryForm)actionForm; |
81 | 0 | form.setMyIpAddress(RiceUtilities.getIpNumber()); |
82 | 0 | form.setMyServiceNamespace(ConfigContext.getCurrentContextConfig().getProperty(KSBConstants.SERVICE_NAMESPACE)); |
83 | 0 | form.setDevMode(ConfigContext.getCurrentContextConfig().getDevMode()); |
84 | 0 | RemotedServiceRegistry registry = KSBServiceLocator.getServiceDeployer(); |
85 | 0 | RemoteResourceServiceLocator remoteLocator = KSBResourceLoaderFactory.getRemoteResourceLocator(); |
86 | 0 | form.setPublishedServices(getPublishedServices(registry)); |
87 | 0 | form.setPublishedTempServices(getPublishedTempServices(registry)); |
88 | 0 | form.setGlobalRegistryServices(getGlobalRegistryServices(remoteLocator)); |
89 | |
|
90 | 0 | return null; |
91 | |
} |
92 | |
|
93 | |
private List<ServiceInfo> getPublishedServices(RemotedServiceRegistry registry) { |
94 | 0 | Map<QName, ServerSideRemotedServiceHolder> publishedServiceHolders = registry.getPublishedServices(); |
95 | 0 | List<ServiceInfo> publishedServices = new ArrayList<ServiceInfo>(); |
96 | 0 | for (ServerSideRemotedServiceHolder holder : publishedServiceHolders.values()) { |
97 | 0 | publishedServices.add(holder.getServiceInfo()); |
98 | |
} |
99 | 0 | return publishedServices; |
100 | |
} |
101 | |
|
102 | |
private List<ServiceInfo> getPublishedTempServices(RemotedServiceRegistry registry) { |
103 | 0 | Map<QName, ServerSideRemotedServiceHolder> publishedTempServiceHolders = registry.getPublishedTempServices(); |
104 | 0 | List<ServiceInfo> publishedTempServices = new ArrayList<ServiceInfo>(); |
105 | 0 | for (ServerSideRemotedServiceHolder holder : publishedTempServiceHolders.values()) { |
106 | 0 | publishedTempServices.add(holder.getServiceInfo()); |
107 | |
} |
108 | 0 | return publishedTempServices; |
109 | |
} |
110 | |
|
111 | |
private List<ServiceInfo> getGlobalRegistryServices(RemoteResourceServiceLocator remoteLocator) { |
112 | 0 | Map<QName, List<RemotedServiceHolder>> clients = remoteLocator.getClients(); |
113 | 0 | List<ServiceInfo> globalRegistryServices = new ArrayList<ServiceInfo>(); |
114 | 0 | for (List<RemotedServiceHolder> client : clients.values()) { |
115 | 0 | for (RemotedServiceHolder holder : client) { |
116 | 0 | globalRegistryServices.add(holder.getServiceInfo()); |
117 | |
} |
118 | |
} |
119 | 0 | return globalRegistryServices; |
120 | |
} |
121 | |
|
122 | |
} |