repo stringclasses 1k
values | file_url stringlengths 96 373 | file_path stringlengths 11 294 | content stringlengths 0 32.8k | language stringclasses 1
value | license stringclasses 6
values | commit_sha stringclasses 1k
values | retrieved_at stringdate 2026-01-04 14:45:56 2026-01-04 18:30:23 | truncated bool 2
classes |
|---|---|---|---|---|---|---|---|---|
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/test/java/org/apache/dubbo/metadata/rest/RestService.java | dubbo-compatible/src/test/java/org/apache/dubbo/metadata/rest/RestService.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.metadata.rest;
import java.util.Map;
/**
* An interface for REST service
*
* @since 2.7.6
*/
public interface RestService {
String param(String param);
String params(int a, String b);
String headers(String header, String header2, Integer param);
String pathVariables(String path1, String path2, String param);
String form(String form);
User requestBodyMap(Map<String, Object> data, String param);
Map<String, Object> requestBodyUser(User user);
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/test/java/org/apache/dubbo/cache/CacheTest.java | dubbo-compatible/src/test/java/org/apache/dubbo/cache/CacheTest.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.cache;
import org.apache.dubbo.rpc.RpcInvocation;
import java.util.List;
import java.util.Map;
import com.alibaba.dubbo.cache.Cache;
import com.alibaba.dubbo.cache.CacheFactory;
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.rpc.Invocation;
import com.alibaba.dubbo.rpc.Invoker;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
class CacheTest {
@Test
void testCacheFactory() {
URL url = URL.valueOf("test://test:11/test?cache=jacache&.cache.write.expire=1");
CacheFactory cacheFactory = new MyCacheFactory();
Invocation invocation = new NullInvocation();
Cache cache = cacheFactory.getCache(url, invocation);
cache.put("testKey", "testValue");
org.apache.dubbo.cache.CacheFactory factory = cacheFactory;
org.apache.dubbo.common.URL u =
org.apache.dubbo.common.URL.valueOf("test://test:11/test?cache=jacache&.cache.write.expire=1");
org.apache.dubbo.rpc.Invocation inv = new RpcInvocation();
org.apache.dubbo.cache.Cache c = factory.getCache(u, inv);
String v = (String) c.get("testKey");
Assertions.assertEquals("testValue", v);
}
static class NullInvocation implements Invocation {
@Override
public String getTargetServiceUniqueName() {
return null;
}
@Override
public String getProtocolServiceKey() {
return null;
}
@Override
public String getMethodName() {
return null;
}
@Override
public Class<?>[] getParameterTypes() {
return new Class[0];
}
@Override
public Object[] getArguments() {
return new Object[0];
}
@Override
public Map<String, String> getAttachments() {
return null;
}
@Override
public String getAttachment(String key) {
return null;
}
@Override
public String getAttachment(String key, String defaultValue) {
return null;
}
@Override
public Invoker<?> getInvoker() {
return null;
}
@Override
public Object put(Object key, Object value) {
return null;
}
@Override
public Object get(Object key) {
return null;
}
@Override
public Map<Object, Object> getAttributes() {
return null;
}
@Override
public void addInvokedInvoker(org.apache.dubbo.rpc.Invoker<?> invoker) {}
@Override
public List<org.apache.dubbo.rpc.Invoker<?>> getInvokedInvokers() {
return null;
}
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/test/java/org/apache/dubbo/cache/MyCache.java | dubbo-compatible/src/test/java/org/apache/dubbo/cache/MyCache.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.cache;
import java.util.HashMap;
import java.util.Map;
import com.alibaba.dubbo.cache.Cache;
import com.alibaba.dubbo.common.URL;
public class MyCache implements Cache {
private Map<Object, Object> map = new HashMap<Object, Object>();
public MyCache(URL url) {}
@Override
public void put(Object key, Object value) {
map.put(key, value);
}
@Override
public Object get(Object key) {
return map.get(key);
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/test/java/org/apache/dubbo/cache/MyCacheFactory.java | dubbo-compatible/src/test/java/org/apache/dubbo/cache/MyCacheFactory.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.cache;
import com.alibaba.dubbo.cache.Cache;
import com.alibaba.dubbo.cache.support.AbstractCacheFactory;
import com.alibaba.dubbo.common.URL;
public class MyCacheFactory extends AbstractCacheFactory {
@Override
protected Cache createCache(URL url) {
return new MyCache(url);
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/test/java/org/apache/dubbo/rpc/RpcContextTest.java | dubbo-compatible/src/test/java/org/apache/dubbo/rpc/RpcContextTest.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.rpc;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Future;
import com.alibaba.dubbo.rpc.RpcContext;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.junit.jupiter.api.Assertions.assertEquals;
class RpcContextTest {
private static final Logger logger = LoggerFactory.getLogger(RpcContextTest.class);
@Test
void testSetFuture() {
CompletableFuture completableFuture = new CompletableFuture();
RpcContext.getContext().setFuture(completableFuture);
CompletableFuture result = FutureContext.getContext().getCompatibleCompletableFuture();
assertEquals(result, completableFuture);
}
@Test
void testSetFutureAlibaba() {
CompletableFuture completableFuture = new CompletableFuture();
RpcContext.getContext().setFuture(completableFuture);
Future future = RpcContext.getContext().getFuture();
logger.info(String.valueOf(future));
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/test/java/org/apache/dubbo/rpc/support/Type.java | dubbo-compatible/src/test/java/org/apache/dubbo/rpc/support/Type.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.rpc.support;
public enum Type {
High,
Normal,
Lower
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/test/java/org/apache/dubbo/rpc/support/Person.java | dubbo-compatible/src/test/java/org/apache/dubbo/rpc/support/Person.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.rpc.support;
import java.io.Serializable;
/**
* Person.java
*/
public class Person implements Serializable {
private static final long serialVersionUID = 1L;
private String name;
private int age;
public Person() {}
public Person(String name, int age) {
this.name = name;
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/test/java/org/apache/dubbo/rpc/support/DemoService.java | dubbo-compatible/src/test/java/org/apache/dubbo/rpc/support/DemoService.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.rpc.support;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
public interface DemoService {
void sayHello(String name);
String echo(String text);
long timestamp();
String getThreadName();
int getSize(String[] strs);
int getSize(Object[] os);
Object invoke(String service, String method) throws Exception;
int stringLength(String str);
Type enumlength(Type... types);
// Type enumlength(Type type);
// String get(CustomArgument arg1);
byte getbyte(byte arg);
Person getPerson(Person person);
String testReturnType(String str);
List<String> testReturnType1(String str);
CompletableFuture<String> testReturnType2(String str);
CompletableFuture<List<String>> testReturnType3(String str);
CompletableFuture testReturnType4(String str);
CompletableFuture<Map<String, String>> testReturnType5(String str);
void $invoke(String s1, String s2);
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/test/java/org/apache/dubbo/rpc/filter/GenericImplFilterTest.java | dubbo-compatible/src/test/java/org/apache/dubbo/rpc/filter/GenericImplFilterTest.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.rpc.filter;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.compact.Dubbo2GenericExceptionUtils;
import org.apache.dubbo.rpc.AppResponse;
import org.apache.dubbo.rpc.AsyncRpcResult;
import org.apache.dubbo.rpc.Invocation;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.Result;
import org.apache.dubbo.rpc.RpcInvocation;
import org.apache.dubbo.rpc.model.ApplicationModel;
import org.apache.dubbo.rpc.support.DemoService;
import org.apache.dubbo.rpc.support.Person;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.when;
class GenericImplFilterTest {
private GenericImplFilter genericImplFilter =
new GenericImplFilter(ApplicationModel.defaultModel().getDefaultModule());
@Test
void testInvokeWithException() throws Exception {
RpcInvocation invocation = new RpcInvocation(
"getPerson",
"org.apache.dubbo.rpc.support.DemoService",
"org.apache.dubbo.rpc.support.DemoService:dubbo",
new Class[] {Person.class},
new Object[] {new Person("dubbo", 10)});
URL url = URL.valueOf("test://test:11/org.apache.dubbo.rpc.support.DemoService?"
+ "accesslog=true&group=dubbo&version=1.1&generic=true");
Invoker invoker = Mockito.mock(Invoker.class);
AppResponse mockRpcResult =
new AppResponse(Dubbo2GenericExceptionUtils.newGenericException(new RuntimeException("failed")));
when(invoker.invoke(any(Invocation.class)))
.thenReturn(AsyncRpcResult.newDefaultAsyncResult(mockRpcResult, invocation));
when(invoker.getUrl()).thenReturn(url);
when(invoker.getInterface()).thenReturn(DemoService.class);
Result asyncResult = genericImplFilter.invoke(invoker, invocation);
Result result = asyncResult.get();
genericImplFilter.onResponse(result, invoker, invocation);
Assertions.assertEquals(RuntimeException.class, result.getException().getClass());
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/test/java/org/apache/dubbo/rpc/cluster/RouterTest.java | dubbo-compatible/src/test/java/org/apache/dubbo/rpc/cluster/RouterTest.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.rpc.cluster;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
class RouterTest {
private static List<Router> routers = new ArrayList<>();
@BeforeAll
public static void setUp() {
CompatibleRouter compatibleRouter = new CompatibleRouter();
routers.add(compatibleRouter);
CompatibleRouter2 compatibleRouter2 = new CompatibleRouter2();
routers.add(compatibleRouter2);
NewRouter newRouter = new NewRouter();
routers.add(newRouter);
}
@Test
void testCompareTo() {
try {
Collections.sort(routers);
Assertions.assertTrue(true);
} catch (Exception e) {
Assertions.assertFalse(false);
}
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/test/java/org/apache/dubbo/rpc/cluster/CompatibleRouter2.java | dubbo-compatible/src/test/java/org/apache/dubbo/rpc/cluster/CompatibleRouter2.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.rpc.cluster;
import java.util.List;
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.rpc.Invocation;
import com.alibaba.dubbo.rpc.Invoker;
import com.alibaba.dubbo.rpc.RpcException;
import com.alibaba.dubbo.rpc.cluster.Router;
public class CompatibleRouter2 implements Router {
@Override
public URL getUrl() {
return null;
}
@Override
public <T> List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation invocation) throws RpcException {
return null;
}
@Override
public int compareTo(Router o) {
return 0;
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/test/java/org/apache/dubbo/rpc/cluster/CompatibleRouter.java | dubbo-compatible/src/test/java/org/apache/dubbo/rpc/cluster/CompatibleRouter.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.rpc.cluster;
import java.util.List;
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.rpc.Invocation;
import com.alibaba.dubbo.rpc.Invoker;
import com.alibaba.dubbo.rpc.RpcException;
import com.alibaba.dubbo.rpc.cluster.Router;
public class CompatibleRouter implements Router {
@Override
public URL getUrl() {
return null;
}
@Override
public <T> List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation invocation) throws RpcException {
return null;
}
@Override
public int compareTo(Router o) {
return 0;
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/test/java/org/apache/dubbo/rpc/cluster/NewRouter.java | dubbo-compatible/src/test/java/org/apache/dubbo/rpc/cluster/NewRouter.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.rpc.cluster;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.rpc.Invocation;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.RpcException;
import java.util.List;
public class NewRouter implements Router {
@Override
public URL getUrl() {
return null;
}
@Override
public <T> List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation invocation) throws RpcException {
return null;
}
@Override
public boolean isRuntime() {
return false;
}
@Override
public boolean isForce() {
return false;
}
@Override
public int getPriority() {
return 0;
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/test/java/org/apache/dubbo/common/extension/ExtensionTest.java | dubbo-compatible/src/test/java/org/apache/dubbo/common/extension/ExtensionTest.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.common.extension;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.extension.activate.ActivateExt1;
import org.apache.dubbo.common.extension.activate.impl.OldActivateExt1Impl2;
import org.apache.dubbo.common.extension.activate.impl.OldActivateExt1Impl3;
import org.apache.dubbo.rpc.model.ApplicationModel;
import java.util.List;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY;
import static org.junit.jupiter.api.Assertions.fail;
class ExtensionTest {
@Test
void testExtensionFactory() {
try {
ExtensionInjector myfactory =
ExtensionLoader.getExtensionLoader(ExtensionInjector.class).getExtension("myfactory");
Assertions.assertTrue(myfactory instanceof ExtensionInjector);
Assertions.assertTrue(myfactory instanceof ExtensionFactory);
Assertions.assertTrue(myfactory instanceof com.alibaba.dubbo.common.extension.ExtensionFactory);
Assertions.assertTrue(myfactory instanceof MyExtensionFactory);
ExtensionInjector spring =
ExtensionLoader.getExtensionLoader(ExtensionInjector.class).getExtension("spring");
Assertions.assertTrue(spring instanceof ExtensionInjector);
Assertions.assertFalse(spring instanceof ExtensionFactory);
Assertions.assertFalse(spring instanceof com.alibaba.dubbo.common.extension.ExtensionFactory);
} catch (IllegalArgumentException expected) {
fail();
}
}
private <T> ExtensionLoader<T> getExtensionLoader(Class<T> type) {
return ApplicationModel.defaultModel().getExtensionDirector().getExtensionLoader(type);
}
@Test
void testLoadActivateExtension() {
// test default
URL url = URL.valueOf("test://localhost/test").addParameter(GROUP_KEY, "old_group");
List<ActivateExt1> list =
getExtensionLoader(ActivateExt1.class).getActivateExtension(url, new String[] {}, "old_group");
Assertions.assertEquals(2, list.size());
Assertions.assertTrue(list.get(0).getClass() == OldActivateExt1Impl2.class
|| list.get(0).getClass() == OldActivateExt1Impl3.class);
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/test/java/org/apache/dubbo/common/extension/MyExtensionFactory.java | dubbo-compatible/src/test/java/org/apache/dubbo/common/extension/MyExtensionFactory.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.common.extension;
import com.alibaba.dubbo.common.extension.ExtensionFactory;
public class MyExtensionFactory implements ExtensionFactory {
@Override
public <T> T getExtension(final Class<T> type, final String name) {
if (type == InjectObject.class) {
return (T) new InjectObject(name);
}
return null;
}
public static class InjectObject {
private final String name;
public InjectObject(final String name) {
this.name = name;
}
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/test/java/org/apache/dubbo/common/extension/MockDispatcher.java | dubbo-compatible/src/test/java/org/apache/dubbo/common/extension/MockDispatcher.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.common.extension;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.remoting.ChannelHandler;
import org.apache.dubbo.remoting.Dispatcher;
public class MockDispatcher implements Dispatcher {
@Override
public ChannelHandler dispatch(ChannelHandler handler, URL url) {
return null;
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/test/java/org/apache/dubbo/common/extension/support/Filter1.java | dubbo-compatible/src/test/java/org/apache/dubbo/common/extension/support/Filter1.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.common.extension.support;
import org.apache.dubbo.common.extension.Activate;
@Activate
public class Filter1 implements Filter0 {}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/test/java/org/apache/dubbo/common/extension/support/Filter2.java | dubbo-compatible/src/test/java/org/apache/dubbo/common/extension/support/Filter2.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.common.extension.support;
import org.apache.dubbo.common.extension.Activate;
@Activate(before = "_1")
public class Filter2 implements Filter0 {}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/test/java/org/apache/dubbo/common/extension/support/Order0Filter2.java | dubbo-compatible/src/test/java/org/apache/dubbo/common/extension/support/Order0Filter2.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.common.extension.support;
import org.apache.dubbo.common.extension.Activate;
@Activate
public class Order0Filter2 implements Order0Filter0 {}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/test/java/org/apache/dubbo/common/extension/support/ActivateComparatorTest.java | dubbo-compatible/src/test/java/org/apache/dubbo/common/extension/support/ActivateComparatorTest.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.common.extension.support;
import org.apache.dubbo.rpc.model.ApplicationModel;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
class ActivateComparatorTest {
private ActivateComparator activateComparator;
@BeforeEach
public void setup() {
activateComparator =
new ActivateComparator(ApplicationModel.defaultModel().getExtensionDirector());
}
@Test
void testActivateComparator() {
Filter1 f1 = new Filter1();
Filter2 f2 = new Filter2();
Filter3 f3 = new Filter3();
Filter4 f4 = new Filter4();
OldFilter5 f5 = new OldFilter5();
List<Class<?>> filters = new ArrayList<>();
filters.add(f1.getClass());
filters.add(f2.getClass());
filters.add(f3.getClass());
filters.add(f4.getClass());
filters.add(f5.getClass());
Collections.sort(filters, activateComparator);
Assertions.assertEquals(f4.getClass(), filters.get(0));
Assertions.assertEquals(f5.getClass(), filters.get(1));
Assertions.assertEquals(f3.getClass(), filters.get(2));
Assertions.assertEquals(f2.getClass(), filters.get(3));
Assertions.assertEquals(f1.getClass(), filters.get(4));
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/test/java/org/apache/dubbo/common/extension/support/Filter0.java | dubbo-compatible/src/test/java/org/apache/dubbo/common/extension/support/Filter0.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.common.extension.support;
import org.apache.dubbo.common.extension.SPI;
@SPI
public interface Filter0 {}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/test/java/org/apache/dubbo/common/extension/support/Filter3.java | dubbo-compatible/src/test/java/org/apache/dubbo/common/extension/support/Filter3.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.common.extension.support;
import org.apache.dubbo.common.extension.Activate;
@Activate(after = "_4")
public class Filter3 implements Filter0 {}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/test/java/org/apache/dubbo/common/extension/support/Filter4.java | dubbo-compatible/src/test/java/org/apache/dubbo/common/extension/support/Filter4.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.common.extension.support;
import org.apache.dubbo.common.extension.Activate;
@Activate(before = "_2")
public class Filter4 implements Filter0 {}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/test/java/org/apache/dubbo/common/extension/support/Order0Filter1.java | dubbo-compatible/src/test/java/org/apache/dubbo/common/extension/support/Order0Filter1.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.common.extension.support;
import org.apache.dubbo.common.extension.Activate;
@Activate
public class Order0Filter1 implements Order0Filter0 {}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/test/java/org/apache/dubbo/common/extension/support/OldFilter0.java | dubbo-compatible/src/test/java/org/apache/dubbo/common/extension/support/OldFilter0.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.common.extension.support;
public interface OldFilter0 extends Filter0 {}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/test/java/org/apache/dubbo/common/extension/support/Order0Filter0.java | dubbo-compatible/src/test/java/org/apache/dubbo/common/extension/support/Order0Filter0.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.common.extension.support;
import org.apache.dubbo.common.extension.SPI;
@SPI
public interface Order0Filter0 {}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/test/java/org/apache/dubbo/common/extension/support/OldFilter5.java | dubbo-compatible/src/test/java/org/apache/dubbo/common/extension/support/OldFilter5.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.common.extension.support;
import com.alibaba.dubbo.common.extension.Activate;
@Activate(after = "_4")
public class OldFilter5 implements OldFilter0 {}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/test/java/org/apache/dubbo/common/extension/activate/ActivateExt1.java | dubbo-compatible/src/test/java/org/apache/dubbo/common/extension/activate/ActivateExt1.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.common.extension.activate;
import org.apache.dubbo.common.extension.SPI;
@SPI("impl1")
public interface ActivateExt1 {
String echo(String msg);
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/test/java/org/apache/dubbo/common/extension/activate/impl/OldActivateExt1Impl3.java | dubbo-compatible/src/test/java/org/apache/dubbo/common/extension/activate/impl/OldActivateExt1Impl3.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.common.extension.activate.impl;
import org.apache.dubbo.common.extension.activate.ActivateExt1;
import com.alibaba.dubbo.common.extension.Activate;
@Activate(group = "old_group")
public class OldActivateExt1Impl3 implements ActivateExt1 {
public String echo(String msg) {
return msg;
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/test/java/org/apache/dubbo/common/extension/activate/impl/OldActivateExt1Impl2.java | dubbo-compatible/src/test/java/org/apache/dubbo/common/extension/activate/impl/OldActivateExt1Impl2.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.common.extension.activate.impl;
import org.apache.dubbo.common.extension.activate.ActivateExt1;
import com.alibaba.dubbo.common.extension.Activate;
@Activate(group = "old_group")
public class OldActivateExt1Impl2 implements ActivateExt1 {
public String echo(String msg) {
return msg;
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/test/java/org/apache/dubbo/common/extension/activate/impl/ActivateExt1Impl1.java | dubbo-compatible/src/test/java/org/apache/dubbo/common/extension/activate/impl/ActivateExt1Impl1.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.common.extension.activate.impl;
import org.apache.dubbo.common.extension.Activate;
import org.apache.dubbo.common.extension.activate.ActivateExt1;
@Activate(
order = 1,
group = {"default_group"})
public class ActivateExt1Impl1 implements ActivateExt1 {
public String echo(String msg) {
return msg;
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/test/java/org/apache/dubbo/common/utils/AnnotationUtilsTest.java | dubbo-compatible/src/test/java/org/apache/dubbo/common/utils/AnnotationUtilsTest.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.common.utils;
import org.apache.dubbo.common.extension.Adaptive;
import org.apache.dubbo.config.annotation.DubboService;
import org.apache.dubbo.config.annotation.Service;
import java.lang.annotation.Annotation;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import org.junit.jupiter.api.Test;
import static java.util.Arrays.asList;
import static org.apache.dubbo.common.utils.AnnotationUtils.excludedType;
import static org.apache.dubbo.common.utils.AnnotationUtils.filterDefaultValues;
import static org.apache.dubbo.common.utils.AnnotationUtils.findAnnotation;
import static org.apache.dubbo.common.utils.AnnotationUtils.findMetaAnnotation;
import static org.apache.dubbo.common.utils.AnnotationUtils.findMetaAnnotations;
import static org.apache.dubbo.common.utils.AnnotationUtils.getAllDeclaredAnnotations;
import static org.apache.dubbo.common.utils.AnnotationUtils.getAllMetaAnnotations;
import static org.apache.dubbo.common.utils.AnnotationUtils.getAnnotation;
import static org.apache.dubbo.common.utils.AnnotationUtils.getAttribute;
import static org.apache.dubbo.common.utils.AnnotationUtils.getAttributes;
import static org.apache.dubbo.common.utils.AnnotationUtils.getDeclaredAnnotations;
import static org.apache.dubbo.common.utils.AnnotationUtils.getDefaultValue;
import static org.apache.dubbo.common.utils.AnnotationUtils.getMetaAnnotations;
import static org.apache.dubbo.common.utils.AnnotationUtils.getValue;
import static org.apache.dubbo.common.utils.AnnotationUtils.isAnnotationPresent;
import static org.apache.dubbo.common.utils.AnnotationUtils.isAnyAnnotationPresent;
import static org.apache.dubbo.common.utils.AnnotationUtils.isSameType;
import static org.apache.dubbo.common.utils.AnnotationUtils.isType;
import static org.apache.dubbo.common.utils.MethodUtils.findMethod;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* {@link AnnotationUtils} Test
*
* @since 2.7.6
*/
class AnnotationUtilsTest {
@Test
void testIsType() {
// null checking
assertFalse(isType(null));
// Method checking
assertFalse(isType(findMethod(A.class, "execute")));
// Class checking
assertTrue(isType(A.class));
}
@Test
void testIsSameType() {
assertTrue(isSameType(A.class.getAnnotation(Service.class), Service.class));
assertFalse(isSameType(A.class.getAnnotation(Service.class), Deprecated.class));
assertFalse(isSameType(A.class.getAnnotation(Service.class), null));
assertFalse(isSameType(null, Deprecated.class));
assertFalse(isSameType(null, null));
}
@Test
void testExcludedType() {
assertFalse(excludedType(Service.class).test(A.class.getAnnotation(Service.class)));
assertTrue(excludedType(Service.class).test(A.class.getAnnotation(Deprecated.class)));
}
@Test
void testGetAttribute() {
Annotation annotation = A.class.getAnnotation(Service.class);
assertEquals("java.lang.CharSequence", getAttribute(annotation, "interfaceName"));
assertEquals(CharSequence.class, getAttribute(annotation, "interfaceClass"));
assertEquals("", getAttribute(annotation, "version"));
assertEquals("", getAttribute(annotation, "group"));
assertEquals("", getAttribute(annotation, "path"));
assertEquals(true, getAttribute(annotation, "export"));
assertEquals(false, getAttribute(annotation, "deprecated"));
}
@Test
void testGetAttributesMap() {
Annotation annotation = A.class.getAnnotation(Service.class);
Map<String, Object> attributes = getAttributes(annotation, false);
assertEquals("java.lang.CharSequence", attributes.get("interfaceName"));
assertEquals(CharSequence.class, attributes.get("interfaceClass"));
assertEquals("", attributes.get("group"));
assertEquals(getDefaultValue(annotation, "export"), attributes.get("export"));
Map<String, Object> filteredAttributes = filterDefaultValues(annotation, attributes);
assertEquals(2, filteredAttributes.size());
assertEquals("java.lang.CharSequence", filteredAttributes.get("interfaceName"));
assertEquals(CharSequence.class, filteredAttributes.get("interfaceClass"));
assertFalse(filteredAttributes.containsKey("group"));
assertFalse(filteredAttributes.containsKey("export"));
Map<String, Object> nonDefaultAttributes = getAttributes(annotation, true);
assertEquals(nonDefaultAttributes, filteredAttributes);
}
@Test
void testGetValue() {
Adaptive adaptive = A.class.getAnnotation(Adaptive.class);
String[] value = getValue(adaptive);
assertEquals(asList("a", "b", "c"), asList(value));
}
@Test
void testGetDeclaredAnnotations() {
List<Annotation> annotations = getDeclaredAnnotations(A.class);
assertADeclaredAnnotations(annotations, 0);
annotations = getDeclaredAnnotations(A.class, a -> isSameType(a, Service.class));
assertEquals(1, annotations.size());
Service service = (Service) annotations.get(0);
assertEquals("java.lang.CharSequence", service.interfaceName());
assertEquals(CharSequence.class, service.interfaceClass());
}
@Test
void testGetAllDeclaredAnnotations() {
List<Annotation> annotations = getAllDeclaredAnnotations(A.class);
assertADeclaredAnnotations(annotations, 0);
annotations = getAllDeclaredAnnotations(B.class);
assertTrue(isSameType(annotations.get(0), Service5.class));
assertADeclaredAnnotations(annotations, 1);
annotations = new LinkedList<>(getAllDeclaredAnnotations(C.class));
assertTrue(isSameType(annotations.get(0), MyAdaptive.class));
assertTrue(isSameType(annotations.get(1), Service5.class));
assertADeclaredAnnotations(annotations, 2);
annotations = getAllDeclaredAnnotations(findMethod(A.class, "execute"));
MyAdaptive myAdaptive = (MyAdaptive) annotations.get(0);
assertArrayEquals(new String[] {"e"}, myAdaptive.value());
annotations = getAllDeclaredAnnotations(findMethod(B.class, "execute"));
Adaptive adaptive = (Adaptive) annotations.get(0);
assertArrayEquals(new String[] {"f"}, adaptive.value());
}
@Test
void testGetMetaAnnotations() {
List<Annotation> metaAnnotations = getMetaAnnotations(Service.class, a -> isSameType(a, Inherited.class));
assertEquals(1, metaAnnotations.size());
assertEquals(Inherited.class, metaAnnotations.get(0).annotationType());
metaAnnotations = getMetaAnnotations(Service.class);
HashSet<Object> set1 = new HashSet<>();
metaAnnotations.forEach(t -> set1.add(t.annotationType()));
HashSet<Object> set2 = new HashSet<>();
set2.add(Inherited.class);
set2.add(Deprecated.class);
assertEquals(2, metaAnnotations.size());
assertEquals(set1, set2);
}
@Test
void testGetAllMetaAnnotations() {
List<Annotation> metaAnnotations = getAllMetaAnnotations(Service5.class);
int offset = 0;
HashSet<Object> set1 = new HashSet<>();
metaAnnotations.forEach(t -> set1.add(t.annotationType()));
HashSet<Object> set2 = new HashSet<>();
set2.add(Inherited.class);
set2.add(DubboService.class);
set2.add(Service4.class);
set2.add(Service3.class);
set2.add(Service2.class);
assertEquals(9, metaAnnotations.size());
assertEquals(set1, set2);
metaAnnotations = getAllMetaAnnotations(MyAdaptive.class);
HashSet<Object> set3 = new HashSet<>();
metaAnnotations.forEach(t -> set3.add(t.annotationType()));
HashSet<Object> set4 = new HashSet<>();
metaAnnotations.forEach(t -> set3.add(t.annotationType()));
set4.add(Inherited.class);
set4.add(Adaptive.class);
assertEquals(2, metaAnnotations.size());
assertEquals(set3, set4);
}
@Test
void testIsAnnotationPresent() {
assertTrue(isAnnotationPresent(A.class, true, Service.class));
assertTrue(
isAnnotationPresent(A.class, true, Service.class, com.alibaba.dubbo.config.annotation.Service.class));
assertTrue(isAnnotationPresent(A.class, Service.class));
assertTrue(isAnnotationPresent(A.class, "org.apache.dubbo.config.annotation.Service"));
assertTrue(AnnotationUtils.isAllAnnotationPresent(
A.class, Service.class, Service.class, com.alibaba.dubbo.config.annotation.Service.class));
assertTrue(isAnnotationPresent(A.class, Deprecated.class));
}
@Test
void testIsAnyAnnotationPresent() {
assertTrue(isAnyAnnotationPresent(
A.class, Service.class, com.alibaba.dubbo.config.annotation.Service.class, Deprecated.class));
assertTrue(isAnyAnnotationPresent(A.class, Service.class, com.alibaba.dubbo.config.annotation.Service.class));
assertTrue(isAnyAnnotationPresent(A.class, Service.class, Deprecated.class));
assertTrue(
isAnyAnnotationPresent(A.class, com.alibaba.dubbo.config.annotation.Service.class, Deprecated.class));
assertTrue(isAnyAnnotationPresent(A.class, Service.class));
assertTrue(isAnyAnnotationPresent(A.class, com.alibaba.dubbo.config.annotation.Service.class));
assertTrue(isAnyAnnotationPresent(A.class, Deprecated.class));
}
@Test
void testGetAnnotation() {
assertNotNull(getAnnotation(A.class, "org.apache.dubbo.config.annotation.Service"));
assertNotNull(getAnnotation(A.class, "com.alibaba.dubbo.config.annotation.Service"));
assertNotNull(getAnnotation(A.class, "org.apache.dubbo.common.extension.Adaptive"));
assertNull(getAnnotation(A.class, "java.lang.Deprecated"));
assertNull(getAnnotation(A.class, "java.lang.String"));
assertNull(getAnnotation(A.class, "NotExistedClass"));
}
@Test
void testFindAnnotation() {
Service service = findAnnotation(A.class, Service.class);
assertEquals("java.lang.CharSequence", service.interfaceName());
assertEquals(CharSequence.class, service.interfaceClass());
service = findAnnotation(B.class, Service.class);
assertEquals(CharSequence.class, service.interfaceClass());
}
@Test
void testFindMetaAnnotations() {
List<DubboService> services = findMetaAnnotations(B.class, DubboService.class);
assertEquals(1, services.size());
DubboService service = services.get(0);
assertEquals("", service.interfaceName());
assertEquals(Cloneable.class, service.interfaceClass());
services = findMetaAnnotations(Service5.class, DubboService.class);
assertEquals(1, services.size());
service = services.get(0);
assertEquals("", service.interfaceName());
assertEquals(Cloneable.class, service.interfaceClass());
}
@Test
void testFindMetaAnnotation() {
DubboService service = findMetaAnnotation(B.class, DubboService.class);
assertEquals(Cloneable.class, service.interfaceClass());
service = findMetaAnnotation(B.class, "org.apache.dubbo.config.annotation.DubboService");
assertEquals(Cloneable.class, service.interfaceClass());
service = findMetaAnnotation(Service5.class, DubboService.class);
assertEquals(Cloneable.class, service.interfaceClass());
}
@Service(interfaceName = "java.lang.CharSequence", interfaceClass = CharSequence.class)
@com.alibaba.dubbo.config.annotation.Service(
interfaceName = "java.lang.CharSequence",
interfaceClass = CharSequence.class)
@Adaptive(value = {"a", "b", "c"})
static class A {
@MyAdaptive("e")
public void execute() {}
}
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE})
@Inherited
@DubboService(interfaceClass = Cloneable.class)
@interface Service2 {}
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE})
@Inherited
@Service2
@interface Service3 {}
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE})
@Inherited
@Service3
@interface Service4 {}
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE})
@Inherited
@Service4
@interface Service5 {}
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.METHOD})
@Inherited
@Adaptive
@interface MyAdaptive {
String[] value() default {};
}
@Service5
static class B extends A {
@Adaptive("f")
@Override
public void execute() {}
}
@MyAdaptive
static class C extends B {}
private void assertADeclaredAnnotations(List<Annotation> annotations, int offset) {
int size = 3 + offset;
assertEquals(size, annotations.size());
boolean apacheServiceFound = false;
boolean alibabaServiceFound = false;
boolean adaptiveFound = false;
for (Annotation annotation : annotations) {
if (!apacheServiceFound && (annotation instanceof Service)) {
assertEquals("java.lang.CharSequence", ((Service) annotation).interfaceName());
assertEquals(CharSequence.class, ((Service) annotation).interfaceClass());
apacheServiceFound = true;
continue;
}
if (!alibabaServiceFound && (annotation instanceof com.alibaba.dubbo.config.annotation.Service)) {
assertEquals(
"java.lang.CharSequence",
((com.alibaba.dubbo.config.annotation.Service) annotation).interfaceName());
assertEquals(
CharSequence.class,
((com.alibaba.dubbo.config.annotation.Service) annotation).interfaceClass());
alibabaServiceFound = true;
continue;
}
if (!adaptiveFound && (annotation instanceof Adaptive)) {
assertArrayEquals(new String[] {"a", "b", "c"}, ((Adaptive) annotation).value());
adaptiveFound = true;
continue;
}
}
assertTrue(apacheServiceFound && alibabaServiceFound && adaptiveFound);
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/test/java/org/apache/dubbo/echo/EchoServiceTest.java | dubbo-compatible/src/test/java/org/apache/dubbo/echo/EchoServiceTest.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.echo;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.extension.ExtensionLoader;
import org.apache.dubbo.rpc.Exporter;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.Protocol;
import org.apache.dubbo.rpc.ProxyFactory;
import org.apache.dubbo.rpc.service.EchoService;
import org.apache.dubbo.service.DemoService;
import org.apache.dubbo.service.DemoServiceImpl;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
class EchoServiceTest {
@Test
void testEcho() {
DemoService server = new DemoServiceImpl();
ProxyFactory proxyFactory =
ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension();
Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension();
URL url = URL.valueOf("dubbo://127.0.0.1:5342/" + DemoService.class.getName() + "?version=1.0.0");
Exporter<DemoService> exporter = protocol.export(proxyFactory.getInvoker(server, DemoService.class, url));
Invoker<DemoService> invoker = protocol.refer(DemoService.class, url);
EchoService client = (EchoService) proxyFactory.getProxy(invoker);
Object result = client.$echo("haha");
Assertions.assertEquals("haha", result);
org.apache.dubbo.rpc.service.EchoService newClient =
(org.apache.dubbo.rpc.service.EchoService) proxyFactory.getProxy(invoker);
Object res = newClient.$echo("hehe");
Assertions.assertEquals("hehe", res);
invoker.destroy();
exporter.unexport();
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/test/java/org/apache/dubbo/config/ProviderConfigTest.java | dubbo-compatible/src/test/java/org/apache/dubbo/config/ProviderConfigTest.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.config;
import java.util.HashMap;
import java.util.Map;
import com.alibaba.dubbo.config.ProviderConfig;
import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasEntry;
import static org.hamcrest.Matchers.hasKey;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
class ProviderConfigTest {
@Test
void testProtocol() {
ProviderConfig provider = new ProviderConfig();
provider.setProtocol("protocol");
assertThat(provider.getProtocol().getName(), equalTo("protocol"));
}
@Test
void testDefault() {
ProviderConfig provider = new ProviderConfig();
provider.setDefault(true);
Map<String, String> parameters = new HashMap<String, String>();
ProviderConfig.appendParameters(parameters, provider);
assertThat(provider.isDefault(), is(true));
assertThat(parameters, not(hasKey("default")));
}
@Test
void testHost() {
ProviderConfig provider = new ProviderConfig();
provider.setHost("demo-host");
Map<String, String> parameters = new HashMap<String, String>();
ProviderConfig.appendParameters(parameters, provider);
assertThat(provider.getHost(), equalTo("demo-host"));
assertThat(parameters, not(hasKey("host")));
}
@Test
void testPort() {
ProviderConfig provider = new ProviderConfig();
provider.setPort(8080);
Map<String, String> parameters = new HashMap<String, String>();
ProviderConfig.appendParameters(parameters, provider);
assertThat(provider.getPort(), is(8080));
assertThat(parameters, not(hasKey("port")));
}
@Test
void testPath() {
ProviderConfig provider = new ProviderConfig();
provider.setPath("/path");
Map<String, String> parameters = new HashMap<String, String>();
ProviderConfig.appendParameters(parameters, provider);
assertThat(provider.getPath(), equalTo("/path"));
assertThat(provider.getContextpath(), equalTo("/path"));
assertThat(parameters, not(hasKey("path")));
}
@Test
void testContextPath() {
ProviderConfig provider = new ProviderConfig();
provider.setContextpath("/context-path");
Map<String, String> parameters = new HashMap<String, String>();
ProviderConfig.appendParameters(parameters, provider);
assertThat(provider.getContextpath(), equalTo("/context-path"));
assertThat(parameters, not(hasKey("/context-path")));
}
@Test
void testThreads() {
ProviderConfig provider = new ProviderConfig();
provider.setThreads(10);
assertThat(provider.getThreads(), is(10));
}
@Test
void testIothreads() {
ProviderConfig provider = new ProviderConfig();
provider.setIothreads(10);
assertThat(provider.getIothreads(), is(10));
}
@Test
void testAlive() {
ProviderConfig provider = new ProviderConfig();
provider.setAlive(10);
assertThat(provider.getAlive(), is(10));
}
@Test
void testQueues() {
ProviderConfig provider = new ProviderConfig();
provider.setQueues(10);
assertThat(provider.getQueues(), is(10));
}
@Test
void testAccepts() {
ProviderConfig provider = new ProviderConfig();
provider.setAccepts(10);
assertThat(provider.getAccepts(), is(10));
}
@Test
void testCharset() throws Exception {
ProviderConfig provider = new ProviderConfig();
provider.setCharset("utf-8");
assertThat(provider.getCharset(), equalTo("utf-8"));
}
@Test
void testPayload() {
ProviderConfig provider = new ProviderConfig();
provider.setPayload(10);
assertThat(provider.getPayload(), is(10));
}
@Test
void testBuffer() {
ProviderConfig provider = new ProviderConfig();
provider.setBuffer(10);
assertThat(provider.getBuffer(), is(10));
}
@Test
void testServer() {
ProviderConfig provider = new ProviderConfig();
provider.setServer("demo-server");
assertThat(provider.getServer(), equalTo("demo-server"));
}
@Test
void testClient() {
ProviderConfig provider = new ProviderConfig();
provider.setClient("client");
assertThat(provider.getClient(), equalTo("client"));
}
@Test
void testPrompt() {
ProviderConfig provider = new ProviderConfig();
provider.setPrompt("#");
Map<String, String> parameters = new HashMap<String, String>();
ProviderConfig.appendParameters(parameters, provider);
assertThat(provider.getPrompt(), equalTo("#"));
assertThat(parameters, hasEntry("prompt", "%23"));
}
@Test
void testDispatcher() {
ProviderConfig provider = new ProviderConfig();
provider.setDispatcher("mockdispatcher");
assertThat(provider.getDispatcher(), equalTo("mockdispatcher"));
}
@Test
void testNetworker() {
ProviderConfig provider = new ProviderConfig();
provider.setNetworker("networker");
assertThat(provider.getNetworker(), equalTo("networker"));
}
@Test
void testWait() {
ProviderConfig provider = new ProviderConfig();
provider.setWait(10);
assertThat(provider.getWait(), equalTo(10));
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/test/java/org/apache/dubbo/config/SignatureTest.java | dubbo-compatible/src/test/java/org/apache/dubbo/config/SignatureTest.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.config;
import org.apache.dubbo.common.utils.IOUtils;
import org.apache.dubbo.common.utils.StringUtils;
import java.io.IOException;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Set;
import java.util.stream.Collectors;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.collection.IsCollectionWithSize.hasSize;
public class SignatureTest {
@ParameterizedTest
@ValueSource(
classes = {
com.alibaba.dubbo.config.ApplicationConfig.class,
com.alibaba.dubbo.config.ArgumentConfig.class,
com.alibaba.dubbo.config.ConsumerConfig.class,
com.alibaba.dubbo.config.MethodConfig.class,
com.alibaba.dubbo.config.ModuleConfig.class,
com.alibaba.dubbo.config.MonitorConfig.class,
com.alibaba.dubbo.config.ProtocolConfig.class,
com.alibaba.dubbo.config.ProviderConfig.class,
com.alibaba.dubbo.config.ReferenceConfig.class,
com.alibaba.dubbo.config.RegistryConfig.class,
com.alibaba.dubbo.config.ServiceConfig.class
})
void test(Class<?> targetClass) throws IOException {
String[] lines = IOUtils.readLines(
this.getClass().getClassLoader().getResourceAsStream("definition/" + targetClass.getName()));
// only compare setter now.
// getter cannot make it compatible with the old version.
Set<String> setters = Arrays.stream(lines)
.filter(StringUtils::isNotEmpty)
.filter(s -> !s.startsWith("//"))
.filter(s -> s.contains("set"))
.collect(Collectors.toSet());
for (Method method : targetClass.getMethods()) {
setters.remove(
method.toString().replace(method.getDeclaringClass().getName() + ".", targetClass.getName() + "."));
}
assertThat(setters.toString(), setters, hasSize(0));
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/test/java/org/apache/dubbo/config/ProtocolConfigTest.java | dubbo-compatible/src/test/java/org/apache/dubbo/config/ProtocolConfigTest.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.config;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import com.alibaba.dubbo.config.ProtocolConfig;
import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasEntry;
import static org.hamcrest.Matchers.is;
class ProtocolConfigTest {
@Test
void testName() throws Exception {
ProtocolConfig protocol = new ProtocolConfig();
protocol.setName("name");
Map<String, String> parameters = new HashMap<String, String>();
ProtocolConfig.appendParameters(parameters, protocol);
assertThat(protocol.getName(), equalTo("name"));
assertThat(protocol.getId(), equalTo(null));
assertThat(parameters.isEmpty(), is(true));
}
@Test
void testHost() throws Exception {
ProtocolConfig protocol = new ProtocolConfig();
protocol.setHost("host");
Map<String, String> parameters = new HashMap<String, String>();
ProtocolConfig.appendParameters(parameters, protocol);
assertThat(protocol.getHost(), equalTo("host"));
assertThat(parameters.isEmpty(), is(true));
}
@Test
void testPort() throws Exception {
ProtocolConfig protocol = new ProtocolConfig();
protocol.setPort(8080);
Map<String, String> parameters = new HashMap<String, String>();
ProtocolConfig.appendParameters(parameters, protocol);
assertThat(protocol.getPort(), equalTo(8080));
assertThat(parameters.isEmpty(), is(true));
}
@Test
void testPath() throws Exception {
ProtocolConfig protocol = new ProtocolConfig();
protocol.setContextpath("context-path");
Map<String, String> parameters = new HashMap<String, String>();
ProtocolConfig.appendParameters(parameters, protocol);
assertThat(protocol.getPath(), equalTo("context-path"));
assertThat(protocol.getContextpath(), equalTo("context-path"));
assertThat(parameters.isEmpty(), is(true));
protocol.setPath("path");
assertThat(protocol.getPath(), equalTo("path"));
assertThat(protocol.getContextpath(), equalTo("path"));
}
@Test
void testThreads() throws Exception {
ProtocolConfig protocol = new ProtocolConfig();
protocol.setThreads(10);
assertThat(protocol.getThreads(), is(10));
}
@Test
void testIothreads() throws Exception {
ProtocolConfig protocol = new ProtocolConfig();
protocol.setIothreads(10);
assertThat(protocol.getIothreads(), is(10));
}
@Test
void testQueues() throws Exception {
ProtocolConfig protocol = new ProtocolConfig();
protocol.setQueues(10);
assertThat(protocol.getQueues(), is(10));
}
@Test
void testAccepts() throws Exception {
ProtocolConfig protocol = new ProtocolConfig();
protocol.setAccepts(10);
assertThat(protocol.getAccepts(), is(10));
}
@Test
void testAccesslog() throws Exception {
ProtocolConfig protocol = new ProtocolConfig();
protocol.setAccesslog("access.log");
assertThat(protocol.getAccesslog(), equalTo("access.log"));
}
@Test
void testRegister() throws Exception {
ProtocolConfig protocol = new ProtocolConfig();
protocol.setRegister(true);
assertThat(protocol.isRegister(), is(true));
}
@Test
void testParameters() throws Exception {
ProtocolConfig protocol = new ProtocolConfig();
protocol.setParameters(Collections.singletonMap("k1", "v1"));
assertThat(protocol.getParameters(), hasEntry("k1", "v1"));
}
@Test
void testDefault() throws Exception {
ProtocolConfig protocol = new ProtocolConfig();
protocol.setDefault(true);
assertThat(protocol.isDefault(), is(true));
}
@Test
void testKeepAlive() throws Exception {
ProtocolConfig protocol = new ProtocolConfig();
protocol.setKeepAlive(true);
assertThat(protocol.getKeepAlive(), is(true));
}
@Test
void testOptimizer() throws Exception {
ProtocolConfig protocol = new ProtocolConfig();
protocol.setOptimizer("optimizer");
assertThat(protocol.getOptimizer(), equalTo("optimizer"));
}
@Test
void testExtension() throws Exception {
ProtocolConfig protocol = new ProtocolConfig();
protocol.setExtension("extension");
assertThat(protocol.getExtension(), equalTo("extension"));
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/test/java/org/apache/dubbo/config/ReferenceConfigTest.java | dubbo-compatible/src/test/java/org/apache/dubbo/config/ReferenceConfigTest.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.config;
import org.apache.dubbo.config.bootstrap.DubboBootstrap;
import org.apache.dubbo.service.DemoService;
import org.apache.dubbo.service.DemoServiceImpl;
import com.alibaba.dubbo.config.ApplicationConfig;
import com.alibaba.dubbo.config.ProtocolConfig;
import com.alibaba.dubbo.config.ReferenceConfig;
import com.alibaba.dubbo.config.RegistryConfig;
import com.alibaba.dubbo.config.ServiceConfig;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
class ReferenceConfigTest {
private ApplicationConfig application = new ApplicationConfig();
private RegistryConfig registry = new RegistryConfig();
private ProtocolConfig protocol = new ProtocolConfig();
@BeforeEach
public void setUp() {
DubboBootstrap.reset();
}
@AfterEach
public void tearDown() {
DubboBootstrap.reset();
}
@Test
void testInjvm() throws Exception {
application.setName("test-protocol-random-port");
registry.setAddress("multicast://224.5.6.7:1234");
protocol.setName("dubbo");
ServiceConfig<DemoService> demoService;
demoService = new ServiceConfig<DemoService>();
demoService.setInterface(DemoService.class);
demoService.setRef(new DemoServiceImpl());
demoService.setApplication(application);
demoService.setRegistry(registry);
demoService.setProtocol(protocol);
ReferenceConfig<DemoService> rc = new ReferenceConfig<DemoService>();
rc.setApplication(application);
rc.setRegistry(registry);
rc.setInterface(DemoService.class.getName());
rc.setInjvm(false);
DubboBootstrap bootstrap = DubboBootstrap.getInstance()
.application(application)
.registry(registry)
.protocol(protocol)
.service(demoService)
.reference(rc);
try {
bootstrap.start();
} finally {
bootstrap.stop();
}
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/test/java/org/apache/dubbo/config/ArgumentConfigTest.java | dubbo-compatible/src/test/java/org/apache/dubbo/config/ArgumentConfigTest.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.config;
import java.util.HashMap;
import java.util.Map;
import com.alibaba.dubbo.config.ArgumentConfig;
import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasEntry;
import static org.hamcrest.Matchers.is;
class ArgumentConfigTest {
@Test
void testIndex() {
ArgumentConfig argument = new ArgumentConfig();
argument.setIndex(1);
assertThat(argument.getIndex(), is(1));
}
@Test
void testType() {
ArgumentConfig argument = new ArgumentConfig();
argument.setType("int");
assertThat(argument.getType(), equalTo("int"));
}
@Test
void testCallback() {
ArgumentConfig argument = new ArgumentConfig();
argument.setCallback(true);
assertThat(argument.isCallback(), is(true));
}
@Test
void testArguments() {
ArgumentConfig argument = new ArgumentConfig();
argument.setIndex(1);
argument.setType("int");
argument.setCallback(true);
Map<String, String> parameters = new HashMap<String, String>();
AbstractServiceConfig.appendParameters(parameters, argument);
assertThat(parameters, hasEntry("callback", "true"));
assertThat(parameters.size(), is(1));
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/test/java/org/apache/dubbo/config/ConfigTest.java | dubbo-compatible/src/test/java/org/apache/dubbo/config/ConfigTest.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.config;
import org.apache.dubbo.config.bootstrap.DubboBootstrap;
import org.apache.dubbo.service.DemoService;
import org.apache.dubbo.service.DemoServiceImpl;
import com.alibaba.dubbo.config.ReferenceConfig;
import com.alibaba.dubbo.config.ServiceConfig;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
class ConfigTest {
private com.alibaba.dubbo.config.ApplicationConfig applicationConfig =
new com.alibaba.dubbo.config.ApplicationConfig("first-dubbo-test");
private com.alibaba.dubbo.config.RegistryConfig registryConfig =
new com.alibaba.dubbo.config.RegistryConfig("multicast://224.5.6.7:1234");
@AfterEach
public void tearDown() {
DubboBootstrap.reset();
}
@BeforeEach
public void setup() {
// In IDE env, make sure adding the following argument to VM options
System.setProperty("java.net.preferIPv4Stack", "true");
DubboBootstrap.reset();
}
@Test
void testConfig() {
com.alibaba.dubbo.config.ServiceConfig<DemoService> service = new ServiceConfig<>();
service.setApplication(applicationConfig);
service.setRegistry(registryConfig);
service.setInterface(DemoService.class);
service.setRef(new DemoServiceImpl());
com.alibaba.dubbo.config.ReferenceConfig<DemoService> reference = new ReferenceConfig<>();
reference.setApplication(applicationConfig);
reference.setRegistry(registryConfig);
reference.setInterface(DemoService.class);
DubboBootstrap bootstrap = DubboBootstrap.getInstance()
.application(applicationConfig)
.registry(registryConfig)
.service(service)
.reference(reference)
.start();
DemoService demoService = bootstrap.getCache().get(reference);
String message = demoService.sayHello("dubbo");
Assertions.assertEquals("hello dubbo", message);
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/test/java/org/apache/dubbo/config/ConsumerConfigTest.java | dubbo-compatible/src/test/java/org/apache/dubbo/config/ConsumerConfigTest.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.config;
import org.apache.dubbo.common.utils.SystemPropertyConfigUtils;
import com.alibaba.dubbo.config.ConsumerConfig;
import org.junit.jupiter.api.Test;
import static org.apache.dubbo.common.constants.CommonConstants.SystemProperty.SYSTEM_TCP_RESPONSE_TIMEOUT;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
class ConsumerConfigTest {
@Test
void testTimeout() throws Exception {
try {
SystemPropertyConfigUtils.clearSystemProperty(SYSTEM_TCP_RESPONSE_TIMEOUT);
ConsumerConfig consumer = new ConsumerConfig();
consumer.setTimeout(10);
assertThat(consumer.getTimeout(), is(10));
assertThat(SystemPropertyConfigUtils.getSystemProperty(SYSTEM_TCP_RESPONSE_TIMEOUT), equalTo("10"));
} finally {
SystemPropertyConfigUtils.clearSystemProperty(SYSTEM_TCP_RESPONSE_TIMEOUT);
}
}
@Test
void testDefault() throws Exception {
ConsumerConfig consumer = new ConsumerConfig();
consumer.setDefault(true);
assertThat(consumer.isDefault(), is(true));
}
@Test
void testClient() throws Exception {
ConsumerConfig consumer = new ConsumerConfig();
consumer.setClient("client");
assertThat(consumer.getClient(), equalTo("client"));
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/test/java/org/apache/dubbo/config/RegistryConfigTest.java | dubbo-compatible/src/test/java/org/apache/dubbo/config/RegistryConfigTest.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.config;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import com.alibaba.dubbo.config.RegistryConfig;
import org.junit.jupiter.api.Test;
import static org.apache.dubbo.common.constants.CommonConstants.SHUTDOWN_WAIT_KEY;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasEntry;
import static org.hamcrest.Matchers.hasKey;
import static org.hamcrest.Matchers.not;
class RegistryConfigTest {
@Test
void testProtocol() throws Exception {
RegistryConfig registry = new RegistryConfig();
registry.setProtocol("protocol");
assertThat(registry.getProtocol(), equalTo(registry.getProtocol()));
}
@Test
void testAddress() throws Exception {
RegistryConfig registry = new RegistryConfig();
registry.setAddress("localhost");
assertThat(registry.getAddress(), equalTo("localhost"));
Map<String, String> parameters = new HashMap<String, String>();
RegistryConfig.appendParameters(parameters, registry);
assertThat(parameters, not(hasKey("address")));
}
@Test
void testUsername() throws Exception {
RegistryConfig registry = new RegistryConfig();
registry.setUsername("username");
assertThat(registry.getUsername(), equalTo("username"));
}
@Test
void testPassword() throws Exception {
RegistryConfig registry = new RegistryConfig();
registry.setPassword("password");
assertThat(registry.getPassword(), equalTo("password"));
}
@Test
void testWait() throws Exception {
RegistryConfig registry = new RegistryConfig();
registry.setWait(10);
assertThat(registry.getWait(), is(10));
assertThat(System.getProperty(SHUTDOWN_WAIT_KEY), equalTo("10"));
}
@Test
void testCheck() throws Exception {
RegistryConfig registry = new RegistryConfig();
registry.setCheck(true);
assertThat(registry.isCheck(), is(true));
}
@Test
void testFile() throws Exception {
RegistryConfig registry = new RegistryConfig();
registry.setFile("file");
assertThat(registry.getFile(), equalTo("file"));
}
@Test
void testTransporter() throws Exception {
RegistryConfig registry = new RegistryConfig();
registry.setTransporter("transporter");
assertThat(registry.getTransporter(), equalTo("transporter"));
}
@Test
void testClient() throws Exception {
RegistryConfig registry = new RegistryConfig();
registry.setClient("client");
assertThat(registry.getClient(), equalTo("client"));
}
@Test
void testTimeout() throws Exception {
RegistryConfig registry = new RegistryConfig();
registry.setTimeout(10);
assertThat(registry.getTimeout(), is(10));
}
@Test
void testSession() throws Exception {
RegistryConfig registry = new RegistryConfig();
registry.setSession(10);
assertThat(registry.getSession(), is(10));
}
@Test
void testDynamic() throws Exception {
RegistryConfig registry = new RegistryConfig();
registry.setDynamic(true);
assertThat(registry.isDynamic(), is(true));
}
@Test
void testRegister() throws Exception {
RegistryConfig registry = new RegistryConfig();
registry.setRegister(true);
assertThat(registry.isRegister(), is(true));
}
@Test
void testSubscribe() throws Exception {
RegistryConfig registry = new RegistryConfig();
registry.setSubscribe(true);
assertThat(registry.isSubscribe(), is(true));
}
@Test
void testCluster() throws Exception {
RegistryConfig registry = new RegistryConfig();
registry.setCluster("cluster");
assertThat(registry.getCluster(), equalTo("cluster"));
}
@Test
void testGroup() throws Exception {
RegistryConfig registry = new RegistryConfig();
registry.setGroup("group");
assertThat(registry.getGroup(), equalTo("group"));
}
@Test
void testVersion() throws Exception {
RegistryConfig registry = new RegistryConfig();
registry.setVersion("1.0.0");
assertThat(registry.getVersion(), equalTo("1.0.0"));
}
@Test
void testParameters() throws Exception {
RegistryConfig registry = new RegistryConfig();
registry.setParameters(Collections.singletonMap("k1", "v1"));
assertThat(registry.getParameters(), hasEntry("k1", "v1"));
Map<String, String> parameters = new HashMap<String, String>();
RegistryConfig.appendParameters(parameters, registry);
assertThat(parameters, hasEntry("k1", "v1"));
}
@Test
void testDefault() throws Exception {
RegistryConfig registry = new RegistryConfig();
registry.setDefault(true);
assertThat(registry.isDefault(), is(true));
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/test/java/org/apache/dubbo/config/ApplicationConfigTest.java | dubbo-compatible/src/test/java/org/apache/dubbo/config/ApplicationConfigTest.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.config;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import com.alibaba.dubbo.config.ApplicationConfig;
import com.alibaba.dubbo.config.MonitorConfig;
import com.alibaba.dubbo.config.RegistryConfig;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import static org.apache.dubbo.common.constants.CommonConstants.APPLICATION_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.DUMP_DIRECTORY;
import static org.apache.dubbo.common.constants.QosConstants.ACCEPT_FOREIGN_IP;
import static org.apache.dubbo.common.constants.QosConstants.QOS_ENABLE;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasEntry;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.sameInstance;
import static org.hamcrest.collection.IsCollectionWithSize.hasSize;
class ApplicationConfigTest {
@Test
void testName() {
ApplicationConfig application = new ApplicationConfig();
application.setName("app");
assertThat(application.getName(), equalTo("app"));
application = new ApplicationConfig("app2");
assertThat(application.getName(), equalTo("app2"));
Map<String, String> parameters = new HashMap<String, String>();
ApplicationConfig.appendParameters(parameters, application);
assertThat(parameters, hasEntry(APPLICATION_KEY, "app2"));
}
@Test
void testVersion() {
ApplicationConfig application = new ApplicationConfig("app");
application.setVersion("1.0.0");
assertThat(application.getVersion(), equalTo("1.0.0"));
Map<String, String> parameters = new HashMap<String, String>();
ApplicationConfig.appendParameters(parameters, application);
assertThat(parameters, hasEntry("application.version", "1.0.0"));
}
@Test
void testOwner() {
ApplicationConfig application = new ApplicationConfig("app");
application.setOwner("owner");
assertThat(application.getOwner(), equalTo("owner"));
}
@Test
void testOrganization() {
ApplicationConfig application = new ApplicationConfig("app");
application.setOrganization("org");
assertThat(application.getOrganization(), equalTo("org"));
}
@Test
void testArchitecture() {
ApplicationConfig application = new ApplicationConfig("app");
application.setArchitecture("arch");
assertThat(application.getArchitecture(), equalTo("arch"));
}
@Test
void testEnvironment1() {
ApplicationConfig application = new ApplicationConfig("app");
application.setEnvironment("develop");
assertThat(application.getEnvironment(), equalTo("develop"));
application.setEnvironment("test");
assertThat(application.getEnvironment(), equalTo("test"));
application.setEnvironment("product");
assertThat(application.getEnvironment(), equalTo("product"));
}
@Test
void testEnvironment2() {
Assertions.assertThrows(IllegalStateException.class, () -> {
ApplicationConfig application = new ApplicationConfig("app");
application.setEnvironment("illegal-env");
});
}
@Test
void testRegistry() {
ApplicationConfig application = new ApplicationConfig("app");
RegistryConfig registry = new RegistryConfig();
application.setRegistry(registry);
assertThat(application.getRegistry(), sameInstance(registry));
application.setRegistries(Collections.singletonList(registry));
assertThat(application.getRegistries(), contains(registry));
assertThat(application.getRegistries(), hasSize(1));
}
@Test
void testMonitor() {
ApplicationConfig application = new ApplicationConfig("app");
application.setMonitor(new MonitorConfig("monitor-addr"));
assertThat(application.getMonitor().getAddress(), equalTo("monitor-addr"));
application.setMonitor("monitor-addr");
assertThat(application.getMonitor().getAddress(), equalTo("monitor-addr"));
}
@Test
void testLogger() {
ApplicationConfig application = new ApplicationConfig("app");
application.setLogger("log4j2");
assertThat(application.getLogger(), equalTo("log4j2"));
}
@Test
void testDefault() {
ApplicationConfig application = new ApplicationConfig("app");
application.setDefault(true);
assertThat(application.isDefault(), is(true));
}
@Test
void testDumpDirectory() {
ApplicationConfig application = new ApplicationConfig("app");
application.setDumpDirectory("/dump");
assertThat(application.getDumpDirectory(), equalTo("/dump"));
Map<String, String> parameters = new HashMap<String, String>();
ApplicationConfig.appendParameters(parameters, application);
assertThat(parameters, hasEntry(DUMP_DIRECTORY, "/dump"));
}
@Test
void testQosEnable() {
ApplicationConfig application = new ApplicationConfig("app");
application.setQosEnable(true);
assertThat(application.getQosEnable(), is(true));
Map<String, String> parameters = new HashMap<String, String>();
ApplicationConfig.appendParameters(parameters, application);
assertThat(parameters, hasEntry(QOS_ENABLE, "true"));
}
@Test
void testQosPort() {
ApplicationConfig application = new ApplicationConfig("app");
application.setQosPort(8080);
assertThat(application.getQosPort(), equalTo(8080));
}
@Test
void testQosAcceptForeignIp() {
ApplicationConfig application = new ApplicationConfig("app");
application.setQosAcceptForeignIp(true);
assertThat(application.getQosAcceptForeignIp(), is(true));
Map<String, String> parameters = new HashMap<String, String>();
ApplicationConfig.appendParameters(parameters, application);
assertThat(parameters, hasEntry(ACCEPT_FOREIGN_IP, "true"));
}
@Test
void testParameters() {
ApplicationConfig application = new ApplicationConfig("app");
application.setQosAcceptForeignIp(true);
Map<String, String> parameters = new HashMap<String, String>();
parameters.put("k1", "v1");
ApplicationConfig.appendParameters(parameters, application);
assertThat(parameters, hasEntry("k1", "v1"));
assertThat(parameters, hasEntry(ACCEPT_FOREIGN_IP, "true"));
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/test/java/org/apache/dubbo/config/ModuleConfigTest.java | dubbo-compatible/src/test/java/org/apache/dubbo/config/ModuleConfigTest.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.config;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import com.alibaba.dubbo.config.ModuleConfig;
import com.alibaba.dubbo.config.MonitorConfig;
import com.alibaba.dubbo.config.RegistryConfig;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasEntry;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.sameInstance;
class ModuleConfigTest {
@Test
void testName2() throws Exception {
ModuleConfig module = new ModuleConfig();
module.setName("module-name");
assertThat(module.getName(), equalTo("module-name"));
assertThat(module.getId(), equalTo(null));
Map<String, String> parameters = new HashMap<String, String>();
ModuleConfig.appendParameters(parameters, module);
assertThat(parameters, hasEntry("module", "module-name"));
}
@Test
void testVersion() throws Exception {
ModuleConfig module = new ModuleConfig();
module.setName("module-name");
module.setVersion("1.0.0");
assertThat(module.getVersion(), equalTo("1.0.0"));
Map<String, String> parameters = new HashMap<String, String>();
ModuleConfig.appendParameters(parameters, module);
assertThat(parameters, hasEntry("module.version", "1.0.0"));
}
@Test
void testOwner() throws Exception {
ModuleConfig module = new ModuleConfig();
module.setOwner("owner");
assertThat(module.getOwner(), equalTo("owner"));
}
@Test
void testOrganization() throws Exception {
ModuleConfig module = new ModuleConfig();
module.setOrganization("org");
assertThat(module.getOrganization(), equalTo("org"));
}
@Test
void testRegistry() throws Exception {
ModuleConfig module = new ModuleConfig();
RegistryConfig registry = new RegistryConfig();
module.setRegistry(registry);
assertThat(module.getRegistry(), sameInstance(registry));
}
@Test
void testRegistries() throws Exception {
ModuleConfig module = new ModuleConfig();
RegistryConfig registry = new RegistryConfig();
module.setRegistries(Collections.singletonList(registry));
assertThat(module.getRegistries(), Matchers.<org.apache.dubbo.config.RegistryConfig>hasSize(1));
assertThat(module.getRegistries(), contains(registry));
}
@Test
void testMonitor() throws Exception {
ModuleConfig module = new ModuleConfig();
module.setMonitor("monitor-addr1");
assertThat(module.getMonitor().getAddress(), equalTo("monitor-addr1"));
module.setMonitor(new MonitorConfig("monitor-addr2"));
assertThat(module.getMonitor().getAddress(), equalTo("monitor-addr2"));
}
@Test
void testDefault() throws Exception {
ModuleConfig module = new ModuleConfig();
module.setDefault(true);
assertThat(module.isDefault(), is(true));
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/test/java/org/apache/dubbo/config/MethodConfigTest.java | dubbo-compatible/src/test/java/org/apache/dubbo/config/MethodConfigTest.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.config;
import org.apache.dubbo.rpc.model.AsyncMethodInfo;
import org.apache.dubbo.service.Person;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import com.alibaba.dubbo.config.ArgumentConfig;
import com.alibaba.dubbo.config.MethodConfig;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Test;
import static org.apache.dubbo.config.Constants.ON_INVOKE_INSTANCE_ATTRIBUTE_KEY;
import static org.apache.dubbo.config.Constants.ON_INVOKE_METHOD_ATTRIBUTE_KEY;
import static org.apache.dubbo.config.Constants.ON_RETURN_INSTANCE_ATTRIBUTE_KEY;
import static org.apache.dubbo.config.Constants.ON_RETURN_METHOD_ATTRIBUTE_KEY;
import static org.apache.dubbo.config.Constants.ON_THROW_INSTANCE_ATTRIBUTE_KEY;
import static org.apache.dubbo.config.Constants.ON_THROW_METHOD_ATTRIBUTE_KEY;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasEntry;
import static org.hamcrest.Matchers.hasKey;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.junit.jupiter.api.Assertions.assertEquals;
class MethodConfigTest {
@Test
void testName() {
MethodConfig method = new MethodConfig();
method.setName("hello");
assertThat(method.getName(), equalTo("hello"));
Map<String, String> parameters = new HashMap<String, String>();
MethodConfig.appendParameters(parameters, method);
assertThat(parameters, not(hasKey("name")));
}
@Test
void testStat() {
MethodConfig method = new MethodConfig();
method.setStat(10);
assertThat(method.getStat(), equalTo(10));
}
@Test
void testRetry() {
MethodConfig method = new MethodConfig();
method.setRetry(true);
assertThat(method.isRetry(), is(true));
}
@Test
void testReliable() {
MethodConfig method = new MethodConfig();
method.setReliable(true);
assertThat(method.isReliable(), is(true));
}
@Test
void testExecutes() {
MethodConfig method = new MethodConfig();
method.setExecutes(10);
assertThat(method.getExecutes(), equalTo(10));
}
@Test
void testDeprecated() {
MethodConfig method = new MethodConfig();
method.setDeprecated(true);
assertThat(method.getDeprecated(), is(true));
}
@Test
void testArguments() {
MethodConfig method = new MethodConfig();
ArgumentConfig argument = new ArgumentConfig();
method.setArguments(Collections.singletonList(argument));
assertThat(method.getArguments(), contains(argument));
assertThat(method.getArguments(), Matchers.<org.apache.dubbo.config.ArgumentConfig>hasSize(1));
}
@Test
void testSticky() {
MethodConfig method = new MethodConfig();
method.setSticky(true);
assertThat(method.getSticky(), is(true));
}
@Test
void testConvertMethodConfig2AsyncInfo() throws Exception {
MethodConfig methodConfig = new MethodConfig();
String methodName = "setName";
methodConfig.setOninvokeMethod(methodName);
methodConfig.setOnthrowMethod(methodName);
methodConfig.setOnreturnMethod(methodName);
methodConfig.setOninvoke(new Person());
methodConfig.setOnthrow(new Person());
methodConfig.setOnreturn(new Person());
AsyncMethodInfo methodInfo = methodConfig.convertMethodConfig2AsyncInfo();
assertEquals(methodInfo.getOninvokeMethod(), Person.class.getMethod(methodName, String.class));
assertEquals(methodInfo.getOnthrowMethod(), Person.class.getMethod(methodName, String.class));
assertEquals(methodInfo.getOnreturnMethod(), Person.class.getMethod(methodName, String.class));
}
// @Test
void testOnreturn() {
MethodConfig method = new MethodConfig();
method.setOnreturn("on-return-object");
assertThat(method.getOnreturn(), equalTo("on-return-object"));
Map<String, String> attributes = new HashMap<>();
MethodConfig.appendAttributes(attributes, method);
assertThat(attributes, hasEntry(ON_RETURN_INSTANCE_ATTRIBUTE_KEY, "on-return-object"));
Map<String, String> parameters = new HashMap<String, String>();
MethodConfig.appendParameters(parameters, method);
assertThat(parameters.size(), is(0));
}
@Test
void testOnreturnMethod() {
MethodConfig method = new MethodConfig();
method.setOnreturnMethod("on-return-method");
assertThat(method.getOnreturnMethod(), equalTo("on-return-method"));
Map<String, String> attributes = new HashMap<>();
MethodConfig.appendAttributes(attributes, method);
assertThat(attributes, hasEntry(ON_RETURN_METHOD_ATTRIBUTE_KEY, "on-return-method"));
Map<String, String> parameters = new HashMap<String, String>();
MethodConfig.appendParameters(parameters, method);
assertThat(parameters.size(), is(0));
}
// @Test
void testOnthrow() {
MethodConfig method = new MethodConfig();
method.setOnthrow("on-throw-object");
assertThat(method.getOnthrow(), equalTo("on-throw-object"));
Map<String, String> attributes = new HashMap<>();
MethodConfig.appendAttributes(attributes, method);
assertThat(attributes, hasEntry(ON_THROW_INSTANCE_ATTRIBUTE_KEY, "on-throw-object"));
Map<String, String> parameters = new HashMap<String, String>();
MethodConfig.appendParameters(parameters, method);
assertThat(parameters.size(), is(0));
}
@Test
void testOnthrowMethod() {
MethodConfig method = new MethodConfig();
method.setOnthrowMethod("on-throw-method");
assertThat(method.getOnthrowMethod(), equalTo("on-throw-method"));
Map<String, String> attributes = new HashMap<>();
MethodConfig.appendAttributes(attributes, method);
assertThat(attributes, hasEntry(ON_THROW_METHOD_ATTRIBUTE_KEY, "on-throw-method"));
Map<String, String> parameters = new HashMap<String, String>();
MethodConfig.appendParameters(parameters, method);
assertThat(parameters.size(), is(0));
}
// @Test
void testOninvoke() {
MethodConfig method = new MethodConfig();
method.setOninvoke("on-invoke-object");
assertThat(method.getOninvoke(), equalTo("on-invoke-object"));
Map<String, String> attributes = new HashMap<>();
MethodConfig.appendAttributes(attributes, method);
assertThat(attributes, hasEntry(ON_INVOKE_INSTANCE_ATTRIBUTE_KEY, "on-invoke-object"));
Map<String, String> parameters = new HashMap<String, String>();
MethodConfig.appendParameters(parameters, method);
assertThat(parameters.size(), is(0));
}
@Test
void testOninvokeMethod() {
MethodConfig method = new MethodConfig();
method.setOninvokeMethod("on-invoke-method");
assertThat(method.getOninvokeMethod(), equalTo("on-invoke-method"));
Map<String, String> attributes = new HashMap<>();
MethodConfig.appendAttributes(attributes, method);
assertThat(attributes, hasEntry(ON_INVOKE_METHOD_ATTRIBUTE_KEY, "on-invoke-method"));
Map<String, String> parameters = new HashMap<String, String>();
MethodConfig.appendParameters(parameters, method);
assertThat(parameters.size(), is(0));
}
@Test
void testReturn() {
MethodConfig method = new MethodConfig();
method.setReturn(true);
assertThat(method.isReturn(), is(true));
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/test/java/org/apache/dubbo/config/spring/beans/factory/annotation/ServiceAnnotationTestConfiguration.java | dubbo-compatible/src/test/java/org/apache/dubbo/config/spring/beans/factory/annotation/ServiceAnnotationTestConfiguration.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.config.spring.beans.factory.annotation;
import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.ProtocolConfig;
import org.apache.dubbo.config.RegistryConfig;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;
import org.springframework.context.annotation.PropertySource;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionException;
import org.springframework.transaction.TransactionStatus;
/**
* {@link Service} Bean
*
* @since 2.6.5
*/
@PropertySource("classpath:/META-INF/default.properties")
public class ServiceAnnotationTestConfiguration {
/**
* Current application configuration, to replace XML config:
* <prev>
* <dubbo:application name="dubbo-demo-application"/>
* </prev>
*
* @return {@link ApplicationConfig} Bean
*/
@Bean("dubbo-demo-application")
public ApplicationConfig applicationConfig() {
ApplicationConfig applicationConfig = new ApplicationConfig();
applicationConfig.setName("dubbo-demo-application");
return applicationConfig;
}
/**
* Current registry center configuration, to replace XML config:
* <prev>
* <dubbo:registry id="my-registry" address="N/A"/>
* </prev>
*
* @return {@link RegistryConfig} Bean
*/
@Bean("my-registry")
public RegistryConfig registryConfig() {
RegistryConfig registryConfig = new RegistryConfig();
registryConfig.setAddress("N/A");
return registryConfig;
}
/**
* Current protocol configuration, to replace XML config:
* <prev>
* <dubbo:protocol name="dubbo" port="12345"/>
* </prev>
*
* @return {@link ProtocolConfig} Bean
*/
@Bean // ("dubbo")
public ProtocolConfig protocolConfig() {
ProtocolConfig protocolConfig = new ProtocolConfig();
protocolConfig.setName("dubbo");
protocolConfig.setPort(12345);
return protocolConfig;
}
@Primary
@Bean
public PlatformTransactionManager platformTransactionManager() {
return new PlatformTransactionManager() {
@Override
public TransactionStatus getTransaction(TransactionDefinition definition) throws TransactionException {
return null;
}
@Override
public void commit(TransactionStatus status) throws TransactionException {}
@Override
public void rollback(TransactionStatus status) throws TransactionException {}
};
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/test/java/org/apache/dubbo/config/spring/filter/MockFilter.java | dubbo-compatible/src/test/java/org/apache/dubbo/config/spring/filter/MockFilter.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.config.spring.filter;
import org.apache.dubbo.rpc.Filter;
import org.apache.dubbo.rpc.Invocation;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.Protocol;
import org.apache.dubbo.rpc.Result;
import org.apache.dubbo.rpc.RpcException;
import org.apache.dubbo.rpc.cluster.LoadBalance;
public class MockFilter implements Filter {
private LoadBalance loadBalance;
private Protocol protocol;
private MockDao mockDao;
public MockDao getMockDao() {
return mockDao;
}
public void setMockDao(MockDao mockDao) {
this.mockDao = mockDao;
}
public LoadBalance getLoadBalance() {
return loadBalance;
}
public void setLoadBalance(LoadBalance loadBalance) {
this.loadBalance = loadBalance;
}
public Protocol getProtocol() {
return protocol;
}
public void setProtocol(Protocol protocol) {
this.protocol = protocol;
}
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
return invoker.invoke(invocation);
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/test/java/org/apache/dubbo/config/spring/filter/MockDaoImpl.java | dubbo-compatible/src/test/java/org/apache/dubbo/config/spring/filter/MockDaoImpl.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.config.spring.filter;
public class MockDaoImpl implements MockDao {}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/test/java/org/apache/dubbo/config/spring/filter/MockDao.java | dubbo-compatible/src/test/java/org/apache/dubbo/config/spring/filter/MockDao.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.config.spring.filter;
public interface MockDao {}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/test/java/org/apache/dubbo/config/spring/api/Box.java | dubbo-compatible/src/test/java/org/apache/dubbo/config/spring/api/Box.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.config.spring.api;
public interface Box {
String getName();
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/test/java/org/apache/dubbo/config/spring/api/DemoService.java | dubbo-compatible/src/test/java/org/apache/dubbo/config/spring/api/DemoService.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.config.spring.api;
public interface DemoService {
String sayName(String name);
Box getBox();
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/test/java/org/apache/dubbo/config/spring/api/HelloService.java | dubbo-compatible/src/test/java/org/apache/dubbo/config/spring/api/HelloService.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.config.spring.api;
public interface HelloService {
String sayHello(String name);
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/test/java/org/apache/dubbo/config/spring/context/annotation/DubboComponentScanRegistrarTest.java | dubbo-compatible/src/test/java/org/apache/dubbo/config/spring/context/annotation/DubboComponentScanRegistrarTest.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.config.spring.context.annotation;
import org.apache.dubbo.config.bootstrap.DubboBootstrap;
import org.apache.dubbo.config.spring.api.DemoService;
import org.apache.dubbo.config.spring.context.annotation.consumer.ConsumerConfiguration;
import org.apache.dubbo.config.spring.context.annotation.provider.DemoServiceImpl;
import org.apache.dubbo.config.spring.context.annotation.provider.ProviderConfiguration;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.aop.support.AopUtils;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.transaction.annotation.Transactional;
import static org.springframework.core.annotation.AnnotationUtils.findAnnotation;
/**
* {@link DubboComponentScanRegistrar} Test
*
* @since 2.5.8
*/
class DubboComponentScanRegistrarTest {
@BeforeEach
public void setUp() {
DubboBootstrap.reset();
}
@AfterEach
public void tearDown() {}
@Test
void test() {
AnnotationConfigApplicationContext providerContext = new AnnotationConfigApplicationContext();
providerContext.register(ProviderConfiguration.class);
providerContext.refresh();
DemoService demoService = providerContext.getBean(DemoService.class);
String value = demoService.sayName("Mercy");
Assertions.assertEquals("Hello,Mercy", value);
Class<?> beanClass = AopUtils.getTargetClass(demoService);
// DemoServiceImpl with @Transactional
Assertions.assertEquals(DemoServiceImpl.class, beanClass);
// Test @Transactional is present or not
Assertions.assertNotNull(findAnnotation(beanClass, Transactional.class));
// consumer app
AnnotationConfigApplicationContext consumerContext = new AnnotationConfigApplicationContext();
consumerContext.register(ConsumerConfiguration.class);
consumerContext.refresh();
ConsumerConfiguration consumerConfiguration = consumerContext.getBean(ConsumerConfiguration.class);
demoService = consumerConfiguration.getDemoService();
value = demoService.sayName("Mercy");
Assertions.assertEquals("Hello,Mercy", value);
ConsumerConfiguration.Child child = consumerContext.getBean(ConsumerConfiguration.Child.class);
// From Child
demoService = child.getDemoServiceFromChild();
Assertions.assertNotNull(demoService);
value = demoService.sayName("Mercy");
Assertions.assertEquals("Hello,Mercy", value);
// From Parent
demoService = child.getDemoServiceFromParent();
Assertions.assertNotNull(demoService);
value = demoService.sayName("Mercy");
Assertions.assertEquals("Hello,Mercy", value);
// From Ancestor
demoService = child.getDemoServiceFromAncestor();
Assertions.assertNotNull(demoService);
value = demoService.sayName("Mercy");
Assertions.assertEquals("Hello,Mercy", value);
providerContext.close();
consumerContext.close();
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/test/java/org/apache/dubbo/config/spring/context/annotation/EnableDubboTest.java | dubbo-compatible/src/test/java/org/apache/dubbo/config/spring/context/annotation/EnableDubboTest.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.config.spring.context.annotation;
import org.apache.dubbo.config.RegistryConfig;
import org.apache.dubbo.config.bootstrap.DubboBootstrap;
import org.apache.dubbo.config.spring.api.DemoService;
import org.apache.dubbo.config.spring.beans.factory.annotation.ServiceAnnotationTestConfiguration;
import org.apache.dubbo.config.spring.context.annotation.consumer.test.TestConsumerConfiguration;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.Primary;
import org.springframework.context.annotation.PropertySource;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionException;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.annotation.EnableTransactionManagement;
/**
* {@link EnableDubbo} Test
*
* @since 2.5.8
*/
class EnableDubboTest {
private AnnotationConfigApplicationContext context;
@BeforeEach
public void setUp() {
context = new AnnotationConfigApplicationContext();
DubboBootstrap.reset();
}
@AfterEach
public void tearDown() {
context.close();
DubboBootstrap.reset();
}
@Test
void testConsumer() {
context.register(TestProviderConfiguration.class, TestConsumerConfiguration.class);
context.refresh();
TestConsumerConfiguration consumerConfiguration = context.getBean(TestConsumerConfiguration.class);
DemoService demoService = consumerConfiguration.getDemoService();
String value = demoService.sayName("Mercy");
Assertions.assertEquals("Hello,Mercy", value);
DemoService autowiredDemoService = consumerConfiguration.getAutowiredDemoService();
Assertions.assertEquals("Hello,Mercy", autowiredDemoService.sayName("Mercy"));
DemoService autowiredReferDemoService = consumerConfiguration.getAutowiredReferDemoService();
Assertions.assertEquals("Hello,Mercy", autowiredReferDemoService.sayName("Mercy"));
TestConsumerConfiguration.Child child = context.getBean(TestConsumerConfiguration.Child.class);
// From Child
demoService = child.getDemoServiceFromChild();
Assertions.assertNotNull(demoService);
value = demoService.sayName("Mercy");
Assertions.assertEquals("Hello,Mercy", value);
// From Parent
demoService = child.getDemoServiceFromParent();
Assertions.assertNotNull(demoService);
value = demoService.sayName("Mercy");
Assertions.assertEquals("Hello,Mercy", value);
// From Ancestor
demoService = child.getDemoServiceFromAncestor();
Assertions.assertNotNull(demoService);
value = demoService.sayName("Mercy");
Assertions.assertEquals("Hello,Mercy", value);
// Test my-registry2 bean presentation
RegistryConfig registryConfig = context.getBean("my-registry", RegistryConfig.class);
// Test multiple binding
Assertions.assertEquals("N/A", registryConfig.getAddress());
}
@EnableDubbo(scanBasePackages = "org.apache.dubbo.config.spring.context.annotation.provider")
@ComponentScan(basePackages = "org.apache.dubbo.config.spring.context.annotation.provider")
@PropertySource("classpath:/META-INF/dubbo-provider.properties")
@Import(ServiceAnnotationTestConfiguration.class)
@EnableTransactionManagement
public static class TestProviderConfiguration {
@Primary
@Bean
public PlatformTransactionManager platformTransactionManager() {
return new PlatformTransactionManager() {
@Override
public TransactionStatus getTransaction(TransactionDefinition definition) throws TransactionException {
return null;
}
@Override
public void commit(TransactionStatus status) throws TransactionException {}
@Override
public void rollback(TransactionStatus status) throws TransactionException {}
};
}
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/test/java/org/apache/dubbo/config/spring/context/annotation/EnableDubboConfigTest.java | dubbo-compatible/src/test/java/org/apache/dubbo/config/spring/context/annotation/EnableDubboConfigTest.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.config.spring.context.annotation;
import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.ConsumerConfig;
import org.apache.dubbo.config.ModuleConfig;
import org.apache.dubbo.config.MonitorConfig;
import org.apache.dubbo.config.ProtocolConfig;
import org.apache.dubbo.config.ProviderConfig;
import org.apache.dubbo.config.RegistryConfig;
import org.apache.dubbo.config.bootstrap.DubboBootstrap;
import org.apache.dubbo.config.context.ConfigManager;
import org.apache.dubbo.rpc.model.ApplicationModel;
import java.util.Collection;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.PropertySource;
import static org.apache.dubbo.config.spring.util.BeanRegistrar.hasAlias;
import static org.junit.jupiter.api.Assertions.assertFalse;
/**
* {@link EnableDubboConfig} Test
*
* @since 2.5.8
*/
class EnableDubboConfigTest {
@BeforeEach
public void setUp() {
DubboBootstrap.reset();
}
@AfterEach
public void tearDown() {
DubboBootstrap.reset();
}
// @Test
public void testSingle() {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
context.register(TestConfig.class);
context.refresh();
// application
ApplicationConfig applicationConfig = context.getBean("applicationBean", ApplicationConfig.class);
Assertions.assertEquals("dubbo-demo-application", applicationConfig.getName());
// module
ModuleConfig moduleConfig = context.getBean("moduleBean", ModuleConfig.class);
Assertions.assertEquals("dubbo-demo-module", moduleConfig.getName());
// registry
RegistryConfig registryConfig = context.getBean(RegistryConfig.class);
Assertions.assertEquals("zookeeper://192.168.99.100:32770", registryConfig.getAddress());
// protocol
ProtocolConfig protocolConfig = context.getBean(ProtocolConfig.class);
Assertions.assertEquals("dubbo", protocolConfig.getName());
Assertions.assertEquals(Integer.valueOf(20880), protocolConfig.getPort());
// monitor
MonitorConfig monitorConfig = context.getBean(MonitorConfig.class);
Assertions.assertEquals("zookeeper://127.0.0.1:32770", monitorConfig.getAddress());
// provider
ProviderConfig providerConfig = context.getBean(ProviderConfig.class);
Assertions.assertEquals("127.0.0.1", providerConfig.getHost());
// consumer
ConsumerConfig consumerConfig = context.getBean(ConsumerConfig.class);
Assertions.assertEquals("netty", consumerConfig.getClient());
// asserts aliases
assertFalse(hasAlias(context, "org.apache.dubbo.config.RegistryConfig#0", "zookeeper"));
assertFalse(hasAlias(context, "org.apache.dubbo.config.MonitorConfig#0", "zookeeper"));
}
// @Test
public void testMultiple() {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
context.register(TestMultipleConfig.class);
context.refresh();
RegistryConfig registry1 = context.getBean("registry1", RegistryConfig.class);
Assertions.assertEquals(2181, registry1.getPort());
RegistryConfig registry2 = context.getBean("registry2", RegistryConfig.class);
Assertions.assertEquals(2182, registry2.getPort());
ConfigManager configManager = ApplicationModel.defaultModel().getApplicationConfigManager();
Collection<ProtocolConfig> protocolConfigs = configManager.getProtocols();
Assertions.assertEquals(3, protocolConfigs.size());
configManager.getProtocol("dubbo").get();
configManager.getProtocol("rest").get();
// asserts aliases
// assertTrue(hasAlias(context, "applicationBean2", "dubbo-demo-application2"));
// assertTrue(hasAlias(context, "applicationBean3", "dubbo-demo-application3"));
}
@EnableDubboConfig
@PropertySource("META-INF/config.properties")
private static class TestMultipleConfig {}
@EnableDubboConfig(multiple = false)
@PropertySource("META-INF/config.properties")
private static class TestConfig {}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/test/java/org/apache/dubbo/config/spring/context/annotation/DubboConfigConfigurationTest.java | dubbo-compatible/src/test/java/org/apache/dubbo/config/spring/context/annotation/DubboConfigConfigurationTest.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.config.spring.context.annotation;
import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.ModuleConfig;
import org.apache.dubbo.config.ProtocolConfig;
import org.apache.dubbo.config.RegistryConfig;
import org.apache.dubbo.config.bootstrap.DubboBootstrap;
import java.io.IOException;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.core.io.support.ResourcePropertySource;
/**
* {@link DubboConfigConfiguration} Test
*
* @since 2.5.8
*/
class DubboConfigConfigurationTest {
private AnnotationConfigApplicationContext context;
@BeforeEach
public void before() throws IOException {
DubboBootstrap.reset();
context = new AnnotationConfigApplicationContext();
ResourcePropertySource propertySource = new ResourcePropertySource("META-INF/config.properties");
context.getEnvironment().getPropertySources().addFirst(propertySource);
}
@AfterEach
public void after() {
context.close();
}
@Test
void testSingle() throws IOException {
context.register(DubboConfigConfiguration.Single.class);
context.refresh();
// application
ApplicationConfig applicationConfig = context.getBean("applicationBean", ApplicationConfig.class);
Assertions.assertEquals("dubbo-demo-application", applicationConfig.getName());
// module
ModuleConfig moduleConfig = context.getBean("moduleBean", ModuleConfig.class);
Assertions.assertEquals("dubbo-demo-module", moduleConfig.getName());
// registry
RegistryConfig registryConfig = context.getBean(RegistryConfig.class);
Assertions.assertEquals("zookeeper://192.168.99.100:32770", registryConfig.getAddress());
// protocol
ProtocolConfig protocolConfig = context.getBean(ProtocolConfig.class);
Assertions.assertEquals("dubbo", protocolConfig.getName());
Assertions.assertEquals(Integer.valueOf(20880), protocolConfig.getPort());
}
@Test
void testMultiple() {
context.register(DubboConfigConfiguration.Multiple.class);
context.refresh();
RegistryConfig registry1 = context.getBean("registry1", RegistryConfig.class);
Assertions.assertEquals(2181, registry1.getPort());
RegistryConfig registry2 = context.getBean("registry2", RegistryConfig.class);
Assertions.assertEquals(2182, registry2.getPort());
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/test/java/org/apache/dubbo/config/spring/context/annotation/provider/ProviderConfiguration.java | dubbo-compatible/src/test/java/org/apache/dubbo/config/spring/context/annotation/provider/ProviderConfiguration.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.config.spring.context.annotation.provider;
import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.ProtocolConfig;
import org.apache.dubbo.config.RegistryConfig;
import org.apache.dubbo.config.spring.context.annotation.DubboComponentScan;
import java.util.UUID;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;
import org.springframework.context.annotation.PropertySource;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionException;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.transaction.support.AbstractPlatformTransactionManager;
import org.springframework.transaction.support.DefaultTransactionStatus;
@DubboComponentScan(basePackages = "org.apache.dubbo.config.spring.context.annotation.provider")
@PropertySource("classpath:/META-INF/default.properties")
@EnableTransactionManagement
public class ProviderConfiguration {
/**
* Current application configuration, to replace XML config:
* <prev>
* <dubbo:application name="dubbo-demo-application"/>
* </prev>
*
* @return {@link ApplicationConfig} Bean
*/
@Bean("dubbo-demo-application")
public ApplicationConfig applicationConfig() {
ApplicationConfig applicationConfig = new ApplicationConfig();
applicationConfig.setName("dubbo-demo-application");
return applicationConfig;
}
/**
* Current registry center configuration, to replace XML config:
* <prev>
* <dubbo:registry id="my-registry" address="N/A"/>
* </prev>
*
* @return {@link RegistryConfig} Bean
*/
@Bean("my-registry")
public RegistryConfig registryConfig() {
RegistryConfig registryConfig = new RegistryConfig();
registryConfig.setAddress("N/A");
return registryConfig;
}
/**
* Current protocol configuration, to replace XML config:
* <prev>
* <dubbo:protocol name="dubbo" port="12345"/>
* </prev>
*
* @return {@link ProtocolConfig} Bean
*/
@Bean("dubbo")
public ProtocolConfig protocolConfig() {
ProtocolConfig protocolConfig = new ProtocolConfig();
protocolConfig.setName("dubbo");
protocolConfig.setPort(12345);
return protocolConfig;
}
@Primary
@Bean
public PlatformTransactionManager platformTransactionManager() {
return new AbstractPlatformTransactionManager() {
private Logger logger = LoggerFactory.getLogger("TestPlatformTransactionManager");
@Override
protected Object doGetTransaction() throws TransactionException {
String transaction = "transaction_" + UUID.randomUUID().toString();
logger.info("Create transaction: " + transaction);
return transaction;
}
@Override
protected void doBegin(Object transaction, TransactionDefinition definition) throws TransactionException {
logger.info("Begin transaction: " + transaction);
}
@Override
protected void doCommit(DefaultTransactionStatus status) throws TransactionException {
logger.info("Commit transaction: " + status.getTransaction());
}
@Override
protected void doRollback(DefaultTransactionStatus status) throws TransactionException {
logger.info("Rollback transaction: " + status.getTransaction());
}
};
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/test/java/org/apache/dubbo/config/spring/context/annotation/provider/DemoServiceImpl.java | dubbo-compatible/src/test/java/org/apache/dubbo/config/spring/context/annotation/provider/DemoServiceImpl.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.config.spring.context.annotation.provider;
import org.apache.dubbo.config.annotation.Method;
import org.apache.dubbo.config.spring.api.Box;
import org.apache.dubbo.config.spring.api.DemoService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
/**
* {@link DemoService} Service implementation
*
* @since 2.5.8
*/
@org.apache.dubbo.config.annotation.Service(
version = "2.5.7",
application = "${demo.service.application}",
protocol = "${demo.service.protocol}",
registry = "${demo.service.registry}",
methods = @Method(timeout = 100, name = "sayName"))
@Service
@Transactional
public class DemoServiceImpl implements DemoService {
@Override
public String sayName(String name) {
return "Hello," + name;
}
@Override
public Box getBox() {
throw new UnsupportedOperationException("For Purposes!");
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/test/java/org/apache/dubbo/config/spring/context/annotation/provider/HelloServiceImpl.java | dubbo-compatible/src/test/java/org/apache/dubbo/config/spring/context/annotation/provider/HelloServiceImpl.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.config.spring.context.annotation.provider;
import org.apache.dubbo.config.spring.api.HelloService;
import com.alibaba.dubbo.config.annotation.Service;
/**
* {@link HelloService} Implementation just annotating Dubbo's {@link Service}
*
* @since 2.5.9
*/
@Service(interfaceName = "org.apache.dubbo.config.spring.api.HelloService", version = "2")
public class HelloServiceImpl implements HelloService {
@Override
public String sayHello(String name) {
return "Hello, " + name;
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/test/java/org/apache/dubbo/config/spring/context/annotation/provider/DefaultHelloService.java | dubbo-compatible/src/test/java/org/apache/dubbo/config/spring/context/annotation/provider/DefaultHelloService.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.config.spring.context.annotation.provider;
import org.apache.dubbo.config.annotation.DubboService;
import org.apache.dubbo.config.spring.api.HelloService;
import org.springframework.stereotype.Service;
/**
* Default {@link HelloService} annotation with Spring's {@link Service}
* and Dubbo's {@link org.apache.dubbo.config.annotation.Service}
*
*/
@Service
@DubboService
public class DefaultHelloService implements HelloService {
@Override
public String sayHello(String name) {
return "Greeting, " + name;
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/test/java/org/apache/dubbo/config/spring/context/annotation/consumer/ConsumerConfiguration.java | dubbo-compatible/src/test/java/org/apache/dubbo/config/spring/context/annotation/consumer/ConsumerConfiguration.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.config.spring.context.annotation.consumer;
import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.RegistryConfig;
import org.apache.dubbo.config.annotation.Reference;
import org.apache.dubbo.config.spring.api.DemoService;
import org.apache.dubbo.config.spring.context.annotation.DubboComponentScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
@Configuration("consumerConfiguration")
@DubboComponentScan(basePackageClasses = ConsumerConfiguration.class)
@PropertySource("META-INF/default.properties")
public class ConsumerConfiguration {
private static final String remoteURL = "dubbo://127.0.0.1:12345?version=2.5.7";
/**
* Current application configuration, to replace XML config:
* <prev>
* <dubbo:application name="dubbo-demo-application"/>
* </prev>
*
* @return {@link ApplicationConfig} Bean
*/
@Bean("dubbo-demo-application")
public ApplicationConfig applicationConfig() {
ApplicationConfig applicationConfig = new ApplicationConfig();
applicationConfig.setName("dubbo-demo-application");
return applicationConfig;
}
/**
* Current registry center configuration, to replace XML config:
* <prev>
* <dubbo:registry address="N/A"/>
* </prev>
*
* @return {@link RegistryConfig} Bean
*/
@Bean
public RegistryConfig registryConfig() {
RegistryConfig registryConfig = new RegistryConfig();
registryConfig.setAddress("N/A");
return registryConfig;
}
@Autowired
private DemoService demoServiceFromAncestor;
@Reference(version = "2.5.7", url = remoteURL)
private DemoService demoService;
public DemoService getDemoService() {
return demoService;
}
public void setDemoService(DemoService demoService) {
this.demoService = demoService;
}
@Bean
public Child c() {
return new Child();
}
public abstract static class Ancestor {
@Reference(version = "2.5.7", url = remoteURL)
private DemoService demoServiceFromAncestor;
public DemoService getDemoServiceFromAncestor() {
return demoServiceFromAncestor;
}
public void setDemoServiceFromAncestor(DemoService demoServiceFromAncestor) {
this.demoServiceFromAncestor = demoServiceFromAncestor;
}
}
public abstract static class Parent extends Ancestor {
private DemoService demoServiceFromParent;
public DemoService getDemoServiceFromParent() {
return demoServiceFromParent;
}
@Reference(version = "2.5.7", url = remoteURL)
public void setDemoServiceFromParent(DemoService demoServiceFromParent) {
this.demoServiceFromParent = demoServiceFromParent;
}
}
public static class Child extends Parent {
@Autowired
private DemoService demoService;
@Reference(version = "2.5.7", url = remoteURL)
private DemoService demoServiceFromChild;
public DemoService getDemoService() {
return demoService;
}
public DemoService getDemoServiceFromChild() {
return demoServiceFromChild;
}
public void setDemoServiceFromChild(DemoService demoServiceFromChild) {
this.demoServiceFromChild = demoServiceFromChild;
}
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/test/java/org/apache/dubbo/config/spring/context/annotation/consumer/test/TestConsumerConfiguration.java | dubbo-compatible/src/test/java/org/apache/dubbo/config/spring/context/annotation/consumer/test/TestConsumerConfiguration.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.config.spring.context.annotation.consumer.test;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.config.annotation.Reference;
import org.apache.dubbo.config.spring.api.DemoService;
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.PropertySource;
import org.springframework.transaction.annotation.EnableTransactionManagement;
/**
* Test Consumer Configuration
*
* @since 2.5.7
*/
@EnableDubbo(scanBasePackageClasses = TestConsumerConfiguration.class)
@PropertySource("classpath:/META-INF/dubbb-consumer.properties")
@EnableTransactionManagement
public class TestConsumerConfiguration {
private static final String remoteURL = "dubbo://127.0.0.1:12345?version=2.5.7";
@Reference(
id = "demoService",
version = "2.5.7",
url = remoteURL,
application = "dubbo-demo-application",
filter = "mymock")
private DemoService demoService;
@Autowired
@Qualifier("demoServiceImpl")
private DemoService autowiredDemoService;
@Autowired
@Qualifier("demoService")
private DemoService autowiredReferDemoService;
public DemoService getAutowiredDemoService() {
return autowiredDemoService;
}
public DemoService getAutowiredReferDemoService() {
return autowiredReferDemoService;
}
public DemoService getDemoService() {
return demoService;
}
public void setDemoService(DemoService demoService) {
this.demoService = demoService;
}
@Bean
public Child c() {
return new Child();
}
public abstract static class Ancestor {
@DubboReference(version = "2.5.7", url = remoteURL, filter = "mymock", application = "dubbo-demo-application")
private DemoService demoServiceFromAncestor;
public DemoService getDemoServiceFromAncestor() {
return demoServiceFromAncestor;
}
public void setDemoServiceFromAncestor(DemoService demoServiceFromAncestor) {
this.demoServiceFromAncestor = demoServiceFromAncestor;
}
}
public abstract static class Parent extends Ancestor {
private DemoService demoServiceFromParent;
public DemoService getDemoServiceFromParent() {
return demoServiceFromParent;
}
@com.alibaba.dubbo.config.annotation.Reference(
version = "2.5.7",
url = remoteURL,
filter = "mymock",
application = "dubbo-demo-application")
public void setDemoServiceFromParent(DemoService demoServiceFromParent) {
this.demoServiceFromParent = demoServiceFromParent;
}
}
public static class Child extends Parent {
@Reference(version = "2.5.7", url = remoteURL, filter = "mymock", application = "dubbo-demo-application")
private DemoService demoServiceFromChild;
public DemoService getDemoServiceFromChild() {
return demoServiceFromChild;
}
public void setDemoServiceFromChild(DemoService demoServiceFromChild) {
this.demoServiceFromChild = demoServiceFromChild;
}
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/test/java/org/apache/dubbo/serialization/MySerialization.java | dubbo-compatible/src/test/java/org/apache/dubbo/serialization/MySerialization.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.serialization;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.common.serialize.ObjectInput;
import com.alibaba.dubbo.common.serialize.ObjectOutput;
import com.alibaba.dubbo.common.serialize.Serialization;
public class MySerialization implements Serialization {
@Override
public ObjectOutput serialize(URL url, OutputStream output) throws IOException {
return new MyObjectOutput(output);
}
@Override
public ObjectInput deserialize(URL url, InputStream input) throws IOException {
return new MyObjectInput(input);
}
@Override
public byte getContentTypeId() {
return 101;
}
@Override
public String getContentType() {
return "x-application/my";
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/test/java/org/apache/dubbo/serialization/MyObjectOutput.java | dubbo-compatible/src/test/java/org/apache/dubbo/serialization/MyObjectOutput.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.serialization;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import com.alibaba.dubbo.common.serialize.ObjectOutput;
public class MyObjectOutput implements ObjectOutput {
private final BufferedWriter writer;
public MyObjectOutput(OutputStream outputStream) {
writer = new BufferedWriter(new OutputStreamWriter(outputStream));
}
@Override
public void writeObject(Object obj) throws IOException {}
@Override
public void writeBool(boolean v) throws IOException {}
@Override
public void writeByte(byte v) throws IOException {}
@Override
public void writeShort(short v) throws IOException {}
@Override
public void writeInt(int v) throws IOException {}
@Override
public void writeLong(long v) throws IOException {}
@Override
public void writeFloat(float v) throws IOException {}
@Override
public void writeDouble(double v) throws IOException {}
@Override
public void writeUTF(String v) throws IOException {
writer.write(v);
writer.write('\n');
}
@Override
public void writeBytes(byte[] v) throws IOException {}
@Override
public void writeBytes(byte[] v, int off, int len) throws IOException {}
@Override
public void flushBuffer() throws IOException {
writer.flush();
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/test/java/org/apache/dubbo/serialization/MyObjectInput.java | dubbo-compatible/src/test/java/org/apache/dubbo/serialization/MyObjectInput.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.serialization;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.Type;
import com.alibaba.dubbo.common.serialize.ObjectInput;
public class MyObjectInput implements ObjectInput {
private final BufferedReader reader;
public MyObjectInput(InputStream inputStream) {
this.reader = new BufferedReader(new InputStreamReader(inputStream));
}
@Override
public Object readObject() throws IOException, ClassNotFoundException {
return null;
}
@Override
public <T> T readObject(Class<T> cls) throws IOException, ClassNotFoundException {
return null;
}
@Override
public <T> T readObject(Class<T> cls, Type type) throws IOException, ClassNotFoundException {
return null;
}
@Override
public boolean readBool() throws IOException {
return false;
}
@Override
public byte readByte() throws IOException {
return 0;
}
@Override
public short readShort() throws IOException {
return 0;
}
@Override
public int readInt() throws IOException {
return 0;
}
@Override
public long readLong() throws IOException {
return 0;
}
@Override
public float readFloat() throws IOException {
return 0;
}
@Override
public double readDouble() throws IOException {
return 0;
}
@Override
public String readUTF() throws IOException {
return reader.readLine();
}
@Override
public byte[] readBytes() throws IOException {
return new byte[0];
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/test/java/org/apache/dubbo/serialization/SerializationTest.java | dubbo-compatible/src/test/java/org/apache/dubbo/serialization/SerializationTest.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.serialization;
import org.apache.dubbo.common.serialize.ObjectInput;
import org.apache.dubbo.common.serialize.ObjectOutput;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import org.hamcrest.CoreMatchers;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledOnOs;
import org.junit.jupiter.api.condition.OS;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.mockito.Mockito.mock;
class SerializationTest {
private MySerialization mySerialization;
private MyObjectOutput myObjectOutput;
private MyObjectInput myObjectInput;
private ByteArrayOutputStream byteArrayOutputStream;
private ByteArrayInputStream byteArrayInputStream;
@BeforeEach
public void setUp() throws Exception {
this.mySerialization = new MySerialization();
this.byteArrayOutputStream = new ByteArrayOutputStream();
this.myObjectOutput = new MyObjectOutput(byteArrayOutputStream);
}
@Test
void testContentType() {
assertThat(mySerialization.getContentType(), is("x-application/my"));
}
@Test
void testContentTypeId() {
assertThat(mySerialization.getContentTypeId(), is((byte) 101));
}
@Test
void testObjectOutput() throws IOException {
ObjectOutput objectOutput = mySerialization.serialize(null, mock(OutputStream.class));
assertThat(objectOutput, Matchers.<ObjectOutput>instanceOf(MyObjectOutput.class));
}
@Test
void testObjectInput() throws IOException {
ObjectInput objectInput = mySerialization.deserialize(null, mock(InputStream.class));
assertThat(objectInput, Matchers.<ObjectInput>instanceOf(MyObjectInput.class));
}
@Test
@DisabledOnOs(OS.WINDOWS) // Charset maynot UTF-8 on Windows JDK 8 ~ 17
void testWriteUTF() throws IOException {
myObjectOutput.writeUTF("Pace");
myObjectOutput.writeUTF("和平");
myObjectOutput.writeUTF(" Мир");
flushToInput();
assertThat(myObjectInput.readUTF(), CoreMatchers.is("Pace"));
assertThat(myObjectInput.readUTF(), CoreMatchers.is("和平"));
assertThat(myObjectInput.readUTF(), CoreMatchers.is(" Мир"));
}
private void flushToInput() throws IOException {
this.myObjectOutput.flushBuffer();
this.byteArrayInputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
this.myObjectInput = new MyObjectInput(byteArrayInputStream);
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/main/java/com/alibaba/dubbo/validation/Validator.java | dubbo-compatible/src/main/java/com/alibaba/dubbo/validation/Validator.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.validation;
@Deprecated
public interface Validator extends org.apache.dubbo.validation.Validator {}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/main/java/com/alibaba/dubbo/validation/Validation.java | dubbo-compatible/src/main/java/com/alibaba/dubbo/validation/Validation.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.validation;
@Deprecated
public interface Validation extends org.apache.dubbo.validation.Validation {}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/main/java/com/alibaba/dubbo/cache/CacheFactory.java | dubbo-compatible/src/main/java/com/alibaba/dubbo/cache/CacheFactory.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.cache;
import com.alibaba.dubbo.common.DelegateURL;
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.rpc.Invocation;
@Deprecated
public interface CacheFactory extends org.apache.dubbo.cache.CacheFactory {
Cache getCache(URL url, Invocation invocation);
default org.apache.dubbo.cache.Cache getCache(
org.apache.dubbo.common.URL url, org.apache.dubbo.rpc.Invocation invocation) {
return this.getCache(new DelegateURL(url), new Invocation.CompatibleInvocation(invocation));
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/main/java/com/alibaba/dubbo/cache/Cache.java | dubbo-compatible/src/main/java/com/alibaba/dubbo/cache/Cache.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.cache;
@Deprecated
public interface Cache extends org.apache.dubbo.cache.Cache {}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/main/java/com/alibaba/dubbo/cache/support/AbstractCacheFactory.java | dubbo-compatible/src/main/java/com/alibaba/dubbo/cache/support/AbstractCacheFactory.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.cache.support;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import com.alibaba.dubbo.cache.Cache;
import com.alibaba.dubbo.cache.CacheFactory;
import com.alibaba.dubbo.common.DelegateURL;
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.rpc.Invocation;
import static org.apache.dubbo.common.constants.CommonConstants.METHOD_KEY;
@Deprecated
public abstract class AbstractCacheFactory implements CacheFactory {
private final ConcurrentMap<String, Cache> caches = new ConcurrentHashMap<>();
@Override
public Cache getCache(URL url, Invocation invocation) {
url = url.addParameter(METHOD_KEY, invocation.getMethodName());
String key = url.toFullString();
Cache cache = caches.get(key);
if (cache == null) {
caches.put(key, createCache(url));
cache = caches.get(key);
}
return cache;
}
protected abstract Cache createCache(URL url);
@Override
public org.apache.dubbo.cache.Cache getCache(
org.apache.dubbo.common.URL url, org.apache.dubbo.rpc.Invocation invocation) {
return getCache(new DelegateURL(url), new Invocation.CompatibleInvocation(invocation));
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/main/java/com/alibaba/dubbo/container/page/Page.java | dubbo-compatible/src/main/java/com/alibaba/dubbo/container/page/Page.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.container.page;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class Page {
private final String navigation;
private final String title;
private final List<String> columns;
private final List<List<String>> rows;
public Page(String navigation) {
this(navigation, (String) null, (String[]) null, (List<List<String>>) null);
}
public Page(String navigation, String title, String column, String row) {
this(
navigation,
title,
column == null ? null : Arrays.asList(new String[] {column}),
row == null ? null : stringToList(row));
}
public Page(String navigation, String title, String[] columns, List<List<String>> rows) {
this(navigation, title, columns == null ? null : Arrays.asList(columns), rows);
}
public Page(String navigation, String title, List<String> columns, List<List<String>> rows) {
this.navigation = navigation;
this.title = title;
this.columns = columns;
this.rows = rows;
}
private static List<List<String>> stringToList(String str) {
List<List<String>> rows = new ArrayList<>();
List<String> row = new ArrayList<>();
row.add(str);
rows.add(row);
return rows;
}
public String getNavigation() {
return navigation;
}
public String getTitle() {
return title;
}
public List<String> getColumns() {
return columns;
}
public List<List<String>> getRows() {
return rows;
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/main/java/com/alibaba/dubbo/container/page/PageHandler.java | dubbo-compatible/src/main/java/com/alibaba/dubbo/container/page/PageHandler.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.container.page;
import org.apache.dubbo.common.extension.SPI;
import com.alibaba.dubbo.common.URL;
@SPI
public interface PageHandler {
/**
* Handle the page.
*
* @param url
* @return the page.
*/
Page handle(URL url);
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/main/java/com/alibaba/dubbo/container/page/MenuComparator.java | dubbo-compatible/src/main/java/com/alibaba/dubbo/container/page/MenuComparator.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.container.page;
import java.io.Serializable;
import java.util.Comparator;
public class MenuComparator implements Comparator<PageHandler>, Serializable {
private static final long serialVersionUID = -3161526932904414029L;
@Override
public int compare(PageHandler o1, PageHandler o2) {
if (o1 == null && o2 == null) {
return 0;
}
if (o1 == null) {
return -1;
}
if (o2 == null) {
return 1;
}
return o1.equals(o2)
? 0
: (o1.getClass().getAnnotation(Menu.class).order()
> o2.getClass().getAnnotation(Menu.class).order()
? 1
: -1);
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/main/java/com/alibaba/dubbo/container/page/Menu.java | dubbo-compatible/src/main/java/com/alibaba/dubbo/container/page/Menu.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.container.page;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Menu
*/
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE})
public @interface Menu {
String name();
String desc() default "";
int order() default 0;
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/main/java/com/alibaba/dubbo/container/page/PageServlet.java | dubbo-compatible/src/main/java/com/alibaba/dubbo/container/page/PageServlet.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.container.page;
import org.apache.dubbo.common.extension.ExtensionLoader;
import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.common.utils.StringUtils;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.concurrent.ConcurrentHashMap;
import com.alibaba.dubbo.common.Constants;
import com.alibaba.dubbo.common.URL;
public class PageServlet extends HttpServlet {
protected static final Logger logger = LoggerFactory.getLogger(PageServlet.class);
private static final long serialVersionUID = -8370312705453328501L;
private static PageServlet INSTANCE;
protected final Random random = new Random();
protected final Map<String, PageHandler> pages = new ConcurrentHashMap<>();
protected final List<PageHandler> menus = new ArrayList<>();
public static PageServlet getInstance() {
return INSTANCE;
}
public List<PageHandler> getMenus() {
return Collections.unmodifiableList(menus);
}
@Override
public void init() throws ServletException {
super.init();
INSTANCE = this;
String config = getServletConfig().getInitParameter("pages");
Collection<String> names;
if (config != null && config.length() > 0) {
names = Arrays.asList(Constants.COMMA_SPLIT_PATTERN.split(config));
} else {
names = ExtensionLoader.getExtensionLoader(PageHandler.class).getSupportedExtensions();
}
for (String name : names) {
PageHandler handler =
ExtensionLoader.getExtensionLoader(PageHandler.class).getExtension(name);
pages.put(ExtensionLoader.getExtensionLoader(PageHandler.class).getExtensionName(handler), handler);
Menu menu = handler.getClass().getAnnotation(Menu.class);
if (menu != null) {
menus.add(handler);
}
}
Collections.sort(menus, new MenuComparator());
}
@Override
protected final void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
}
@Override
protected final void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
if (!response.isCommitted()) {
PrintWriter writer = response.getWriter();
String uri = request.getRequestURI();
boolean isHtml = false;
if (uri == null || uri.length() == 0 || "/".equals(uri)) {
uri = "index";
isHtml = true;
} else {
if (uri.startsWith("/")) {
uri = uri.substring(1);
}
if (uri.endsWith(".html")) {
uri = uri.substring(0, uri.length() - ".html".length());
isHtml = true;
}
}
if (uri.endsWith("favicon.ico")) {
response.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}
ExtensionLoader<PageHandler> pageHandlerLoader = ExtensionLoader.getExtensionLoader(PageHandler.class);
PageHandler pageHandler = pageHandlerLoader.hasExtension(uri) ? pageHandlerLoader.getExtension(uri) : null;
if (isHtml) {
writer.println("<html><head><title>Dubbo</title>");
writer.println(
"<style type=\"text/css\">html, body {margin: 10;padding: 0;background-color: #6D838C;font-family: Arial, Verdana;font-size: 12px;color: #FFFFFF;text-align: center;vertical-align: middle;word-break: break-all; } table {width: 90%; margin: 0px auto;border-collapse: collapse;border: 8px solid #FFFFFF; } thead tr {background-color: #253c46; } tbody tr {background-color: #8da5af; } th {padding-top: 4px;padding-bottom: 4px;font-size: 14px;height: 20px; } td {margin: 3px;padding: 3px;border: 2px solid #FFFFFF;font-size: 14px;height: 25px; } a {color: #FFFFFF;cursor: pointer;text-decoration: underline; } a:hover {text-decoration: none; }</style>");
writer.println("</head><body>");
}
if (pageHandler != null) {
Page page = null;
try {
String query = request.getQueryString();
page = pageHandler.handle(
URL.valueOf(request.getRequestURL().toString()
+ (query == null || query.length() == 0 ? "" : "?" + query)));
} catch (Throwable t) {
logger.warn(t.getMessage(), t);
String msg = t.getMessage();
if (msg == null) {
msg = StringUtils.toString(t);
}
if (isHtml) {
writer.println("<table>");
writer.println("<thead>");
writer.println(" <tr>");
writer.println(" <th>Error</th>");
writer.println(" </tr>");
writer.println("</thead>");
writer.println("<tbody>");
writer.println(" <tr>");
writer.println(" <td>");
writer.println(" "
+ msg.replace("<", "<").replace(">", "<").replace("\n", "<br/>"));
writer.println(" </td>");
writer.println(" </tr>");
writer.println("</tbody>");
writer.println("</table>");
writer.println("<br/>");
} else {
writer.println(msg);
}
}
if (page != null) {
if (isHtml) {
String nav = page.getNavigation();
if (nav == null || nav.length() == 0) {
nav = ExtensionLoader.getExtensionLoader(PageHandler.class)
.getExtensionName(pageHandler);
nav = nav.substring(0, 1).toUpperCase() + nav.substring(1);
}
if (!"index".equals(uri)) {
nav = "<a href=\"/\">Home</a> > " + nav;
}
writeMenu(request, writer, nav);
writeTable(writer, page.getTitle(), page.getColumns(), page.getRows());
} else {
if (page.getRows().size() > 0 && page.getRows().get(0).size() > 0) {
writer.println(page.getRows().get(0).get(0));
}
}
}
} else {
if (isHtml) {
writer.println("<table>");
writer.println("<thead>");
writer.println(" <tr>");
writer.println(" <th>Error</th>");
writer.println(" </tr>");
writer.println("</thead>");
writer.println("<tbody>");
writer.println(" <tr>");
writer.println(" <td>");
writer.println(" Not found " + uri + " page. Please goto <a href=\"/\">Home</a> page.");
writer.println(" </td>");
writer.println(" </tr>");
writer.println("</tbody>");
writer.println("</table>");
writer.println("<br/>");
} else {
writer.println("Not found " + uri + " page.");
}
}
if (isHtml) {
writer.println("</body></html>");
}
writer.flush();
}
}
protected final void writeMenu(HttpServletRequest request, PrintWriter writer, String nav) {
writer.println("<table>");
writer.println("<thead>");
writer.println(" <tr>");
for (PageHandler handler : menus) {
String uri = ExtensionLoader.getExtensionLoader(PageHandler.class).getExtensionName(handler);
Menu menu = handler.getClass().getAnnotation(Menu.class);
writer.println(" <th><a href=\"" + uri + ".html\">" + menu.name() + "</a></th>");
}
writer.println(" </tr>");
writer.println("</thead>");
writer.println("<tbody>");
writer.println(" <tr>");
writer.println(" <td style=\"text-align: left\" colspan=\"" + menus.size() + "\">");
writer.println(nav);
writer.println(" </td>");
writer.println(" </tr>");
writer.println("</tbody>");
writer.println("</table>");
writer.println("<br/>");
}
protected final void writeTable(PrintWriter writer, String title, List<String> columns, List<List<String>> rows) {
int n = random.nextInt();
int c = (columns == null
? (rows == null || rows.size() == 0 ? 0 : rows.get(0).size())
: columns.size());
int r = (rows == null ? 0 : rows.size());
writer.println("<table>");
writer.println("<thead>");
writer.println(" <tr>");
writer.println(" <th colspan=\"" + c + "\">" + title + "</th>");
writer.println(" </tr>");
if (columns != null && columns.size() > 0) {
writer.println(" <tr>");
for (int i = 0; i < columns.size(); i++) {
String col = columns.get(i);
if (col.endsWith(":")) {
col += " <input type=\"text\" id=\"in_"
+ n
+ "_"
+ i
+ "\" onkeyup=\"for (var i = 0; i < "
+ r
+ "; i ++) { var m = true; for (var j = 0; j < "
+ columns.size()
+ "; j ++) { if (document.getElementById('in_"
+ n
+ "_' + j)) { var iv = document.getElementById('in_"
+ n
+ "_' + j).value; var tv = document.getElementById('td_"
+ n
+ "_' + i + '_' + j).innerHTML; if (iv.length > 0 && (tv.length < iv.length || tv.indexOf(iv) == -1)) { m = false; break; } } } document.getElementById('tr_"
+ n
+ "_' + i).style.display = (m ? '' : 'none');}\" style=\"width: 100%\" />";
}
writer.println(" <td>" + col + "</td>");
}
writer.println(" </tr>");
}
writer.println("</thead>");
if (rows != null && rows.size() > 0) {
writer.println("<tbody>");
int i = 0;
for (Collection<String> row : rows) {
writer.println(" <tr id=\"tr_" + n + "_" + i + "\">");
int j = 0;
for (String col : row) {
writer.println(" <td id=\"td_" + n + "_" + i + "_" + j + "\" style=\"display: ;\">" + col
+ "</td>");
j++;
}
writer.println(" </tr>");
i++;
}
writer.println("</tbody>");
}
writer.println("</table>");
writer.println("<br/>");
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/main/java/com/alibaba/dubbo/container/page/ResourceFilter.java | dubbo-compatible/src/main/java/com/alibaba/dubbo/container/page/ResourceFilter.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.container.page;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import com.alibaba.dubbo.common.Constants;
public class ResourceFilter implements Filter {
private static final String CLASSPATH_PREFIX = "classpath:";
private final long start = System.currentTimeMillis();
private final List<String> resources = new ArrayList<>();
public void init(FilterConfig filterConfig) throws ServletException {
String config = filterConfig.getInitParameter("resources");
if (config != null && config.length() > 0) {
String[] configs = Constants.COMMA_SPLIT_PATTERN.split(config);
for (String c : configs) {
if (c != null && c.length() > 0) {
c = c.replace('\\', '/');
if (c.endsWith("/")) {
c = c.substring(0, c.length() - 1);
}
resources.add(c);
}
}
}
}
public void destroy() {}
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) req;
HttpServletResponse response = (HttpServletResponse) res;
if (response.isCommitted()) {
return;
}
String uri = request.getRequestURI();
String context = request.getContextPath();
if (uri.endsWith("/favicon.ico")) {
uri = "/favicon.ico";
} else if (context != null && !"/".equals(context)) {
uri = uri.substring(context.length());
}
if (!uri.startsWith("/")) {
uri = "/" + uri;
}
long lastModified = getLastModified(uri);
long since = request.getDateHeader("If-Modified-Since");
if (since >= lastModified) {
response.sendError(HttpServletResponse.SC_NOT_MODIFIED);
return;
}
byte[] data;
InputStream input = getInputStream(uri);
if (input == null) {
chain.doFilter(req, res);
return;
}
try {
ByteArrayOutputStream output = new ByteArrayOutputStream();
byte[] buffer = new byte[8192];
int n = 0;
while (-1 != (n = input.read(buffer))) {
output.write(buffer, 0, n);
}
data = output.toByteArray();
} finally {
input.close();
}
response.setDateHeader("Last-Modified", lastModified);
OutputStream output = response.getOutputStream();
output.write(data);
output.flush();
}
private boolean isFile(String path) {
return path.startsWith("/") || path.indexOf(":") <= 1;
}
private long getLastModified(String uri) {
for (String resource : resources) {
if (resource != null && resource.length() > 0) {
String path = resource + uri;
if (isFile(path)) {
File file = new File(path);
if (file.exists()) {
return file.lastModified();
}
}
}
}
return start;
}
private InputStream getInputStream(String uri) {
for (String resource : resources) {
String path = resource + uri;
try {
if (isFile(path)) {
return new FileInputStream(path);
} else if (path.startsWith(CLASSPATH_PREFIX)) {
return Thread.currentThread()
.getContextClassLoader()
.getResourceAsStream(path.substring(CLASSPATH_PREFIX.length()));
} else {
return new URL(path).openStream();
}
} catch (IOException e) {
}
}
return null;
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/main/java/com/alibaba/dubbo/container/page/pages/LogPageHandler.java | dubbo-compatible/src/main/java/com/alibaba/dubbo/container/page/pages/LogPageHandler.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.container.page.pages;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Enumeration;
import java.util.List;
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.container.page.Menu;
import com.alibaba.dubbo.container.page.Page;
import com.alibaba.dubbo.container.page.PageHandler;
import org.apache.log4j.Appender;
import org.apache.log4j.FileAppender;
import org.apache.log4j.Level;
import org.apache.log4j.LogManager;
@Menu(name = "Log", desc = "Show system log.", order = Integer.MAX_VALUE - 11000)
public class LogPageHandler implements PageHandler {
private static final int SHOW_LOG_LENGTH = 30000;
private File file;
@SuppressWarnings("unchecked")
public LogPageHandler() {
try {
org.apache.log4j.Logger logger = LogManager.getRootLogger();
if (logger != null) {
Enumeration<Appender> appenders = logger.getAllAppenders();
if (appenders != null) {
while (appenders.hasMoreElements()) {
Appender appender = appenders.nextElement();
if (appender instanceof FileAppender) {
FileAppender fileAppender = (FileAppender) appender;
String filename = fileAppender.getFile();
file = new File(filename);
break;
}
}
}
}
} catch (Throwable t) {
}
}
@Override
public Page handle(URL url) {
long size = 0;
String content = "";
String modified = "Not exist";
if (file != null && file.exists()) {
try {
FileInputStream fis = new FileInputStream(file);
FileChannel channel = fis.getChannel();
size = channel.size();
ByteBuffer bb;
if (size <= SHOW_LOG_LENGTH) {
bb = ByteBuffer.allocate((int) size);
channel.read(bb, 0);
} else {
int pos = (int) (size - SHOW_LOG_LENGTH);
bb = ByteBuffer.allocate(SHOW_LOG_LENGTH);
channel.read(bb, pos);
}
bb.flip();
content = new String(bb.array())
.replace("<", "<")
.replace(">", ">")
.replace("\n", "<br/><br/>");
modified = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(file.lastModified()));
} catch (IOException e) {
}
}
Level level = LogManager.getRootLogger().getLevel();
List<List<String>> rows = new ArrayList<>();
List<String> row = new ArrayList<>();
row.add(content);
rows.add(row);
return new Page(
"Log",
"Log",
new String[] {(file == null ? "" : file.getName()) + ", " + size + " bytes, " + modified + ", " + level
},
rows);
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/main/java/com/alibaba/dubbo/container/page/pages/StatusPageHandler.java | dubbo-compatible/src/main/java/com/alibaba/dubbo/container/page/pages/StatusPageHandler.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.container.page.pages;
import org.apache.dubbo.common.extension.ExtensionLoader;
import org.apache.dubbo.common.status.Status;
import org.apache.dubbo.common.status.support.StatusUtils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.common.status.StatusChecker;
import com.alibaba.dubbo.container.page.Menu;
import com.alibaba.dubbo.container.page.Page;
import com.alibaba.dubbo.container.page.PageHandler;
@Menu(name = "Status", desc = "Show system status.", order = Integer.MAX_VALUE - 12000)
public class StatusPageHandler implements PageHandler {
@Override
public Page handle(URL url) {
List<List<String>> rows = new ArrayList<>();
Set<String> names =
ExtensionLoader.getExtensionLoader(StatusChecker.class).getSupportedExtensions();
Map<String, Status> statuses = new HashMap<>();
for (String name : names) {
StatusChecker checker =
ExtensionLoader.getExtensionLoader(StatusChecker.class).getExtension(name);
List<String> row = new ArrayList<>();
row.add(name);
Status status = checker.check();
if (status != null && !Status.Level.UNKNOWN.equals(status.getLevel())) {
statuses.put(name, status);
row.add(getLevelHtml(status.getLevel()));
row.add(status.getMessage());
rows.add(row);
}
}
Status status = StatusUtils.getSummaryStatus(statuses);
if ("status".equals(url.getPath())) {
return new Page("", "", "", status.getLevel().toString());
} else {
List<String> row = new ArrayList<>();
row.add("summary");
row.add(getLevelHtml(status.getLevel()));
row.add("<a href=\"/status\" target=\"_blank\">summary</a>");
rows.add(row);
return new Page(
"Status (<a href=\"/status\" target=\"_blank\">summary</a>)",
"Status",
new String[] {"Name", "Status", "Description"},
rows);
}
}
private String getLevelHtml(Status.Level level) {
return "<font color=\"" + getLevelColor(level) + "\">" + level.name() + "</font>";
}
private String getLevelColor(Status.Level level) {
if (level == Status.Level.OK) {
return "green";
} else if (level == Status.Level.ERROR) {
return "red";
} else if (level == Status.Level.WARN) {
return "yellow";
}
return "gray";
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/main/java/com/alibaba/dubbo/container/page/pages/HomePageHandler.java | dubbo-compatible/src/main/java/com/alibaba/dubbo/container/page/pages/HomePageHandler.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.container.page.pages;
import org.apache.dubbo.common.extension.ExtensionLoader;
import java.util.ArrayList;
import java.util.List;
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.container.page.Menu;
import com.alibaba.dubbo.container.page.Page;
import com.alibaba.dubbo.container.page.PageHandler;
import com.alibaba.dubbo.container.page.PageServlet;
@Menu(name = "Home", desc = "Home page.", order = Integer.MIN_VALUE)
public class HomePageHandler implements PageHandler {
@Override
public Page handle(URL url) {
List<List<String>> rows = new ArrayList<>();
for (PageHandler handler : PageServlet.getInstance().getMenus()) {
String uri = ExtensionLoader.getExtensionLoader(PageHandler.class).getExtensionName(handler);
Menu menu = handler.getClass().getAnnotation(Menu.class);
List<String> row = new ArrayList<>();
row.add("<a href=\"" + uri + ".html\">" + menu.name() + "</a>");
row.add(menu.desc());
rows.add(row);
}
return new Page("Home", "Menus", new String[] {"Menu Name", "Menu Desc"}, rows);
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/main/java/com/alibaba/dubbo/container/page/pages/SystemPageHandler.java | dubbo-compatible/src/main/java/com/alibaba/dubbo/container/page/pages/SystemPageHandler.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.container.page.pages;
import org.apache.dubbo.common.Version;
import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.common.utils.NetUtils;
import org.apache.dubbo.common.utils.SystemPropertyConfigUtils;
import java.lang.management.ManagementFactory;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.container.page.Menu;
import com.alibaba.dubbo.container.page.Page;
import com.alibaba.dubbo.container.page.PageHandler;
@Menu(name = "System", desc = "Show system environment information.", order = Integer.MAX_VALUE - 10000)
public class SystemPageHandler implements PageHandler {
private static final long SECOND = 1000;
private static final long MINUTE = 60 * SECOND;
private static final long HOUR = 60 * MINUTE;
private static final long DAY = 24 * HOUR;
@Override
public Page handle(URL url) {
List<List<String>> rows = new ArrayList<>();
List<String> row;
row = new ArrayList<>();
row.add("Version");
row.add(Version.getVersion(SystemPageHandler.class, "2.0.0"));
rows.add(row);
row = new ArrayList<>();
row.add("Host");
String address = NetUtils.getLocalHost();
row.add(NetUtils.getHostName(address) + "/" + address);
rows.add(row);
row = new ArrayList<>();
row.add("OS");
row.add(SystemPropertyConfigUtils.getSystemProperty(CommonConstants.SystemProperty.SYSTEM_OS_NAME) + " "
+ SystemPropertyConfigUtils.getSystemProperty(CommonConstants.SystemProperty.SYSTEM_OS_VERSION));
rows.add(row);
row = new ArrayList<>();
row.add("JVM");
row.add(SystemPropertyConfigUtils.getSystemProperty(CommonConstants.SystemProperty.JAVA_RUNTIME_NAME) + " "
+ SystemPropertyConfigUtils.getSystemProperty(CommonConstants.SystemProperty.JAVA_RUNTIME_VERSION)
+ ",<br/>"
+ SystemPropertyConfigUtils.getSystemProperty(CommonConstants.SystemProperty.JAVA_VM_NAME) + " "
+ SystemPropertyConfigUtils.getSystemProperty(CommonConstants.SystemProperty.JAVA_VM_VERSION) + " "
+ SystemPropertyConfigUtils.getSystemProperty(CommonConstants.SystemProperty.JAVA_VM_INFO, ""));
rows.add(row);
row = new ArrayList<>();
row.add("CPU");
row.add(SystemPropertyConfigUtils.getSystemProperty(CommonConstants.SystemProperty.OS_ARCH, "") + ", "
+ String.valueOf(Runtime.getRuntime().availableProcessors()) + " cores");
rows.add(row);
row = new ArrayList<>();
row.add("Locale");
row.add(Locale.getDefault().toString() + "/"
+ SystemPropertyConfigUtils.getSystemProperty(CommonConstants.SystemProperty.SYSTEM_FILE_ENCODING));
rows.add(row);
row = new ArrayList<>();
row.add("Uptime");
row.add(formatUptime(ManagementFactory.getRuntimeMXBean().getUptime()));
rows.add(row);
row = new ArrayList<>();
row.add("Time");
row.add(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS Z").format(new Date()));
rows.add(row);
return new Page("System", "System", new String[] {"Property", "Value"}, rows);
}
private String formatUptime(long uptime) {
StringBuilder buf = new StringBuilder();
if (uptime > DAY) {
long days = (uptime - uptime % DAY) / DAY;
buf.append(days);
buf.append(" Days");
uptime = uptime % DAY;
}
if (uptime > HOUR) {
long hours = (uptime - uptime % HOUR) / HOUR;
if (buf.length() > 0) {
buf.append(", ");
}
buf.append(hours);
buf.append(" Hours");
uptime = uptime % HOUR;
}
if (uptime > MINUTE) {
long minutes = (uptime - uptime % MINUTE) / MINUTE;
if (buf.length() > 0) {
buf.append(", ");
}
buf.append(minutes);
buf.append(" Minutes");
uptime = uptime % MINUTE;
}
if (uptime > SECOND) {
long seconds = (uptime - uptime % SECOND) / SECOND;
if (buf.length() > 0) {
buf.append(", ");
}
buf.append(seconds);
buf.append(" Seconds");
uptime = uptime % SECOND;
}
if (uptime > 0) {
if (buf.length() > 0) {
buf.append(", ");
}
buf.append(uptime);
buf.append(" Milliseconds");
}
return buf.toString();
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/RpcResult.java | dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/RpcResult.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.rpc;
import org.apache.dubbo.rpc.AppResponse;
@Deprecated
public class RpcResult extends AppResponse implements com.alibaba.dubbo.rpc.Result {
public RpcResult() {}
public RpcResult(Object result) {
super(result);
}
public RpcResult(Throwable exception) {
super(exception);
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/Invocation.java | dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/Invocation.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.rpc;
import org.apache.dubbo.rpc.model.ServiceModel;
import java.beans.Transient;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
@Deprecated
public interface Invocation extends org.apache.dubbo.rpc.Invocation {
@Override
Invoker<?> getInvoker();
default org.apache.dubbo.rpc.Invocation getOriginal() {
return null;
}
@Override
default void setAttachment(String key, String value) {
setObjectAttachment(key, value);
}
@Override
default void setAttachmentIfAbsent(String key, String value) {
setObjectAttachmentIfAbsent(key, value);
}
@Override
default void setObjectAttachmentIfAbsent(String key, Object value) {}
@Override
default void setObjectAttachment(String key, Object value) {}
@Override
default void setAttachment(String key, Object value) {
setObjectAttachment(key, value);
}
@Override
default void setAttachmentIfAbsent(String key, Object value) {
setObjectAttachmentIfAbsent(key, value);
}
@Override
default String getServiceName() {
return null;
}
@Override
default String getTargetServiceUniqueName() {
return null;
}
@Override
default String getAttachment(String key, String defaultValue) {
return null;
}
@Override
default void setServiceModel(ServiceModel serviceModel) {}
@Override
default ServiceModel getServiceModel() {
return null;
}
@Override
default Object put(Object key, Object value) {
return null;
}
@Override
default Object get(Object key) {
return null;
}
@Override
default Map<Object, Object> getAttributes() {
return null;
}
@Override
default Map<String, Object> getObjectAttachments() {
return Collections.emptyMap();
}
@Override
default Map<String, Object> copyObjectAttachments() {
return new HashMap<>(getObjectAttachments());
}
@Override
default void foreachAttachment(Consumer<Map.Entry<String, Object>> consumer) {
getObjectAttachments().entrySet().forEach(consumer);
}
@Override
default Object getObjectAttachment(String key) {
return null;
}
@Override
default Object getObjectAttachment(String key, Object defaultValue) {
return null;
}
class CompatibleInvocation implements Invocation {
private org.apache.dubbo.rpc.Invocation delegate;
public CompatibleInvocation(org.apache.dubbo.rpc.Invocation invocation) {
this.delegate = invocation;
}
@Override
public String getTargetServiceUniqueName() {
return delegate.getTargetServiceUniqueName();
}
@Override
public String getProtocolServiceKey() {
return delegate.getProtocolServiceKey();
}
@Override
public String getMethodName() {
return delegate.getMethodName();
}
@Override
public String getServiceName() {
return null;
}
@Override
public Class<?>[] getParameterTypes() {
return delegate.getParameterTypes();
}
@Override
public Object[] getArguments() {
return delegate.getArguments();
}
@Override
public Map<String, String> getAttachments() {
return delegate.getAttachments();
}
@Override
public String getAttachment(String key) {
return delegate.getAttachment(key);
}
@Override
public String getAttachment(String key, String defaultValue) {
return delegate.getAttachment(key, defaultValue);
}
@Override
@Transient
public Invoker<?> getInvoker() {
return new Invoker.CompatibleInvoker(delegate.getInvoker());
}
@Override
public void setServiceModel(ServiceModel serviceModel) {
delegate.setServiceModel(serviceModel);
}
@Override
public ServiceModel getServiceModel() {
return delegate.getServiceModel();
}
@Override
public Object put(Object key, Object value) {
return delegate.put(key, value);
}
@Override
public Object get(Object key) {
return delegate.get(key);
}
@Override
public Map<Object, Object> getAttributes() {
return delegate.getAttributes();
}
@Override
public org.apache.dubbo.rpc.Invocation getOriginal() {
return delegate;
}
@Override
public void addInvokedInvoker(org.apache.dubbo.rpc.Invoker<?> invoker) {
delegate.addInvokedInvoker(invoker);
}
@Override
public List<org.apache.dubbo.rpc.Invoker<?>> getInvokedInvokers() {
return delegate.getInvokedInvokers();
}
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/Exporter.java | dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/Exporter.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.rpc;
@Deprecated
public interface Exporter<T> extends org.apache.dubbo.rpc.Exporter<T> {
@Override
Invoker<T> getInvoker();
default void register() {}
default void unregister() {}
class CompatibleExporter<T> implements Exporter<T> {
private org.apache.dubbo.rpc.Exporter<T> delegate;
public CompatibleExporter(org.apache.dubbo.rpc.Exporter<T> delegate) {
this.delegate = delegate;
}
@Override
public Invoker<T> getInvoker() {
return new Invoker.CompatibleInvoker<>(delegate.getInvoker());
}
@Override
public void unexport() {
delegate.unexport();
}
@Override
public void register() {
delegate.register();
}
@Override
public void unregister() {
delegate.unregister();
}
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/Protocol.java | dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/Protocol.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.rpc;
import org.apache.dubbo.rpc.ProtocolServer;
import java.util.Collections;
import java.util.List;
import com.alibaba.dubbo.common.DelegateURL;
import com.alibaba.dubbo.common.URL;
@Deprecated
public interface Protocol extends org.apache.dubbo.rpc.Protocol {
<T> Exporter<T> export(Invoker<T> invoker) throws RpcException;
<T> Invoker<T> refer(Class<T> aClass, URL url) throws RpcException;
@Override
default <T> org.apache.dubbo.rpc.Exporter<T> export(org.apache.dubbo.rpc.Invoker<T> invoker) throws RpcException {
return this.export(new Invoker.CompatibleInvoker<>(invoker));
}
@Override
default <T> org.apache.dubbo.rpc.Invoker<T> refer(Class<T> aClass, org.apache.dubbo.common.URL url)
throws RpcException {
return this.refer(aClass, new DelegateURL(url));
}
@Override
default List<ProtocolServer> getServers() {
return Collections.emptyList();
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/Filter.java | dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/Filter.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.rpc;
import org.apache.dubbo.rpc.AsyncRpcResult;
import org.apache.dubbo.rpc.AttachmentsAdapter;
import java.util.Map;
@Deprecated
public interface Filter extends org.apache.dubbo.rpc.Filter {
Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException;
@Override
default org.apache.dubbo.rpc.Result invoke(
org.apache.dubbo.rpc.Invoker<?> invoker, org.apache.dubbo.rpc.Invocation invocation)
throws org.apache.dubbo.rpc.RpcException {
Result invokeResult =
invoke(new Invoker.CompatibleInvoker<>(invoker), new Invocation.CompatibleInvocation(invocation));
if (invokeResult instanceof Result.CompatibleResult) {
return ((Result.CompatibleResult) invokeResult).getDelegate();
}
AsyncRpcResult asyncRpcResult = AsyncRpcResult.newDefaultAsyncResult(invocation);
asyncRpcResult.setValue(invokeResult.getValue());
asyncRpcResult.setException(invokeResult.getException());
Map<String, String> attachments = invokeResult.getAttachments();
if (!(attachments instanceof AttachmentsAdapter.ObjectToStringMap)) {
asyncRpcResult.setAttachments(attachments);
}
asyncRpcResult.setObjectAttachments(invokeResult.getObjectAttachments());
return asyncRpcResult;
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/RpcContext.java | dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/RpcContext.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.rpc;
import org.apache.dubbo.common.utils.CollectionUtils;
import org.apache.dubbo.rpc.FutureContext;
import java.net.InetSocketAddress;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.FutureTask;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.stream.Collectors;
import com.alibaba.dubbo.common.Constants;
import com.alibaba.dubbo.common.DelegateURL;
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.rpc.protocol.dubbo.FutureAdapter;
@Deprecated
public class RpcContext {
public static RpcContext getContext() {
return new RpcContext(org.apache.dubbo.rpc.RpcContext.getContext());
}
public static RpcContext getServerContext() {
return new RpcContext(org.apache.dubbo.rpc.RpcContext.getServerContext());
}
public static RpcContext getClientResponseContext() {
return new RpcContext(org.apache.dubbo.rpc.RpcContext.getClientResponseContext());
}
public static RpcContext getServerResponseContext() {
return new RpcContext(org.apache.dubbo.rpc.RpcContext.getServerResponseContext());
}
public static void removeClientResponseContext() {
org.apache.dubbo.rpc.RpcContext.removeClientResponseContext();
}
public static void removeServerResponseContext() {
org.apache.dubbo.rpc.RpcContext.removeServerResponseContext();
}
public static void removeServerContext() {
org.apache.dubbo.rpc.RpcContext.removeServerContext();
}
public static void removeContext() {
org.apache.dubbo.rpc.RpcContext.removeContext();
}
private org.apache.dubbo.rpc.RpcContext newRpcContext;
public RpcContext(org.apache.dubbo.rpc.RpcContext newRpcContext) {
this.newRpcContext = newRpcContext;
}
public Object getRequest() {
return newRpcContext.getRequest();
}
public <T> T getRequest(Class<T> clazz) {
return newRpcContext.getRequest(clazz);
}
public void setRequest(Object request) {
newRpcContext.setRequest(request);
}
/**
* Get the response object of the underlying RPC protocol, e.g. HttpServletResponse
*
* @return null if the underlying protocol doesn't provide support for getting response
*/
public Object getResponse() {
return newRpcContext.getResponse();
}
/**
* Get the response object of the underlying RPC protocol, e.g. HttpServletResponse
*
* @return null if the underlying protocol doesn't provide support for getting response or the response is not of the specified type
*/
@SuppressWarnings("unchecked")
public <T> T getResponse(Class<T> clazz) {
return newRpcContext.getResponse(clazz);
}
public void setResponse(Object response) {
newRpcContext.setResponse(response);
}
/**
* is provider side.
*
* @return provider side.
*/
public boolean isProviderSide() {
return newRpcContext.isProviderSide();
}
/**
* is consumer side.
*
* @return consumer side.
*/
public boolean isConsumerSide() {
return newRpcContext.isConsumerSide();
}
public List<URL> getUrls() {
List<org.apache.dubbo.common.URL> newUrls = newRpcContext.getUrls();
if (CollectionUtils.isNotEmpty(newUrls)) {
List<URL> urls = new ArrayList<>(newUrls.size());
for (org.apache.dubbo.common.URL newUrl : newUrls) {
urls.add(new DelegateURL(newUrl));
}
return urls;
}
return Collections.emptyList();
}
public void setUrls(List<URL> urls) {
if (CollectionUtils.isNotEmpty(urls)) {
List<org.apache.dubbo.common.URL> newUrls = new ArrayList<>(urls.size());
for (URL url : urls) {
newUrls.add(url.getOriginalURL());
}
newRpcContext.setUrls(newUrls);
}
}
public URL getUrl() {
return new DelegateURL(newRpcContext.getUrl());
}
public void setUrl(URL url) {
newRpcContext.setUrl(url.getOriginalURL());
}
public String getMethodName() {
return newRpcContext.getMethodName();
}
public void setMethodName(String methodName) {
newRpcContext.setMethodName(methodName);
}
public Class<?>[] getParameterTypes() {
return newRpcContext.getParameterTypes();
}
public void setParameterTypes(Class<?>[] parameterTypes) {
newRpcContext.setParameterTypes(parameterTypes);
}
public Object[] getArguments() {
return newRpcContext.getArguments();
}
public void setArguments(Object[] arguments) {
newRpcContext.setArguments(arguments);
}
public RpcContext setLocalAddress(String host, int port) {
newRpcContext.setLocalAddress(host, port);
return this;
}
/**
* get local address.
*
* @return local address
*/
public InetSocketAddress getLocalAddress() {
return newRpcContext.getLocalAddress();
}
public RpcContext setLocalAddress(InetSocketAddress address) {
newRpcContext.setLocalAddress(address);
return this;
}
public String getLocalAddressString() {
return newRpcContext.getLocalAddressString();
}
public String getLocalHostName() {
return newRpcContext.getLocalHostName();
}
public RpcContext setRemoteAddress(String host, int port) {
newRpcContext.setRemoteAddress(host, port);
return this;
}
public InetSocketAddress getRemoteAddress() {
return newRpcContext.getRemoteAddress();
}
public RpcContext setRemoteAddress(InetSocketAddress address) {
newRpcContext.setRemoteAddress(address);
return this;
}
public String getRemoteAddressString() {
return newRpcContext.getRemoteAddressString();
}
public String getRemoteHostName() {
return newRpcContext.getRemoteHostName();
}
public String getLocalHost() {
return newRpcContext.getLocalHost();
}
public int getLocalPort() {
return newRpcContext.getLocalPort();
}
public String getRemoteHost() {
return newRpcContext.getRemoteHost();
}
public int getRemotePort() {
return newRpcContext.getRemotePort();
}
public String getAttachment(String key) {
return newRpcContext.getAttachment(key);
}
public RpcContext setAttachment(String key, String value) {
newRpcContext.setAttachment(key, value);
return this;
}
public RpcContext removeAttachment(String key) {
newRpcContext.removeAttachment(key);
return this;
}
public Map<String, String> getAttachments() {
return newRpcContext.getAttachments();
}
public RpcContext setAttachments(Map<String, String> attachment) {
newRpcContext.setAttachments(attachment);
return this;
}
public void clearAttachments() {
newRpcContext.clearAttachments();
}
/**
* get values.
*
* @return values
*/
public Map<String, Object> get() {
return newRpcContext.get();
}
/**
* set value.
*
* @param key
* @param value
* @return context
*/
public RpcContext set(String key, Object value) {
newRpcContext.set(key, value);
return this;
}
public RpcContext remove(String key) {
newRpcContext.remove(key);
return this;
}
public Object get(String key) {
return newRpcContext.get(key);
}
public Invocation getInvocation() {
return new Invocation.CompatibleInvocation(newRpcContext.getInvocation());
}
@Deprecated
public boolean isServerSide() {
return isProviderSide();
}
@Deprecated
public boolean isClientSide() {
return isConsumerSide();
}
@Deprecated
public Invoker<?> getInvoker() {
org.apache.dubbo.rpc.Invoker<?> invoker = newRpcContext.getInvoker();
if (invoker == null) {
return null;
}
return new Invoker.CompatibleInvoker<>(invoker);
}
@Deprecated
public List<Invoker<?>> getInvokers() {
List<org.apache.dubbo.rpc.Invoker<?>> invokers = newRpcContext.getInvokers();
if (CollectionUtils.isEmpty(invokers)) {
return Collections.emptyList();
}
return invokers.stream().map(Invoker.CompatibleInvoker::new).collect(Collectors.toList());
}
/**
* Async invocation. Timeout will be handled even if <code>Future.get()</code> is not called.
*
* @param callable
* @return get the return result from <code>future.get()</code>
*/
@SuppressWarnings("unchecked")
public <T> Future<T> asyncCall(Callable<T> callable) {
try {
try {
setAttachment(Constants.ASYNC_KEY, Boolean.TRUE.toString());
final T o = callable.call();
// local invoke will return directly
if (o != null) {
FutureTask<T> f = new FutureTask<>(new Callable<T>() {
@Override
public T call() throws Exception {
return o;
}
});
f.run();
return f;
} else {
}
} catch (Exception e) {
throw new RpcException(e);
} finally {
removeAttachment(Constants.ASYNC_KEY);
}
} catch (final RpcException e) {
return new Future<T>() {
@Override
public boolean cancel(boolean mayInterruptIfRunning) {
return false;
}
@Override
public boolean isCancelled() {
return false;
}
@Override
public boolean isDone() {
return true;
}
@Override
public T get() throws InterruptedException, ExecutionException {
throw new ExecutionException(e.getCause());
}
@Override
public T get(long timeout, TimeUnit unit)
throws InterruptedException, ExecutionException, TimeoutException {
return get();
}
};
}
return ((Future<T>) getContext().getFuture());
}
/**
* one way async call, send request only, and result is not required
*
* @param runnable
*/
public void asyncCall(Runnable runnable) {
try {
setAttachment(Constants.RETURN_KEY, Boolean.FALSE.toString());
runnable.run();
} catch (Throwable e) {
// FIXME should put exception in future?
throw new RpcException("oneway call error ." + e.getMessage(), e);
} finally {
removeAttachment(Constants.RETURN_KEY);
}
}
public <T> Future<T> getFuture() {
CompletableFuture completableFuture = FutureContext.getContext().getCompatibleCompletableFuture();
if (completableFuture == null) {
return null;
}
return new FutureAdapter(completableFuture);
}
public void setFuture(CompletableFuture<?> future) {
FutureContext.getContext().setCompatibleFuture(future);
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/Result.java | dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/Result.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.rpc;
import java.util.Collections;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.function.BiConsumer;
import java.util.function.Function;
@Deprecated
public interface Result extends org.apache.dubbo.rpc.Result {
@Override
default void setValue(Object value) {}
@Override
default void setException(Throwable t) {}
@Override
default Map<String, Object> getObjectAttachments() {
return Collections.emptyMap();
}
@Override
default void addObjectAttachments(Map<String, Object> map) {}
@Override
default void setObjectAttachments(Map<String, Object> map) {}
@Override
default Object getObjectAttachment(String key) {
return null;
}
@Override
default Object getObjectAttachment(String key, Object defaultValue) {
return null;
}
/**
* @see com.alibaba.dubbo.rpc.Result#getValue()
* @deprecated Replace to getValue()
*/
@Deprecated
default Object getResult() {
return getValue();
}
class CompatibleResult implements Result {
private org.apache.dubbo.rpc.Result delegate;
public CompatibleResult(org.apache.dubbo.rpc.Result result) {
this.delegate = result;
}
public org.apache.dubbo.rpc.Result getDelegate() {
return delegate;
}
@Override
public org.apache.dubbo.rpc.Result whenCompleteWithContext(
BiConsumer<org.apache.dubbo.rpc.Result, Throwable> fn) {
return delegate.whenCompleteWithContext(fn);
}
@Override
public Object getValue() {
return delegate.getValue();
}
@Override
public void setValue(Object value) {
delegate.setValue(value);
}
@Override
public Throwable getException() {
return delegate.getException();
}
@Override
public void setException(Throwable t) {
delegate.setException(t);
}
@Override
public boolean hasException() {
return delegate.hasException();
}
@Override
public Object recreate() throws Throwable {
return delegate.recreate();
}
@Override
public Map<String, String> getAttachments() {
return delegate.getAttachments();
}
@Override
public void addAttachments(Map<String, String> map) {
delegate.addAttachments(map);
}
@Override
public void setAttachments(Map<String, String> map) {
delegate.setAttachments(map);
}
@Override
public String getAttachment(String key) {
return delegate.getAttachment(key);
}
@Override
public String getAttachment(String key, String defaultValue) {
return delegate.getAttachment(key, defaultValue);
}
@Override
public void setAttachment(String key, String value) {
delegate.setAttachment(key, value);
}
@Override
public void setAttachment(String key, Object value) {
delegate.setAttachment(key, value);
}
@Override
public void setObjectAttachment(String key, Object value) {
delegate.setObjectAttachment(key, value);
}
@Override
public <U> CompletableFuture<U> thenApply(Function<org.apache.dubbo.rpc.Result, ? extends U> fn) {
return delegate.thenApply(fn);
}
@Override
public org.apache.dubbo.rpc.Result get() throws InterruptedException, ExecutionException {
return delegate.get();
}
@Override
public org.apache.dubbo.rpc.Result get(long timeout, TimeUnit unit)
throws InterruptedException, ExecutionException, TimeoutException {
return delegate.get(timeout, unit);
}
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/Invoker.java | dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/Invoker.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.rpc;
import org.apache.dubbo.rpc.AsyncRpcResult;
import com.alibaba.dubbo.common.DelegateURL;
import com.alibaba.dubbo.common.URL;
@Deprecated
public interface Invoker<T> extends org.apache.dubbo.rpc.Invoker<T> {
Result invoke(Invocation invocation) throws RpcException;
@Override
URL getUrl();
default org.apache.dubbo.rpc.Invoker<T> getOriginal() {
return null;
}
// This method will never be called for a legacy invoker.
@Override
default org.apache.dubbo.rpc.Result invoke(org.apache.dubbo.rpc.Invocation invocation)
throws org.apache.dubbo.rpc.RpcException {
return null;
}
class CompatibleInvoker<T> implements Invoker<T> {
private org.apache.dubbo.rpc.Invoker<T> invoker;
public CompatibleInvoker(org.apache.dubbo.rpc.Invoker<T> invoker) {
this.invoker = invoker;
}
@Override
public Class<T> getInterface() {
return invoker.getInterface();
}
@Override
public org.apache.dubbo.rpc.Result invoke(org.apache.dubbo.rpc.Invocation invocation)
throws org.apache.dubbo.rpc.RpcException {
return new Result.CompatibleResult(invoker.invoke(invocation));
}
@Override
public Result invoke(Invocation invocation) throws RpcException {
if (invoker instanceof Invoker) {
Result result = ((Invoker) invoker).invoke(invocation);
if (result instanceof Result.CompatibleResult) {
return result;
} else {
AsyncRpcResult asyncRpcResult = AsyncRpcResult.newDefaultAsyncResult(invocation.getOriginal());
asyncRpcResult.setValue(result.getValue());
asyncRpcResult.setException(result.getException());
asyncRpcResult.setObjectAttachments(result.getObjectAttachments());
return new Result.CompatibleResult(asyncRpcResult);
}
}
return new Result.CompatibleResult(invoker.invoke(invocation.getOriginal()));
}
@Override
public URL getUrl() {
return new DelegateURL(invoker.getUrl());
}
@Override
public boolean isAvailable() {
return invoker.isAvailable();
}
@Override
public void destroy() {
invoker.destroy();
}
@Override
public org.apache.dubbo.rpc.Invoker<T> getOriginal() {
return invoker;
}
@Override
public int hashCode() {
return invoker.hashCode();
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof CompatibleInvoker)) {
return false;
}
return invoker.equals(o);
}
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/InvokerListener.java | dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/InvokerListener.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.rpc;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.RpcException;
@Deprecated
public interface InvokerListener extends org.apache.dubbo.rpc.InvokerListener {
void referred(com.alibaba.dubbo.rpc.Invoker<?> invoker) throws com.alibaba.dubbo.rpc.RpcException;
void destroyed(com.alibaba.dubbo.rpc.Invoker<?> invoker);
@Override
default void referred(Invoker<?> invoker) throws RpcException {
this.referred(new com.alibaba.dubbo.rpc.Invoker.CompatibleInvoker<>(invoker));
}
@Override
default void destroyed(Invoker<?> invoker) {
this.destroyed(new com.alibaba.dubbo.rpc.Invoker.CompatibleInvoker<>(invoker));
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/RpcException.java | dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/RpcException.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.rpc;
@Deprecated
public class RpcException extends org.apache.dubbo.rpc.RpcException {
public RpcException() {
super();
}
public RpcException(String message, Throwable cause) {
super(message, cause);
}
public RpcException(String message) {
super(message);
}
public RpcException(Throwable cause) {
super(cause);
}
public RpcException(int code) {
super(code);
}
public RpcException(int code, String message, Throwable cause) {
super(code, message, cause);
}
public RpcException(int code, String message) {
super(code, message);
}
public RpcException(int code, Throwable cause) {
super(code, cause);
}
public boolean isForbidded() {
return isForbidden();
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/RpcInvocation.java | dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/RpcInvocation.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.rpc;
import java.beans.Transient;
import java.io.Serializable;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.alibaba.dubbo.common.Constants;
import com.alibaba.dubbo.common.URL;
@Deprecated
public class RpcInvocation implements Invocation, Serializable {
private static final long serialVersionUID = -4355285085441097045L;
private String methodName;
private Class<?>[] parameterTypes;
private Object[] arguments;
private Map<String, String> attachments;
private transient Invoker<?> invoker;
public RpcInvocation() {}
public RpcInvocation(Invocation invocation, Invoker<?> invoker) {
this(
invocation.getMethodName(),
invocation.getParameterTypes(),
invocation.getArguments(),
new HashMap<String, String>(invocation.getAttachments()),
invocation.getInvoker());
if (invoker != null) {
URL url = invoker.getUrl();
setAttachment(Constants.PATH_KEY, url.getPath());
if (url.hasParameter(Constants.INTERFACE_KEY)) {
setAttachment(Constants.INTERFACE_KEY, url.getParameter(Constants.INTERFACE_KEY));
}
if (url.hasParameter(Constants.GROUP_KEY)) {
setAttachment(Constants.GROUP_KEY, url.getParameter(Constants.GROUP_KEY));
}
if (url.hasParameter(Constants.VERSION_KEY)) {
setAttachment(Constants.VERSION_KEY, url.getParameter(Constants.VERSION_KEY, "0.0.0"));
}
if (url.hasParameter(Constants.TIMEOUT_KEY)) {
setAttachment(Constants.TIMEOUT_KEY, url.getParameter(Constants.TIMEOUT_KEY));
}
if (url.hasParameter(Constants.TOKEN_KEY)) {
setAttachment(Constants.TOKEN_KEY, url.getParameter(Constants.TOKEN_KEY));
}
if (url.hasParameter(Constants.APPLICATION_KEY)) {
setAttachment(Constants.APPLICATION_KEY, url.getParameter(Constants.APPLICATION_KEY));
}
}
}
public RpcInvocation(Invocation invocation) {
this(
invocation.getMethodName(),
invocation.getParameterTypes(),
invocation.getArguments(),
invocation.getAttachments(),
invocation.getInvoker());
}
public RpcInvocation(Method method, Object[] arguments) {
this(method.getName(), method.getParameterTypes(), arguments, null, null);
}
public RpcInvocation(Method method, Object[] arguments, Map<String, String> attachment) {
this(method.getName(), method.getParameterTypes(), arguments, attachment, null);
}
public RpcInvocation(String methodName, Class<?>[] parameterTypes, Object[] arguments) {
this(methodName, parameterTypes, arguments, null, null);
}
public RpcInvocation(
String methodName, Class<?>[] parameterTypes, Object[] arguments, Map<String, String> attachments) {
this(methodName, parameterTypes, arguments, attachments, null);
}
public RpcInvocation(
String methodName,
Class<?>[] parameterTypes,
Object[] arguments,
Map<String, String> attachments,
Invoker<?> invoker) {
this.methodName = methodName;
this.parameterTypes = parameterTypes == null ? new Class<?>[0] : parameterTypes;
this.arguments = arguments == null ? new Object[0] : arguments;
this.attachments = attachments == null ? new HashMap<String, String>() : attachments;
this.invoker = invoker;
}
@Transient
public Invoker<?> getInvoker() {
return invoker;
}
public void setInvoker(Invoker<?> invoker) {
this.invoker = invoker;
}
@Override
public String getProtocolServiceKey() {
return null;
}
public String getMethodName() {
return methodName;
}
public void setMethodName(String methodName) {
this.methodName = methodName;
}
public Class<?>[] getParameterTypes() {
return parameterTypes;
}
public void setParameterTypes(Class<?>[] parameterTypes) {
this.parameterTypes = parameterTypes == null ? new Class<?>[0] : parameterTypes;
}
public Object[] getArguments() {
return arguments;
}
public void setArguments(Object[] arguments) {
this.arguments = arguments == null ? new Object[0] : arguments;
}
public Map<String, String> getAttachments() {
return attachments;
}
public void setAttachments(Map<String, String> attachments) {
this.attachments = attachments == null ? new HashMap<String, String>() : attachments;
}
public void setAttachment(String key, String value) {
if (attachments == null) {
attachments = new HashMap<>();
}
attachments.put(key, value);
}
public void setAttachmentIfAbsent(String key, String value) {
if (attachments == null) {
attachments = new HashMap<>();
}
if (!attachments.containsKey(key)) {
attachments.put(key, value);
}
}
public void addAttachments(Map<String, String> attachments) {
if (attachments == null) {
return;
}
if (this.attachments == null) {
this.attachments = new HashMap<>();
}
this.attachments.putAll(attachments);
}
public void addAttachmentsIfAbsent(Map<String, String> attachments) {
if (attachments == null) {
return;
}
for (Map.Entry<String, String> entry : attachments.entrySet()) {
setAttachmentIfAbsent(entry.getKey(), entry.getValue());
}
}
public String getAttachment(String key) {
if (attachments == null) {
return null;
}
return (String) attachments.get(key);
}
public String getAttachment(String key, String defaultValue) {
if (attachments == null) {
return defaultValue;
}
String value = (String) attachments.get(key);
if (value == null || value.length() == 0) {
return defaultValue;
}
return value;
}
@Override
public void addInvokedInvoker(org.apache.dubbo.rpc.Invoker<?> invoker) {
throw new UnsupportedOperationException();
}
@Override
public List<org.apache.dubbo.rpc.Invoker<?>> getInvokedInvokers() {
throw new UnsupportedOperationException();
}
@Override
public String toString() {
return "RpcInvocation [methodName=" + methodName + ", parameterTypes="
+ Arrays.toString(parameterTypes) + ", arguments=" + Arrays.toString(arguments)
+ ", attachments=" + attachments + "]";
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/ProxyFactory.java | dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/ProxyFactory.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.rpc;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.RpcException;
@Deprecated
public interface ProxyFactory extends org.apache.dubbo.rpc.ProxyFactory {
<T> T getProxy(com.alibaba.dubbo.rpc.Invoker<T> invoker) throws com.alibaba.dubbo.rpc.RpcException;
<T> T getProxy(com.alibaba.dubbo.rpc.Invoker<T> invoker, boolean generic) throws com.alibaba.dubbo.rpc.RpcException;
<T> com.alibaba.dubbo.rpc.Invoker<T> getInvoker(T proxy, Class<T> type, com.alibaba.dubbo.common.URL url)
throws com.alibaba.dubbo.rpc.RpcException;
@Override
default <T> T getProxy(Invoker<T> invoker) throws RpcException {
return getProxy(new com.alibaba.dubbo.rpc.Invoker.CompatibleInvoker<>(invoker));
}
@Override
default <T> T getProxy(Invoker<T> invoker, boolean generic) throws RpcException {
return getProxy(new com.alibaba.dubbo.rpc.Invoker.CompatibleInvoker<>(invoker), generic);
}
@Override
default <T> Invoker<T> getInvoker(T proxy, Class<T> type, URL url) throws RpcException {
return getInvoker(proxy, type, new com.alibaba.dubbo.common.DelegateURL(url));
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/support/RpcUtils.java | dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/support/RpcUtils.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.rpc.support;
import java.lang.reflect.Type;
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.rpc.Invocation;
/**
* 2019-04-18
*/
public class RpcUtils extends org.apache.dubbo.rpc.support.RpcUtils {
public static Class<?> getReturnType(Invocation invocation) {
return org.apache.dubbo.rpc.support.RpcUtils.getReturnType(invocation);
}
// TODO why not get return type when initialize Invocation?
public static Type[] getReturnTypes(Invocation invocation) {
return org.apache.dubbo.rpc.support.RpcUtils.getReturnTypes(invocation);
}
public static Long getInvocationId(Invocation inv) {
return org.apache.dubbo.rpc.support.RpcUtils.getInvocationId(inv);
}
/**
* Idempotent operation: invocation id will be added in async operation by default
*
* @param url
* @param inv
*/
public static void attachInvocationIdIfAsync(URL url, Invocation inv) {
org.apache.dubbo.rpc.support.RpcUtils.attachInvocationIdIfAsync(url.getOriginalURL(), inv);
}
public static String getMethodName(Invocation invocation) {
return org.apache.dubbo.rpc.support.RpcUtils.getMethodName(invocation);
}
public static Object[] getArguments(Invocation invocation) {
return org.apache.dubbo.rpc.support.RpcUtils.getArguments(invocation);
}
public static Class<?>[] getParameterTypes(Invocation invocation) {
return org.apache.dubbo.rpc.support.RpcUtils.getParameterTypes(invocation);
}
public static boolean isAsync(URL url, Invocation inv) {
return org.apache.dubbo.rpc.support.RpcUtils.isAsync(url.getOriginalURL(), inv);
}
public static boolean isReturnTypeFuture(Invocation inv) {
return org.apache.dubbo.rpc.support.RpcUtils.isReturnTypeFuture(inv);
}
public static boolean isOneway(URL url, Invocation inv) {
return org.apache.dubbo.rpc.support.RpcUtils.isOneway(url.getOriginalURL(), inv);
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/service/GenericService.java | dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/service/GenericService.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.rpc.service;
@Deprecated
public interface GenericService extends org.apache.dubbo.rpc.service.GenericService {
@Override
Object $invoke(String method, String[] parameterTypes, Object[] args) throws GenericException;
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/service/GenericException.java | dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/service/GenericException.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.rpc.service;
@Deprecated
public class GenericException extends org.apache.dubbo.rpc.service.GenericException {
private static final long serialVersionUID = -1182299763306599962L;
public GenericException() {}
public GenericException(String exceptionMessage) {
super(exceptionMessage);
}
public GenericException(String exceptionClass, String exceptionMessage) {
super(exceptionClass, exceptionMessage);
}
public GenericException(Throwable cause) {
super(cause);
}
public GenericException(String message, Throwable cause, String exceptionClass, String exceptionMessage) {
super(message, cause, exceptionClass, exceptionMessage);
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/service/EchoService.java | dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/service/EchoService.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.rpc.service;
@Deprecated
public interface EchoService extends org.apache.dubbo.rpc.service.EchoService {}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/cluster/Configurator.java | dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/cluster/Configurator.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.rpc.cluster;
import org.apache.dubbo.common.URL;
@Deprecated
public interface Configurator extends org.apache.dubbo.rpc.cluster.Configurator {
/**
* Get the configurator url.
*
* @return configurator url.
*/
com.alibaba.dubbo.common.URL getUrl();
/**
* Configure the provider url.
*
* @param url - old provider url.
* @return new provider url.
*/
com.alibaba.dubbo.common.URL configure(com.alibaba.dubbo.common.URL url);
@Override
default URL configure(URL url) {
return this.configure(new com.alibaba.dubbo.common.DelegateURL(url));
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/cluster/Directory.java | dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/cluster/Directory.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.rpc.cluster;
import org.apache.dubbo.rpc.Invocation;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.RpcException;
import java.util.List;
import java.util.stream.Collectors;
import com.alibaba.dubbo.common.URL;
@Deprecated
public interface Directory<T> extends org.apache.dubbo.rpc.cluster.Directory<T> {
@Override
URL getUrl();
List<com.alibaba.dubbo.rpc.Invoker<T>> list(com.alibaba.dubbo.rpc.Invocation invocation)
throws com.alibaba.dubbo.rpc.RpcException;
@Override
default List<Invoker<T>> list(Invocation invocation) throws RpcException {
List<com.alibaba.dubbo.rpc.Invoker<T>> res =
this.list(new com.alibaba.dubbo.rpc.Invocation.CompatibleInvocation(invocation));
return res.stream().map(com.alibaba.dubbo.rpc.Invoker::getOriginal).collect(Collectors.toList());
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/cluster/RouterFactory.java | dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/cluster/RouterFactory.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.rpc.cluster;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.rpc.cluster.Router;
@Deprecated
public interface RouterFactory extends org.apache.dubbo.rpc.cluster.RouterFactory {
com.alibaba.dubbo.rpc.cluster.Router getRouter(com.alibaba.dubbo.common.URL url);
@Override
default Router getRouter(URL url) {
return this.getRouter(new com.alibaba.dubbo.common.DelegateURL(url));
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/cluster/RuleConverter.java | dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/cluster/RuleConverter.java | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.rpc.cluster;
import org.apache.dubbo.common.URL;
import java.util.List;
import java.util.stream.Collectors;
@Deprecated
public interface RuleConverter extends org.apache.dubbo.rpc.cluster.RuleConverter {
List<com.alibaba.dubbo.common.URL> convert(com.alibaba.dubbo.common.URL subscribeUrl, Object source);
@Override
default List<URL> convert(URL subscribeUrl, Object source) {
return this.convert(new com.alibaba.dubbo.common.DelegateURL(subscribeUrl), source).stream()
.map(url -> url.getOriginalURL())
.collect(Collectors.toList());
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.