Remove bytebuddy implementation (#13916)

This commit is contained in:
TomlongTK 2024-03-14 14:36:34 +08:00 committed by GitHub
parent cf53c38179
commit 1145b4015b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
21 changed files with 0 additions and 763 deletions

View File

@ -118,7 +118,6 @@ dubbo-seata-spring-boot-starter
dubbo-spring-security
dubbo-tracing
dubbo-xds
dubbo-plugin-proxy-bytebuddy
dubbo-plugin-loom
dubbo-rest-jaxrs
dubbo-rest-servlet

View File

@ -276,14 +276,6 @@
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-plugin-proxy-bytebuddy</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-rest-jaxrs</artifactId>
@ -555,7 +547,6 @@
<include>org.apache.dubbo:dubbo-security</include>
<include>org.apache.dubbo:dubbo-reactive</include>
<include>org.apache.dubbo:dubbo-spring-security</include>
<include>org.apache.dubbo:dubbo-plugin-proxy-bytebuddy</include>
<include>org.apache.dubbo:dubbo-registry-api</include>
<include>org.apache.dubbo:dubbo-registry-multicast</include>
<include>org.apache.dubbo:dubbo-registry-multiple</include>

View File

@ -329,11 +329,6 @@
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-plugin-proxy-bytebuddy</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-rest-jaxrs</artifactId>

View File

@ -1,41 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-plugin</artifactId>
<version>${revision}</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>dubbo-plugin-proxy-bytebuddy</artifactId>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-rpc-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -1,40 +0,0 @@
/*
* 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.proxy.bytebuddy;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import net.bytebuddy.implementation.bind.annotation.AllArguments;
import net.bytebuddy.implementation.bind.annotation.Origin;
import net.bytebuddy.implementation.bind.annotation.RuntimeType;
import net.bytebuddy.implementation.bind.annotation.This;
public class ByteBuddyInterceptor {
private final InvocationHandler handler;
ByteBuddyInterceptor(InvocationHandler handler) {
this.handler = handler;
}
@RuntimeType
public Object intercept(@This Object obj, @AllArguments Object[] allArguments, @Origin Method method)
throws Throwable {
return handler.invoke(obj, method, allArguments);
}
}

View File

@ -1,130 +0,0 @@
/*
* 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.proxy.bytebuddy;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Map;
import java.util.WeakHashMap;
import java.util.concurrent.ConcurrentHashMap;
import net.bytebuddy.ByteBuddy;
import net.bytebuddy.description.ByteCodeElement;
import net.bytebuddy.implementation.MethodDelegation;
import net.bytebuddy.matcher.ElementMatcher;
import net.bytebuddy.matcher.ElementMatchers;
import static org.apache.dubbo.common.constants.CommonConstants.MAX_PROXY_COUNT;
public class ByteBuddyProxy {
private static final Map<ClassLoader, Map<CacheKey, ByteBuddyProxy>> PROXY_CACHE_MAP = new WeakHashMap<>();
private final Class<?> proxyClass;
private final InvocationHandler handler;
private ByteBuddyProxy(Class<?> proxyClass, InvocationHandler handler) {
this.proxyClass = proxyClass;
this.handler = handler;
}
public static Object newInstance(ClassLoader cl, Class<?>[] interfaces, InvocationHandler handler) {
return getProxy(cl, interfaces, handler).newInstance();
}
private static ByteBuddyProxy getProxy(ClassLoader cl, Class<?>[] interfaces, InvocationHandler handler) {
if (interfaces.length > MAX_PROXY_COUNT) {
throw new IllegalArgumentException("interface limit exceeded");
}
interfaces = interfaces.clone();
Arrays.sort(interfaces, Comparator.comparing(Class::getName));
CacheKey key = new CacheKey(interfaces);
// get cache by class loader.
final Map<CacheKey, ByteBuddyProxy> cache;
synchronized (PROXY_CACHE_MAP) {
cache = PROXY_CACHE_MAP.computeIfAbsent(cl, k -> new ConcurrentHashMap<>());
}
ByteBuddyProxy proxy = cache.get(key);
if (proxy == null) {
synchronized (interfaces[0]) {
proxy = cache.get(key);
if (proxy == null) {
// create ByteBuddyProxy class.
proxy = new ByteBuddyProxy(buildProxyClass(cl, interfaces, handler), handler);
cache.put(key, proxy);
}
}
}
return proxy;
}
private Object newInstance() {
try {
Constructor<?> constructor = proxyClass.getDeclaredConstructor(InvocationHandler.class);
return constructor.newInstance(handler);
} catch (ReflectiveOperationException e) {
throw new RuntimeException(e);
}
}
private static Class<?> buildProxyClass(ClassLoader cl, Class<?>[] ics, InvocationHandler handler) {
ElementMatcher.Junction<ByteCodeElement> methodMatcher = Arrays.stream(ics)
.map(ElementMatchers::isDeclaredBy)
.reduce(ElementMatcher.Junction::or)
.orElse(ElementMatchers.none())
.and(ElementMatchers.not(ElementMatchers.isDeclaredBy(Object.class)));
return new ByteBuddy()
.subclass(Proxy.class)
.implement(ics)
.method(methodMatcher)
.intercept(MethodDelegation.to(new ByteBuddyInterceptor(handler)))
.make()
.load(cl)
.getLoaded();
}
private static class CacheKey {
private final Class<?>[] classes;
private CacheKey(Class<?>[] classes) {
this.classes = classes;
}
public Class<?>[] getClasses() {
return classes;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
CacheKey that = (CacheKey) o;
return Arrays.equals(classes, that.classes);
}
@Override
public int hashCode() {
return Arrays.hashCode(classes);
}
}
}

View File

@ -1,40 +0,0 @@
/*
* 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.proxy.bytebuddy;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.proxy.AbstractFallbackJdkProxyFactory;
import org.apache.dubbo.rpc.proxy.InvokerInvocationHandler;
/**
* ByteBuddyRpcProxyFactory
*/
public class ByteBuddyProxyFactory extends AbstractFallbackJdkProxyFactory {
@Override
protected <T> Invoker<T> doGetInvoker(T proxy, Class<T> type, URL url) {
return ByteBuddyProxyInvoker.newInstance(proxy, type, url);
}
@Override
@SuppressWarnings("unchecked")
protected <T> T doGetProxy(Invoker<T> invoker, Class<?>[] interfaces) {
ClassLoader classLoader = invoker.getInterface().getClassLoader();
return (T) ByteBuddyProxy.newInstance(classLoader, interfaces, new InvokerInvocationHandler(invoker));
}
}

View File

@ -1,56 +0,0 @@
/*
* 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.proxy.bytebuddy;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.rpc.proxy.AbstractProxyInvoker;
import org.apache.dubbo.rpc.proxy.MethodInvoker;
class ByteBuddyProxyInvoker<T> extends AbstractProxyInvoker<T> {
private final MethodInvoker methodInvoker;
private ByteBuddyProxyInvoker(T proxy, Class<T> type, URL url, MethodInvoker methodInvoker) {
super(proxy, type, url);
this.methodInvoker = methodInvoker;
}
@Override
protected Object doInvoke(T instance, String methodName, Class<?>[] parameterTypes, Object[] arguments)
throws Throwable {
if ("getClass".equals(methodName)) {
return instance.getClass();
}
if ("hashCode".equals(methodName)) {
return instance.hashCode();
}
if ("toString".equals(methodName)) {
return instance.toString();
}
if ("equals".equals(methodName)) {
if (arguments.length == 1) {
return instance.equals(arguments[0]);
}
throw new IllegalArgumentException("Invoke method [" + methodName + "] argument number error.");
}
return methodInvoker.invoke(instance, methodName, parameterTypes, arguments);
}
static <T> ByteBuddyProxyInvoker<T> newInstance(T proxy, Class<T> type, URL url) {
return new ByteBuddyProxyInvoker<>(proxy, type, url, MethodInvoker.newInstance(proxy.getClass()));
}
}

View File

@ -1 +0,0 @@
bytebuddy=org.apache.dubbo.rpc.proxy.bytebuddy.ByteBuddyProxyFactory

View File

@ -1,87 +0,0 @@
/*
* 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.proxy;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.ProxyFactory;
import org.apache.dubbo.rpc.RpcInvocation;
import org.apache.dubbo.rpc.service.Destroyable;
import org.apache.dubbo.rpc.service.EchoService;
import org.apache.dubbo.rpc.support.DemoService;
import org.apache.dubbo.rpc.support.DemoServiceImpl;
import org.apache.dubbo.rpc.support.MyInvoker;
import java.util.Arrays;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public abstract class AbstractProxyTest {
public static ProxyFactory factory;
@Test
void testGetProxy() {
URL url = URL.valueOf("test://test:11/test?group=dubbo&version=1.1");
MyInvoker<DemoService> invoker = new MyInvoker<>(url);
DemoService proxy = factory.getProxy(invoker);
Assertions.assertNotNull(proxy);
Assertions.assertTrue(Arrays.asList(proxy.getClass().getInterfaces()).contains(DemoService.class));
Assertions.assertTrue(Arrays.asList(proxy.getClass().getInterfaces()).contains(Destroyable.class));
Assertions.assertTrue(Arrays.asList(proxy.getClass().getInterfaces()).contains(EchoService.class));
Assertions.assertEquals(
invoker.invoke(new RpcInvocation(
"echo",
DemoService.class.getName(),
DemoService.class.getName() + ":dubbo",
new Class[] {String.class},
new Object[] {"aa"}))
.getValue(),
proxy.echo("aa"));
Destroyable destroyable = (Destroyable) proxy;
destroyable.$destroy();
Assertions.assertTrue(invoker.isDestroyed());
}
@Test
void testGetInvoker() {
URL url = URL.valueOf("test://test:11/test?group=dubbo&version=1.1");
DemoService origin = new DemoServiceImpl();
Invoker<DemoService> invoker = factory.getInvoker(new DemoServiceImpl(), DemoService.class, url);
Assertions.assertEquals(invoker.getInterface(), DemoService.class);
Assertions.assertEquals(
invoker.invoke(new RpcInvocation(
"echo",
DemoService.class.getName(),
DemoService.class.getName() + ":dubbo",
new Class[] {String.class},
new Object[] {"aa"}))
.getValue(),
origin.echo("aa"));
}
}

View File

@ -1,26 +0,0 @@
/*
* 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.proxy;
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface RemoteService extends Remote {
String sayHello(String name) throws RemoteException;
String getThreadName() throws RemoteException;
}

View File

@ -1,45 +0,0 @@
/*
* 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.proxy.bytebuddy;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
class ByteBuddyInterceptorTest {
@AfterEach
public void after() {
Mockito.clearAllCaches();
}
@Test
void testIntercept() throws Throwable {
InvocationHandler handler = Mockito.mock(InvocationHandler.class);
ByteBuddyInterceptor interceptor = new ByteBuddyInterceptor(handler);
Method method = Mockito.mock(Method.class);
Proxy proxy = Mockito.mock(Proxy.class);
Object[] args = new Object[0];
interceptor.intercept(proxy, args, method);
// 'intercept' method will call 'invoke' method directly
Mockito.verify(handler, Mockito.times(1)).invoke(proxy, method, args);
}
}

View File

@ -1,26 +0,0 @@
/*
* 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.proxy.bytebuddy;
import org.apache.dubbo.rpc.proxy.AbstractProxyTest;
class ByteBuddyProxyFactoryTest extends AbstractProxyTest {
static {
AbstractProxyTest.factory = new ByteBuddyProxyFactory();
}
}

View File

@ -1,41 +0,0 @@
/*
* 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.proxy.bytebuddy;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.rpc.proxy.RemoteService;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
class ByteBuddyProxyInvokerTest {
@Test
void testNewInstance() throws Throwable {
URL url = URL.valueOf("test://test:11/test?group=dubbo&version=1.1");
RemoteService proxy = Mockito.mock(RemoteService.class);
ByteBuddyProxyInvoker<RemoteService> invoker =
ByteBuddyProxyInvoker.newInstance(proxy, RemoteService.class, url);
invoker.doInvoke(proxy, "sayHello", new Class[] {String.class}, new Object[] {"test"});
Mockito.verify(proxy, Mockito.times(1)).sayHello("test");
Assertions.assertThrows(
IllegalArgumentException.class,
() -> invoker.doInvoke(proxy, "equals", new Class[] {String.class}, new Object[] {"test", "test2"}));
}
}

View File

@ -1,44 +0,0 @@
/*
* 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.proxy.bytebuddy;
import org.apache.dubbo.rpc.proxy.InvokerInvocationHandler;
import org.apache.dubbo.rpc.proxy.RemoteService;
import java.lang.reflect.Proxy;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.mockito.ArgumentMatchers.any;
class ByteBuddyProxyTest {
@Test
void testNewInstance() throws Throwable {
ClassLoader cl = Thread.currentThread().getContextClassLoader();
InvokerInvocationHandler handler = Mockito.mock(InvokerInvocationHandler.class);
Object proxy = ByteBuddyProxy.newInstance(cl, new Class<?>[] {RemoteService.class}, handler);
assertInstanceOf(RemoteService.class, proxy);
assertInstanceOf(Proxy.class, proxy);
RemoteService remoteService = (RemoteService) proxy;
remoteService.getThreadName();
remoteService.sayHello("test");
Mockito.verify(handler, Mockito.times(2)).invoke(any(), any(), any());
}
}

View File

@ -1,21 +0,0 @@
/*
* 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 interface DemoService {
String echo(String text);
}

View File

@ -1,26 +0,0 @@
/*
* 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;
/**
* DemoServiceImpl
*/
public class DemoServiceImpl implements DemoService {
public String echo(String text) {
return text;
}
}

View File

@ -1,89 +0,0 @@
/*
* 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 org.apache.dubbo.common.URL;
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.RpcException;
import java.util.concurrent.CompletableFuture;
/**
* MockInvoker.java
*/
public class MyInvoker<T> implements Invoker<T> {
URL url;
Class<T> type;
boolean hasException = false;
boolean destroyed = false;
public MyInvoker(URL url) {
this.url = url;
type = (Class<T>) DemoService.class;
}
public MyInvoker(URL url, boolean hasException) {
this.url = url;
type = (Class<T>) DemoService.class;
this.hasException = hasException;
}
@Override
public Class<T> getInterface() {
return type;
}
public URL getUrl() {
return url;
}
@Override
public boolean isAvailable() {
return false;
}
@Override
public Result invoke(Invocation invocation) throws RpcException {
AppResponse result = new AppResponse();
if (!hasException) {
result.setValue("alibaba");
} else {
result.setException(new RuntimeException("mocked exception"));
}
return new AsyncRpcResult(CompletableFuture.completedFuture(result), invocation);
}
@Override
public void destroy() {
destroyed = true;
}
public boolean isDestroyed() {
return destroyed;
}
@Override
public String toString() {
return "MyInvoker.toString()";
}
}

View File

@ -1,29 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
-->
<Configuration status="WARN">
<Appenders>
<Console name="Console" target="SYSTEM_OUT" follow="true">
<PatternLayout pattern="%d{HH:mm:ss.SSS} |-%highlight{%-5p} [%t] %40.40c:%-3L -| %m%n%rEx{filters(jdk.internal.reflect,java.lang.reflect,sun.reflect,org.junit,org.mockito)}" charset="UTF-8"/>
</Console>
</Appenders>
<Loggers>
<Root level="info">
<AppenderRef ref="Console"/>
</Root>
</Loggers>
</Configuration>

View File

@ -40,7 +40,6 @@
<module>dubbo-compiler</module>
<module>dubbo-filter-cache</module>
<module>dubbo-filter-validation</module>
<module>dubbo-plugin-proxy-bytebuddy</module>
<module>dubbo-rest-jaxrs</module>
<module>dubbo-rest-servlet</module>
<module>dubbo-rest-spring</module>

View File

@ -251,11 +251,6 @@
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-plugin-proxy-bytebuddy</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-rest-jaxrs</artifactId>