org.apache.dubbo.common.URL Java Examples
The following examples show how to use
org.apache.dubbo.common.URL.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DubboServiceRegistrationNonWebApplicationAutoConfiguration.java From spring-cloud-alibaba with Apache License 2.0 | 6 votes |
/** * Set web port from {@link ServiceBean#getExportedUrls() exported URLs} if "rest" * protocol is present. */ private void setServerPort() { if (serverPort == null) { synchronized (DubboServiceRegistrationNonWebApplicationAutoConfiguration.class) { if (serverPort == null) { for (List<URL> urls : repository.getAllExportedUrls().values()) { urls.stream().filter( url -> REST_PROTOCOL.equalsIgnoreCase(url.getProtocol())) .findFirst().ifPresent(url -> { serverPort = url.getPort(); }); // If REST protocol is not present, use any applied port. if (serverPort == null) { urls.stream().findAny().ifPresent(url -> { serverPort = url.getPort(); }); } } } } } }
Example #2
Source File: DubboInterceptorTest.java From skywalking with Apache License 2.0 | 6 votes |
@Before public void setUp() throws Exception { dubboInterceptor = new DubboInterceptor(); PowerMockito.mockStatic(RpcContext.class); when(invoker.getUrl()).thenReturn(URL.valueOf("dubbo://127.0.0.1:20880/org.apache.skywalking.apm.test.TestDubboService")); when(invocation.getMethodName()).thenReturn("test"); when(invocation.getParameterTypes()).thenReturn(new Class[] {String.class}); when(invocation.getArguments()).thenReturn(new Object[] {"abc"}); PowerMockito.when(RpcContext.getContext()).thenReturn(rpcContext); when(rpcContext.isConsumerSide()).thenReturn(true); allArguments = new Object[] { invoker, invocation }; argumentTypes = new Class[] { invoker.getClass(), invocation.getClass() }; Config.Agent.SERVICE_NAME = "DubboTestCases-APP"; }
Example #3
Source File: DemoServiceIT.java From dubbo-samples with Apache License 2.0 | 6 votes |
@Test public void verifyConsumer() throws Exception { List<String> urls = ZkUtil.getChildren(ZkUtil.toUrlPath("consumers")); urls.stream().map(URL::decode).forEach(System.out::println); Assert.assertEquals(1, urls.size()); String url = urls.get(0); Assert.assertFalse(url.contains("retries")); Assert.assertFalse(url.contains("timeout")); Assert.assertFalse(url.contains("owner")); Assert.assertFalse(url.contains("actives")); Assert.assertTrue(url.contains("application")); Assert.assertTrue(url.contains("version")); Assert.assertTrue(url.contains("group")); Assert.assertTrue(url.contains("release")); }
Example #4
Source File: NacosRegistry.java From dubbo-registry-nacos with Apache License 2.0 | 6 votes |
private Set<String> getServiceNames0(URL url) { NacosServiceName serviceName = createServiceName(url); final Set<String> serviceNames; if (serviceName.isConcrete()) { // is the concrete service name serviceNames = new LinkedHashSet<>(); serviceNames.add(serviceName.toString()); // Add the legacy service name since 2.7.6 String legacySubscribedServiceName = getLegacySubscribedServiceName(url); if (!serviceName.toString().equals(legacySubscribedServiceName)) { //avoid duplicated service names serviceNames.add(legacySubscribedServiceName); } } else { serviceNames = filterServiceNames(serviceName); } return serviceNames; }
Example #5
Source File: NacosRegistry.java From dubbo-registry-nacos with Apache License 2.0 | 6 votes |
private void scheduleServiceNamesLookup(final URL url, final NotifyListener listener) { if (scheduledExecutorService == null) { scheduledExecutorService = Executors.newSingleThreadScheduledExecutor(); scheduledExecutorService.scheduleAtFixedRate(() -> { Set<String> serviceNames = getAllServiceNames(); filterData(serviceNames, serviceName -> { boolean accepted = false; for (String category : ALL_SUPPORTED_CATEGORIES) { String prefix = category + SERVICE_NAME_SEPARATOR; if (serviceName != null && serviceName.startsWith(prefix)) { accepted = true; break; } } return accepted; }); doSubscribe(url, listener, serviceNames); }, LOOKUP_INTERVAL, LOOKUP_INTERVAL, TimeUnit.SECONDS); } }
Example #6
Source File: NacosRegistry.java From dubbo-registry-nacos with Apache License 2.0 | 6 votes |
private void subscribeEventListener(String serviceName, final URL url, final NotifyListener listener) throws NacosException { EventListener eventListener = event -> { if (event instanceof NamingEvent) { NamingEvent e = (NamingEvent) event; List<Instance> instances = e.getInstances(); if(isServiceNamesWithCompatibleMode(url)){ /** * Get all instances with corresponding serviceNames to avoid instance overwrite and but with empty instance mentioned * in https://github.com/apache/dubbo/issues/5885 and https://github.com/apache/dubbo/issues/5899 */ NacosInstanceManageUtil.initOrRefreshServiceInstanceList(serviceName, instances); instances = NacosInstanceManageUtil.getAllCorrespondingServiceInstanceList(serviceName); } notifySubscriber(url, listener, instances); } }; namingService.subscribe(serviceName, eventListener); }
Example #7
Source File: UserLoadBalance.java From dubbo-samples with Apache License 2.0 | 6 votes |
@Override public <T> Invoker<T> doSelect(List<Invoker<T>> invokers, URL url, Invocation invocation) throws RpcException { for (Invoker t : invokers) { try { InetAddress addr = InetAddress.getLocalHost(); String ip = addr.getHostAddress().toString(); URL u = t.getUrl(); if (u.getIp().equals(ip)) { return t; } } catch (Exception e) { // no op } } return super.doSelect(invokers, url, invocation); }
Example #8
Source File: DubboInterceptor.java From skywalking with Apache License 2.0 | 6 votes |
/** * Format operation name. e.g. org.apache.skywalking.apm.plugin.test.Test.test(String) * * @return operation name. */ private String generateOperationName(URL requestURL, Invocation invocation) { StringBuilder operationName = new StringBuilder(); operationName.append(requestURL.getPath()); operationName.append("." + invocation.getMethodName() + "("); for (Class<?> classes : invocation.getParameterTypes()) { operationName.append(classes.getSimpleName() + ","); } if (invocation.getParameterTypes().length > 0) { operationName.delete(operationName.length() - 1, operationName.length()); } operationName.append(")"); return operationName.toString(); }
Example #9
Source File: DemoServiceIT.java From dubbo-samples with Apache License 2.0 | 6 votes |
@Test public void verifyConsumer() throws Exception { List<String> urls = ZkUtil.getChildren(ZkUtil.toUrlPath("consumers")); urls.stream().map(URL::decode).forEach(System.out::println); Assert.assertEquals(1, urls.size()); String url = urls.get(0); Assert.assertFalse(url.contains("retries")); Assert.assertFalse(url.contains("timeout")); Assert.assertFalse(url.contains("owner")); Assert.assertFalse(url.contains("actives")); Assert.assertTrue(url.contains("application")); Assert.assertTrue(url.contains("version")); Assert.assertTrue(url.contains("group")); Assert.assertTrue(url.contains("release")); }
Example #10
Source File: AbstractSpringCloudRegistry.java From spring-cloud-alibaba with Apache License 2.0 | 6 votes |
@Override public final void doSubscribe(URL url, NotifyListener listener) { if (isAdminURL(url)) { // TODO in future } else if (isDubboMetadataServiceURL(url)) { // for DubboMetadataService subscribeDubboMetadataServiceURLs(url, listener); if (from(url).getParameter(CATEGORY_KEY) != null && from(url).getParameter(CATEGORY_KEY).contains(PROVIDER)) { // Fix #1259 and #753 Listene meta service change events to remove useless // clients registerServiceInstancesChangedEventListener(url, listener); } } else { // for general Dubbo Services subscribeDubboServiceURLs(url, listener); } }
Example #11
Source File: AnnotationServiceIT.java From dubbo-samples with Apache License 2.0 | 6 votes |
@Test public void verifyConsumer() throws Exception { List<String> urls = ZkUtil.getChildren(ZkUtil.toUrlPath("consumers")); urls.stream().map(URL::decode).forEach(System.out::println); Assert.assertEquals(1, urls.size()); String url = urls.get(0); Assert.assertFalse(url.contains("retries")); Assert.assertFalse(url.contains("timeout")); Assert.assertFalse(url.contains("owner")); Assert.assertFalse(url.contains("actives")); Assert.assertTrue(url.contains("application")); Assert.assertTrue(url.contains("version")); Assert.assertTrue(url.contains("group")); Assert.assertTrue(url.contains("release")); }
Example #12
Source File: MonitorServiceIT.java From dubbo-samples with Apache License 2.0 | 5 votes |
@Test public void test() throws Exception { for (int i = 0; i < 10; i++) { demoService.sayHello("world"); Thread.sleep(50); } ReferenceConfig<MonitorService> reference = new ReferenceConfig<>(); reference.setApplication(new ApplicationConfig("demo-consumer")); reference.setRegistry(new RegistryConfig("zookeeper://" + zookeeperHost + ":2181")); reference.setInterface(MonitorService.class); reference.setFilter("-monitor"); MonitorService service = reference.get(); List<URL> stats = service.lookup(null); boolean countProvider = false; boolean countConsumer = false; for (URL stat : stats) { Assert.assertEquals("count", stat.getProtocol()); Assert.assertEquals("org.apache.dubbo.samples.monitor.api.DemoService/sayHello", stat.getPath()); if (stat.getParameter("application").equals("demo-provider")) { countProvider = true; } if (stat.getParameter("application").equals("demo-consumer")) { countConsumer = true; } System.out.println(stat); } Assert.assertTrue(countConsumer && countProvider); }
Example #13
Source File: DubboUserServiceGrpc.java From dubbo-benchmark with Apache License 2.0 | 5 votes |
public DubboUserServiceStub(io.grpc.Channel channel, io.grpc.CallOptions callOptions, URL url, ReferenceConfigBase<?> referenceConfig) { this.url = url; this.referenceConfig = referenceConfig; blockingStub = UserServiceGrpc.newBlockingStub(channel).build(channel, callOptions); futureStub = UserServiceGrpc.newFutureStub(channel).build(channel, callOptions); stub = UserServiceGrpc.newStub(channel).build(channel, callOptions); }
Example #14
Source File: NoSimpleRegistryConsumer.java From dubbo-samples with Apache License 2.0 | 5 votes |
private static void printServiceData() { List<String> urls = ZkUtil.getChildren(ZkUtil.toUrlPath("consumers")); System.out.println("*********************************************************"); urls.stream().map(URL::decode).forEach(System.out::println); System.out.println("contains 'retries':" + urls.get(0).contains("retries")); System.out.println("contains 'owner':" + urls.get(0).contains("owner")); System.out.println("contains 'actives':" + urls.get(0).contains("actives")); System.out.println("contains 'timeout':" + urls.get(0).contains("timeout")); System.out.println("contains 'application':" + urls.get(0).contains("application")); System.out.println("contains 'version':" + urls.get(0).contains("version")); System.out.println("contains 'group':" + urls.get(0).contains("group")); System.out.println("contains 'specVersion(default)':" + urls.get(0).contains(RELEASE_KEY)); System.out.println("*********************************************************"); }
Example #15
Source File: NacosRegistry.java From dubbo-registry-nacos with Apache License 2.0 | 5 votes |
@Override public List<URL> lookup(final URL url) { final List<URL> urls = new LinkedList<>(); execute(namingService -> { Set<String> serviceNames = getServiceNames(url, null); for (String serviceName : serviceNames) { List<Instance> instances = namingService.getAllInstances(serviceName); urls.addAll(buildURLs(url, instances)); } }); return urls; }
Example #16
Source File: SimpleRegistryXmlConsumer.java From dubbo-samples with Apache License 2.0 | 5 votes |
private static void printServiceData() { List<String> urls = ZkUtil.getChildren(ZkUtil.toUrlPath("consumers")); System.out.println("*********************************************************"); urls.stream().map(URL::decode).forEach(System.out::println); System.out.println("not contains 'retries':" + !urls.get(0).contains("retries")); System.out.println("not contains 'owner':" + !urls.get(0).contains("owner")); System.out.println("not contains 'actives':" + !urls.get(0).contains("actives")); System.out.println("not contains 'timeout':" + !urls.get(0).contains("timeout")); System.out.println("contains 'application':" + urls.get(0).contains("application")); System.out.println("contains 'version':" + urls.get(0).contains("version")); System.out.println("contains 'group':" + urls.get(0).contains("group")); System.out.println("contains 'specVersion(default)':" + urls.get(0).contains(RELEASE_KEY)); System.out.println("*********************************************************"); }
Example #17
Source File: DubboServiceMetadataRepository.java From spring-cloud-alibaba with Apache License 2.0 | 5 votes |
/** * Remove the metadata and initialized service of Dubbo Services if no there is no * service instance. * @param serviceName the service name * @param url the meta service url */ public void removeMetadataAndInitializedService(String serviceName, URL url) { synchronized (monitor) { initializedServices.remove(serviceName); dubboRestServiceMetadataRepository.remove(serviceName); // fix #1260 if the subscribedDubboMetadataServiceURLs removed fail,old meta // information will be retained if (DubboMetadataService.class.getName().equals(url.getServiceInterface())) { String serviceKey = url.getServiceKey(); subscribedDubboMetadataServiceURLs.remove(serviceKey); } } }
Example #18
Source File: DubboAppContextFilterTest.java From Sentinel-Dashboard-Nacos with Apache License 2.0 | 5 votes |
@Test public void testInvokeNullApplicationKey() { Invoker invoker = mock(Invoker.class); Invocation invocation = mock(Invocation.class); URL url = URL.valueOf("test://test:111/test?application="); when(invoker.getUrl()).thenReturn(url); filter.invoke(invoker, invocation); verify(invoker).invoke(invocation); String application = RpcContext.getContext().getAttachment(DubboUtils.SENTINEL_DUBBO_APPLICATION_KEY); assertNull(application); }
Example #19
Source File: DemoServiceIT.java From dubbo-samples with Apache License 2.0 | 5 votes |
@Test public void testRegisteredConsumers() throws Exception { List<String> urls = ZkUtil.getChildren(ZkUtil.toUrlPath("consumers")); List<String> decodedUrls = urls.stream().map(URL::decode).collect(Collectors.toList()); Assert.assertFalse(decodedUrls.isEmpty()); String url = decodedUrls.get(0); Assert.assertTrue(url.startsWith("consumer://")); }
Example #20
Source File: DubboAppContextFilterTest.java From Sentinel with Apache License 2.0 | 5 votes |
@Test public void testInvokeApplicationKey() { Invoker invoker = mock(Invoker.class); Invocation invocation = mock(Invocation.class); URL url = URL.valueOf("test://test:111/test?application=serviceA"); when(invoker.getUrl()).thenReturn(url); filter.invoke(invoker, invocation); verify(invoker).invoke(invocation); String application = RpcContext.getContext().getAttachment(DubboUtils.SENTINEL_DUBBO_APPLICATION_KEY); assertEquals("serviceA", application); }
Example #21
Source File: SentinelDubboProviderFilterTest.java From Sentinel with Apache License 2.0 | 5 votes |
@Test public void testInvoke() { final String originApplication = "consumerA"; URL url = DubboTestUtil.getDefaultTestURL(); url = url.addParameter(CommonConstants.SIDE_KEY, CommonConstants.PROVIDER_SIDE); Invoker invoker = DubboTestUtil.getMockInvoker(url, DemoService.class); Invocation invocation = DubboTestUtil.getMockInvocation(DemoService.class.getMethods()[0]); when(invocation.getAttachment(DubboUtils.SENTINEL_DUBBO_APPLICATION_KEY, "")) .thenReturn(originApplication); final Result result = mock(Result.class); when(result.hasException()).thenReturn(false); when(result.getException()).thenReturn(new Exception()); when(invoker.invoke(invocation)).thenAnswer(invocationOnMock -> { verifyInvocationStructure(originApplication, invoker, invocation); return result; }); filter.invoke(invoker, invocation); verify(invoker).invoke(invocation); Context context = ContextUtil.getContext(); assertNull(context); }
Example #22
Source File: ApacheDubboUtil.java From DevToolBox with GNU Lesser General Public License v2.1 | 5 votes |
/** * 调用方法 * * @param c * @param method * @param fullUrl * @param args * @return * @throws java.lang.Exception */ public static Object invoke(Class c, Method method, String fullUrl, Object... args) throws Exception { URL url = URL.valueOf(fullUrl); AsyncToSyncInvoker<?> invoker = (AsyncToSyncInvoker<?>) PROTOCOL.refer(c, url); if (invoker.isAvailable()) { Invocation inv = new RpcInvocation(method, url.getParameter("interface"), args); Result ret = invoker.invoke(inv); PROTOCOL.destroy(); return JSON.json(ret.getValue()); } return null; }
Example #23
Source File: DubboServiceMetadataRepository.java From spring-cloud-alibaba with Apache License 2.0 | 5 votes |
public void exportURL(URL url) { URL actualURL = url; InetUtils.HostInfo hostInfo = inetUtils.findFirstNonLoopbackHostInfo(); String ipAddress = hostInfo.getIpAddress(); // To use InetUtils to set IP if they are different // issue : // https://github.com/spring-cloud-incubator/spring-cloud-alibaba/issues/589 if (!Objects.equals(url.getHost(), ipAddress)) { actualURL = url.setHost(ipAddress); } this.allExportedURLs.add(actualURL.getServiceKey(), actualURL); }
Example #24
Source File: AbstractSpringCloudRegistry.java From spring-cloud-alibaba with Apache License 2.0 | 5 votes |
public AbstractSpringCloudRegistry(URL url, DiscoveryClient discoveryClient, DubboServiceMetadataRepository dubboServiceMetadataRepository, DubboMetadataServiceProxy dubboMetadataConfigServiceProxy, JSONUtils jsonUtils, DubboGenericServiceFactory dubboGenericServiceFactory, ConfigurableApplicationContext applicationContext) { super(url); this.servicesLookupInterval = url .getParameter(SERVICES_LOOKUP_INTERVAL_PARAM_NAME, 60L); this.discoveryClient = discoveryClient; this.repository = dubboServiceMetadataRepository; this.dubboMetadataConfigServiceProxy = dubboMetadataConfigServiceProxy; this.jsonUtils = jsonUtils; this.dubboGenericServiceFactory = dubboGenericServiceFactory; this.applicationContext = applicationContext; }
Example #25
Source File: DubboAppContextFilterTest.java From dubbo-sentinel-support with Apache License 2.0 | 5 votes |
@Test public void testInvokeNullApplicationKey() { Invoker invoker = mock(Invoker.class); Invocation invocation = mock(Invocation.class); URL url = URL.valueOf("test://test:111/test?application="); when(invoker.getUrl()).thenReturn(url); filter.invoke(invoker, invocation); verify(invoker).invoke(invocation); String application = RpcContext.getContext().getAttachment(DubboUtils.SENTINEL_DUBBO_APPLICATION_KEY); assertNull(application); }
Example #26
Source File: DubboAppContextFilterTest.java From dubbo-sentinel-support with Apache License 2.0 | 5 votes |
@Test public void testInvokeApplicationKey() { Invoker invoker = mock(Invoker.class); Invocation invocation = mock(Invocation.class); URL url = URL.valueOf("test://test:111/test?application=serviceA"); when(invoker.getUrl()).thenReturn(url); filter.invoke(invoker, invocation); verify(invoker).invoke(invocation); String application = RpcContext.getContext().getAttachment(DubboUtils.SENTINEL_DUBBO_APPLICATION_KEY); assertEquals("serviceA", application); }
Example #27
Source File: SimpleRegistryAnnotationProvider.java From dubbo-samples with Apache License 2.0 | 5 votes |
private static void printServiceData() { List<String> urls = ZkUtil.getChildren(ZkUtil.toUrlPath("providers")); System.out.println("*********************************************************"); urls.stream().map(URL::decode).forEach(System.out::println); System.out.println("not contains 'executes':" + !urls.get(0).contains("executes")); System.out.println("contains 'retries':" + urls.get(0).contains("retries")); System.out.println("contains 'owner':" + urls.get(0).contains("owner")); System.out.println("contains 'timeout(default)':" + urls.get(0).contains("timeout")); System.out.println("contains 'version(default)':" + urls.get(0).contains("version")); System.out.println("contains 'group(default)':" + urls.get(0).contains("group")); System.out.println("contains 'specVersion(default)':" + urls.get(0).contains(RELEASE_KEY)); System.out.println("*********************************************************"); }
Example #28
Source File: AbstractSpringCloudRegistry.java From spring-cloud-alibaba with Apache License 2.0 | 5 votes |
@Override public final void doRegister(URL url) { if (!shouldRegister(url)) { return; } doRegister0(url); }
Example #29
Source File: DubboServiceMetadataRepository.java From spring-cloud-alibaba with Apache License 2.0 | 5 votes |
public void unexportURL(URL url) { String key = url.getServiceKey(); // NPE issue : // https://github.com/spring-cloud-incubator/spring-cloud-alibaba/issues/591 List<URL> urls = allExportedURLs.get(key); if (!isEmpty(urls)) { urls.remove(url); allExportedURLs.addAll(key, urls); } }
Example #30
Source File: ApacheDubboProviderInterceptorTest.java From pinpoint with Apache License 2.0 | 5 votes |
@Test public void createTrace() { doReturn(true).when(trace).canSampled(); doReturn(spanRecorder).when(trace).getSpanRecorder(); doReturn(trace).when(traceContext).newTraceObject(); Invoker invoker = new DubboInvoker(Object.class, new URL("http", "127.0.0.1", 8080), null); ApacheDubboProviderInterceptor interceptor = new ApacheDubboProviderInterceptor(traceContext, descriptor); RpcInvocation rpcInvocation = new RpcInvocation(); rpcInvocation.setInvoker(invoker); rpcInvocation.setMethodName("test"); rpcInvocation.setAttachment(ApacheDubboConstants.META_PARENT_APPLICATION_NAME, UUID.randomUUID().toString()); Object[] args = new Object[]{rpcInvocation}; interceptor.createTrace(invoker, args); }