|
6 | 6 | import org.apache.dubbo.config.ProtocolConfig; |
7 | 7 | import org.apache.dubbo.config.RegistryConfig; |
8 | 8 | import org.apache.dubbo.config.ServiceConfig; |
9 | | -import org.apache.dubbo.config.ServiceConfigBase; |
10 | 9 | import org.apache.dubbo.config.context.ConfigManager; |
11 | 10 | import org.apache.dubbo.rpc.model.ApplicationModel; |
12 | 11 |
|
@@ -152,9 +151,43 @@ public String registerService() throws Throwable { |
152 | 151 | } |
153 | 152 | } |
154 | 153 |
|
| 154 | + @SuppressWarnings("all") |
155 | 155 | private boolean isPathRegisteredInFramework(String path) { |
156 | | - Collection<ServiceConfigBase> services = ApplicationModel.getConfigManager().getServices(); |
157 | | - return services.stream().anyMatch(s -> path.equals(s.getPath())); |
| 156 | + try { |
| 157 | + for (Object service : getRegisteredServices()) { |
| 158 | + try { |
| 159 | + Method getPath = service.getClass().getMethod("getPath"); |
| 160 | + if (path.equals(getPath.invoke(service))) { |
| 161 | + return true; |
| 162 | + } |
| 163 | + } catch (Exception ignored) { |
| 164 | + } |
| 165 | + } |
| 166 | + } catch (Exception ignored) { |
| 167 | + } |
| 168 | + return false; |
| 169 | + } |
| 170 | + |
| 171 | + @SuppressWarnings("all") |
| 172 | + private Collection<?> getRegisteredServices() { |
| 173 | + try { |
| 174 | + ConfigManager configManager = ApplicationModel.getConfigManager(); |
| 175 | + Method getServices = configManager.getClass().getMethod("getServices"); |
| 176 | + return (Collection<?>) getServices.invoke(configManager); |
| 177 | + } catch (Exception e) { |
| 178 | + try { |
| 179 | + Method defaultModel = ApplicationModel.class.getMethod("defaultModel"); |
| 180 | + Object model = defaultModel.invoke(null); |
| 181 | + Method getDefaultModule = model.getClass().getMethod("getDefaultModule"); |
| 182 | + Object moduleModel = getDefaultModule.invoke(model); |
| 183 | + Method getConfigManager = moduleModel.getClass().getMethod("getConfigManager"); |
| 184 | + Object moduleConfigManager = getConfigManager.invoke(moduleModel); |
| 185 | + Method getServices = moduleConfigManager.getClass().getMethod("getServices"); |
| 186 | + return (Collection<?>) getServices.invoke(moduleConfigManager); |
| 187 | + } catch (Exception ex) { |
| 188 | + return new ArrayList<>(); |
| 189 | + } |
| 190 | + } |
158 | 191 | } |
159 | 192 |
|
160 | 193 | private String normalizePath(String path) { |
@@ -200,6 +233,7 @@ private ServiceConfig<Object> createServiceConfig(String path, Class<?> interfac |
200 | 233 | serviceConfig.setRef(serviceInstance); |
201 | 234 | serviceConfig.setPath(path); |
202 | 235 | serviceConfig.setVersion("1.0.0"); |
| 236 | + serviceConfig.setProxy("jdk"); |
203 | 237 | serviceConfig.setApplication(configManager.getApplication().orElse(null)); |
204 | 238 |
|
205 | 239 | List<ProtocolConfig> protocols = new ArrayList<>(configManager.getDefaultProtocols()); |
|
0 commit comments