You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by li...@apache.org on 2019/11/27 01:49:26 UTC
[dubbo] branch 2.7.5-release updated: New version will not support
outdated http-invoker rpc protocol anymore
This is an automated email from the ASF dual-hosted git repository.
liujun pushed a commit to branch 2.7.5-release
in repository https://gitbox.apache.org/repos/asf/dubbo.git
The following commit(s) were added to refs/heads/2.7.5-release by this push:
new 9b18fe2 New version will not support outdated http-invoker rpc protocol anymore
9b18fe2 is described below
commit 9b18fe228971eaeca9b87d7b7e95df1c2a8ff91b
Author: ken.lj <ke...@gmail.com>
AuthorDate: Wed Nov 27 09:49:10 2019 +0800
New version will not support outdated http-invoker rpc protocol anymore
---
dubbo-rpc/dubbo-rpc-http-invoker/pom.xml | 57 ------
.../rpc/protocol/http/HttpRemoteInvocation.java | 28 ---
.../protocol/httpinvoker/HttpInvokerProtocol.java | 225 ---------------------
.../protocol/httpinvoker/HttpRemoteInvocation.java | 59 ------
.../dubbo/internal/org.apache.dubbo.rpc.Protocol | 1 -
.../httpinvoker/HttpInvokerProtocolTest.java | 203 -------------------
.../rpc/protocol/httpinvoker/HttpService.java | 35 ----
.../rpc/protocol/httpinvoker/HttpServiceImpl.java | 71 -------
8 files changed, 679 deletions(-)
diff --git a/dubbo-rpc/dubbo-rpc-http-invoker/pom.xml b/dubbo-rpc/dubbo-rpc-http-invoker/pom.xml
deleted file mode 100644
index f467cc8..0000000
--- a/dubbo-rpc/dubbo-rpc-http-invoker/pom.xml
+++ /dev/null
@@ -1,57 +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.
- -->
-<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/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.apache.dubbo</groupId>
- <artifactId>dubbo-rpc</artifactId>
- <version>${revision}</version>
- </parent>
- <artifactId>dubbo-rpc-http-invoker</artifactId>
- <packaging>jar</packaging>
- <name>${project.artifactId}</name>
- <description>The http rpc module of dubbo project</description>
- <properties>
- <skip_maven_deploy>false</skip_maven_deploy>
- </properties>
- <dependencies>
- <dependency>
- <groupId>org.apache.dubbo</groupId>
- <artifactId>dubbo-rpc-api</artifactId>
- <version>${project.parent.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.dubbo</groupId>
- <artifactId>dubbo-remoting-http</artifactId>
- <version>${project.parent.version}</version>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-context</artifactId>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-web</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.dubbo</groupId>
- <artifactId>dubbo-serialization-jdk</artifactId>
- <version>${project.parent.version}</version>
- <scope>test</scope>
- </dependency>
- </dependencies>
-</project>
\ No newline at end of file
diff --git a/dubbo-rpc/dubbo-rpc-http-invoker/src/main/java/com/alibaba/dubbo/rpc/protocol/http/HttpRemoteInvocation.java b/dubbo-rpc/dubbo-rpc-http-invoker/src/main/java/com/alibaba/dubbo/rpc/protocol/http/HttpRemoteInvocation.java
deleted file mode 100644
index 2c74155..0000000
--- a/dubbo-rpc/dubbo-rpc-http-invoker/src/main/java/com/alibaba/dubbo/rpc/protocol/http/HttpRemoteInvocation.java
+++ /dev/null
@@ -1,28 +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 com.alibaba.dubbo.rpc.protocol.http;
-
-import org.aopalliance.intercept.MethodInvocation;
-
-@Deprecated
-public class HttpRemoteInvocation extends org.apache.dubbo.rpc.protocol.httpinvoker.HttpRemoteInvocation {
- private static final long serialVersionUID = 1L;
-
- public HttpRemoteInvocation(MethodInvocation methodInvocation) {
- super(methodInvocation);
- }
-}
diff --git a/dubbo-rpc/dubbo-rpc-http-invoker/src/main/java/org/apache/dubbo/rpc/protocol/httpinvoker/HttpInvokerProtocol.java b/dubbo-rpc/dubbo-rpc-http-invoker/src/main/java/org/apache/dubbo/rpc/protocol/httpinvoker/HttpInvokerProtocol.java
deleted file mode 100644
index 6657681..0000000
--- a/dubbo-rpc/dubbo-rpc-http-invoker/src/main/java/org/apache/dubbo/rpc/protocol/httpinvoker/HttpInvokerProtocol.java
+++ /dev/null
@@ -1,225 +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.protocol.httpinvoker;
-
-import org.apache.dubbo.common.URL;
-import org.apache.dubbo.common.Version;
-import org.apache.dubbo.common.utils.StringUtils;
-import org.apache.dubbo.remoting.Constants;
-import org.apache.dubbo.remoting.http.HttpBinder;
-import org.apache.dubbo.remoting.http.HttpHandler;
-import org.apache.dubbo.remoting.http.HttpServer;
-import org.apache.dubbo.rpc.RpcContext;
-import org.apache.dubbo.rpc.RpcException;
-import org.apache.dubbo.rpc.protocol.AbstractProxyProtocol;
-import org.apache.dubbo.rpc.service.GenericService;
-import org.apache.dubbo.rpc.support.ProtocolUtils;
-
-import org.aopalliance.intercept.MethodInvocation;
-import org.springframework.remoting.RemoteAccessException;
-import org.springframework.remoting.httpinvoker.HttpComponentsHttpInvokerRequestExecutor;
-import org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean;
-import org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter;
-import org.springframework.remoting.httpinvoker.SimpleHttpInvokerRequestExecutor;
-import org.springframework.remoting.support.RemoteInvocation;
-import org.springframework.remoting.support.RemoteInvocationFactory;
-
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
-import java.net.HttpURLConnection;
-import java.net.SocketTimeoutException;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_TIMEOUT;
-import static org.apache.dubbo.common.constants.CommonConstants.DUBBO_VERSION_KEY;
-import static org.apache.dubbo.common.constants.CommonConstants.RELEASE_KEY;
-import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY;
-import static org.apache.dubbo.rpc.Constants.GENERIC_KEY;
-
-/**
- * HttpInvokerProtocol
- */
-public class HttpInvokerProtocol extends AbstractProxyProtocol {
-
- public static final int DEFAULT_PORT = 80;
-
- private final Map<String, HttpServer> serverMap = new ConcurrentHashMap<String, HttpServer>();
-
- private final Map<String, HttpInvokerServiceExporter> skeletonMap = new ConcurrentHashMap<String, HttpInvokerServiceExporter>();
-
- private HttpBinder httpBinder;
-
- public HttpInvokerProtocol() {
- super(RemoteAccessException.class);
- }
-
- public void setHttpBinder(HttpBinder httpBinder) {
- this.httpBinder = httpBinder;
- }
-
- @Override
- public int getDefaultPort() {
- return DEFAULT_PORT;
- }
-
- @Override
- protected <T> Runnable doExport(final T impl, Class<T> type, URL url) throws RpcException {
- String addr = getAddr(url);
- HttpServer server = serverMap.get(addr);
- if (server == null) {
- server = httpBinder.bind(url, new InternalHandler());
- serverMap.put(addr, server);
- }
- final String path = url.getAbsolutePath();
- skeletonMap.put(path, createExporter(impl, type));
-
- final String genericPath = path + "/" + GENERIC_KEY;
-
- skeletonMap.put(genericPath, createExporter(impl, GenericService.class));
- return new Runnable() {
- @Override
- public void run() {
- skeletonMap.remove(path);
- skeletonMap.remove(genericPath);
- }
- };
- }
-
- private <T> HttpInvokerServiceExporter createExporter(T impl, Class<?> type) {
- final HttpInvokerServiceExporter httpServiceExporter = new HttpInvokerServiceExporter();
- httpServiceExporter.setServiceInterface(type);
- httpServiceExporter.setService(impl);
- try {
- httpServiceExporter.afterPropertiesSet();
- } catch (Exception e) {
- throw new RpcException(e.getMessage(), e);
- }
- return httpServiceExporter;
- }
-
- @Override
- @SuppressWarnings("unchecked")
- protected <T> T doRefer(final Class<T> serviceType, final URL url) throws RpcException {
- final String generic = url.getParameter(GENERIC_KEY);
- final boolean isGeneric = ProtocolUtils.isGeneric(generic) || serviceType.equals(GenericService.class);
-
- final HttpInvokerProxyFactoryBean httpProxyFactoryBean = new HttpInvokerProxyFactoryBean();
- httpProxyFactoryBean.setRemoteInvocationFactory(new RemoteInvocationFactory() {
- @Override
- public RemoteInvocation createRemoteInvocation(MethodInvocation methodInvocation) {
- RemoteInvocation invocation;
- /*
- package was renamed to 'org.apache.dubbo' in v2.7.0, so only provider versions after v2.7.0 can
- recognize org.apache.xxx.HttpRemoteInvocation'.
- */
- if (Version.isRelease270OrHigher(url.getParameter(RELEASE_KEY))) {
- invocation = new HttpRemoteInvocation(methodInvocation);
- } else {
- /*
- The customized 'com.alibaba.dubbo.rpc.protocol.http.HttpRemoteInvocation' was firstly introduced
- in v2.6.3. The main purpose is to support transformation of attachments in HttpInvokerProtocol, see
- https://github.com/apache/dubbo/pull/1827. To guarantee interoperability with lower
- versions, we need to check if the provider is v2.6.3 or higher before sending customized
- HttpRemoteInvocation.
- */
- if (Version.isRelease263OrHigher(url.getParameter(DUBBO_VERSION_KEY))) {
- invocation = new com.alibaba.dubbo.rpc.protocol.http.HttpRemoteInvocation(methodInvocation);
- } else {
- invocation = new RemoteInvocation(methodInvocation);
- }
- }
- if (isGeneric) {
- invocation.addAttribute(GENERIC_KEY, generic);
- }
- return invocation;
- }
- });
-
- String key = url.toIdentityString();
- if (isGeneric) {
- key = key + "/" + GENERIC_KEY;
- }
-
- httpProxyFactoryBean.setServiceUrl(key.replace("http-invoker","http"));
- httpProxyFactoryBean.setServiceInterface(serviceType);
- String client = url.getParameter(Constants.CLIENT_KEY);
- if (StringUtils.isEmpty(client) || "simple".equals(client)) {
- SimpleHttpInvokerRequestExecutor httpInvokerRequestExecutor = new SimpleHttpInvokerRequestExecutor() {
- @Override
- protected void prepareConnection(HttpURLConnection con,
- int contentLength) throws IOException {
- super.prepareConnection(con, contentLength);
- con.setReadTimeout(url.getParameter(TIMEOUT_KEY, DEFAULT_TIMEOUT));
- con.setConnectTimeout(url.getParameter(Constants.CONNECT_TIMEOUT_KEY, Constants.DEFAULT_CONNECT_TIMEOUT));
- }
- };
- httpProxyFactoryBean.setHttpInvokerRequestExecutor(httpInvokerRequestExecutor);
- } else if ("commons".equals(client)) {
- HttpComponentsHttpInvokerRequestExecutor httpInvokerRequestExecutor = new HttpComponentsHttpInvokerRequestExecutor();
- httpInvokerRequestExecutor.setReadTimeout(url.getParameter(TIMEOUT_KEY, DEFAULT_TIMEOUT));
- httpInvokerRequestExecutor.setConnectTimeout(url.getParameter(Constants.CONNECT_TIMEOUT_KEY, Constants.DEFAULT_CONNECT_TIMEOUT));
- httpProxyFactoryBean.setHttpInvokerRequestExecutor(httpInvokerRequestExecutor);
- } else {
- throw new IllegalStateException("Unsupported http protocol client " + client + ", only supported: simple, commons");
- }
- httpProxyFactoryBean.afterPropertiesSet();
- return (T) httpProxyFactoryBean.getObject();
- }
-
- @Override
- protected int getErrorCode(Throwable e) {
- if (e instanceof RemoteAccessException) {
- e = e.getCause();
- }
- if (e != null) {
- Class<?> cls = e.getClass();
- if (SocketTimeoutException.class.equals(cls)) {
- return RpcException.TIMEOUT_EXCEPTION;
- } else if (IOException.class.isAssignableFrom(cls)) {
- return RpcException.NETWORK_EXCEPTION;
- } else if (ClassNotFoundException.class.isAssignableFrom(cls)) {
- return RpcException.SERIALIZATION_EXCEPTION;
- }
- }
- return super.getErrorCode(e);
- }
-
- private class InternalHandler implements HttpHandler {
-
- @Override
- public void handle(HttpServletRequest request, HttpServletResponse response)
- throws IOException, ServletException {
- String uri = request.getRequestURI();
- HttpInvokerServiceExporter skeleton = skeletonMap.get(uri);
- if (!"POST".equalsIgnoreCase(request.getMethod())) {
- response.setStatus(500);
- } else {
- RpcContext.getContext().setRemoteAddress(request.getRemoteAddr(), request.getRemotePort());
- try {
- skeleton.handleRequest(request, response);
- } catch (Throwable e) {
- throw new ServletException(e);
- }
- }
- }
-
- }
-
-}
diff --git a/dubbo-rpc/dubbo-rpc-http-invoker/src/main/java/org/apache/dubbo/rpc/protocol/httpinvoker/HttpRemoteInvocation.java b/dubbo-rpc/dubbo-rpc-http-invoker/src/main/java/org/apache/dubbo/rpc/protocol/httpinvoker/HttpRemoteInvocation.java
deleted file mode 100644
index fca5103..0000000
--- a/dubbo-rpc/dubbo-rpc-http-invoker/src/main/java/org/apache/dubbo/rpc/protocol/httpinvoker/HttpRemoteInvocation.java
+++ /dev/null
@@ -1,59 +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.protocol.httpinvoker;
-
-import org.apache.dubbo.common.utils.StringUtils;
-import org.apache.dubbo.rpc.RpcContext;
-
-import org.aopalliance.intercept.MethodInvocation;
-import org.springframework.remoting.support.RemoteInvocation;
-
-import java.lang.reflect.InvocationTargetException;
-import java.util.HashMap;
-import java.util.Map;
-
-import static org.apache.dubbo.rpc.Constants.GENERIC_KEY;
-
-public class HttpRemoteInvocation extends RemoteInvocation {
-
- private static final long serialVersionUID = 1L;
- private static final String DUBBO_ATTACHMENTS_ATTR_NAME = "dubbo.attachments";
-
- public HttpRemoteInvocation(MethodInvocation methodInvocation) {
- super(methodInvocation);
- addAttribute(DUBBO_ATTACHMENTS_ATTR_NAME, new HashMap<String, Object>(RpcContext.getContext().getAttachments()));
- }
-
- @Override
- public Object invoke(Object targetObject) throws NoSuchMethodException, IllegalAccessException,
- InvocationTargetException {
- RpcContext context = RpcContext.getContext();
- context.setAttachments((Map<String, Object>) getAttribute(DUBBO_ATTACHMENTS_ATTR_NAME));
-
- String generic = (String) getAttribute(GENERIC_KEY);
- if (StringUtils.isNotEmpty(generic)) {
- context.setAttachment(GENERIC_KEY, generic);
- }
- try {
- return super.invoke(targetObject);
- } finally {
- context.setAttachments(null);
-
- }
- }
-}
diff --git a/dubbo-rpc/dubbo-rpc-http-invoker/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.Protocol b/dubbo-rpc/dubbo-rpc-http-invoker/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.Protocol
deleted file mode 100644
index 9076376..0000000
--- a/dubbo-rpc/dubbo-rpc-http-invoker/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.Protocol
+++ /dev/null
@@ -1 +0,0 @@
-http-invoker=org.apache.dubbo.rpc.protocol.httpinvoker.HttpInvokerProtocol
\ No newline at end of file
diff --git a/dubbo-rpc/dubbo-rpc-http-invoker/src/test/java/org/apache/dubbo/rpc/protocol/httpinvoker/HttpInvokerProtocolTest.java b/dubbo-rpc/dubbo-rpc-http-invoker/src/test/java/org/apache/dubbo/rpc/protocol/httpinvoker/HttpInvokerProtocolTest.java
deleted file mode 100644
index 046c3b7..0000000
--- a/dubbo-rpc/dubbo-rpc-http-invoker/src/test/java/org/apache/dubbo/rpc/protocol/httpinvoker/HttpInvokerProtocolTest.java
+++ /dev/null
@@ -1,203 +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.protocol.httpinvoker;
-
-import org.apache.dubbo.common.URL;
-import org.apache.dubbo.common.beanutil.JavaBeanDescriptor;
-import org.apache.dubbo.common.beanutil.JavaBeanSerializeUtil;
-import org.apache.dubbo.common.extension.ExtensionLoader;
-import org.apache.dubbo.common.serialize.ObjectInput;
-import org.apache.dubbo.common.serialize.ObjectOutput;
-import org.apache.dubbo.common.serialize.Serialization;
-import org.apache.dubbo.common.serialize.nativejava.NativeJavaSerialization;
-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.RpcException;
-import org.apache.dubbo.rpc.service.GenericService;
-
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.Test;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-
-import static org.junit.jupiter.api.Assertions.fail;
-
-/**
- * HttpInvokerProtocolTest
- */
-public class HttpInvokerProtocolTest {
-
- @Test
- public void testHttpProtocol() {
- HttpServiceImpl server = new HttpServiceImpl();
- Assertions.assertFalse(server.isCalled());
- ProxyFactory proxyFactory = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension();
- Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension();
- URL url = URL.valueOf("http-invoker://127.0.0.1:5342/" + HttpService.class.getName() + "?release=2.7.0");
- Exporter<HttpService> exporter = protocol.export(proxyFactory.getInvoker(server, HttpService.class, url));
- Invoker<HttpService> invoker = protocol.refer(HttpService.class, url);
- HttpService client = proxyFactory.getProxy(invoker);
- String result = client.sayHello("haha");
- Assertions.assertTrue(server.isCalled());
- Assertions.assertEquals("Hello, haha", result);
- invoker.destroy();
- exporter.unexport();
- }
-
- @Test
- public void testGenericInvoke() {
- HttpServiceImpl server = new HttpServiceImpl();
- Assertions.assertFalse(server.isCalled());
- ProxyFactory proxyFactory = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension();
- Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension();
- URL url = URL.valueOf("http-invoker://127.0.0.1:5342/" + HttpService.class.getName() + "?release=2.7.0");
- Exporter<HttpService> exporter = protocol.export(proxyFactory.getInvoker(server, HttpService.class, url));
- Invoker<GenericService> invoker = protocol.refer(GenericService.class, url);
- GenericService client = proxyFactory.getProxy(invoker, true);
- String result = (String) client.$invoke("sayHello", new String[]{"java.lang.String"}, new Object[]{"haha"});
- Assertions.assertTrue(server.isCalled());
- Assertions.assertEquals("Hello, haha", result);
- invoker.destroy();
- exporter.unexport();
- }
-
- @Test
- public void testGenericInvokeWithNativeJava() throws IOException, ClassNotFoundException {
- HttpServiceImpl server = new HttpServiceImpl();
- Assertions.assertFalse(server.isCalled());
- ProxyFactory proxyFactory = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension();
- Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension();
- URL url = URL.valueOf("http-invoker://127.0.0.1:5342/" + HttpService.class.getName() + "?release=2.7.0&generic=nativejava");
- Exporter<HttpService> exporter = protocol.export(proxyFactory.getInvoker(server, HttpService.class, url));
- Invoker<GenericService> invoker = protocol.refer(GenericService.class, url);
- GenericService client = proxyFactory.getProxy(invoker);
-
- Serialization serialization = new NativeJavaSerialization();
- ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
-
- ObjectOutput objectOutput = serialization.serialize(url, byteArrayOutputStream);
- objectOutput.writeObject("haha");
- objectOutput.flushBuffer();
-
- Object result = client.$invoke("sayHello", new String[]{"java.lang.String"}, new Object[]{byteArrayOutputStream.toByteArray()});
- ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream((byte[]) result);
- ObjectInput objectInput = serialization.deserialize(url, byteArrayInputStream);
- Assertions.assertTrue(server.isCalled());
- Assertions.assertEquals("Hello, haha", objectInput.readObject());
- invoker.destroy();
- exporter.unexport();
- }
-
- @Test
- public void testGenericInvokeWithBean() {
- HttpServiceImpl server = new HttpServiceImpl();
- Assertions.assertFalse(server.isCalled());
- ProxyFactory proxyFactory = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension();
- Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension();
- URL url = URL.valueOf("http-invoker://127.0.0.1:5342/" + HttpService.class.getName() + "?release=2.7.0&generic=bean");
- Exporter<HttpService> exporter = protocol.export(proxyFactory.getInvoker(server, HttpService.class, url));
- Invoker<GenericService> invoker = protocol.refer(GenericService.class, url);
- GenericService client = proxyFactory.getProxy(invoker);
-
- JavaBeanDescriptor javaBeanDescriptor = JavaBeanSerializeUtil.serialize("haha");
-
- Object result = client.$invoke("sayHello", new String[]{"java.lang.String"}, new Object[]{javaBeanDescriptor});
- Assertions.assertTrue(server.isCalled());
- Assertions.assertEquals("Hello, haha", JavaBeanSerializeUtil.deserialize((JavaBeanDescriptor) result));
- invoker.destroy();
- exporter.unexport();
- }
-
- @Test
- public void testOverload() {
- HttpServiceImpl server = new HttpServiceImpl();
- Assertions.assertFalse(server.isCalled());
- ProxyFactory proxyFactory = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension();
- Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension();
- URL url = URL.valueOf("http-invoker://127.0.0.1:5342/" + HttpService.class.getName() + "?release=2.7.0&hessian.overload.method=true&hessian2.request=false");
- Exporter<HttpService> exporter = protocol.export(proxyFactory.getInvoker(server, HttpService.class, url));
- Invoker<HttpService> invoker = protocol.refer(HttpService.class, url);
- HttpService client = proxyFactory.getProxy(invoker);
- String result = client.sayHello("haha");
- Assertions.assertEquals("Hello, haha", result);
- result = client.sayHello("haha", 1);
- Assertions.assertEquals("Hello, haha. ", result);
- invoker.destroy();
- exporter.unexport();
- }
-
- @Test
- public void testSimpleClient() {
- HttpServiceImpl server = new HttpServiceImpl();
- Assertions.assertFalse(server.isCalled());
- ProxyFactory proxyFactory = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension();
- Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension();
- URL url = URL.valueOf("http-invoker://127.0.0.1:5342/" + HttpService.class.getName() + "?release=2.7.0&client=simple");
- Exporter<HttpService> exporter = protocol.export(proxyFactory.getInvoker(server, HttpService.class, url));
- Invoker<HttpService> invoker = protocol.refer(HttpService.class, url);
- HttpService client = proxyFactory.getProxy(invoker);
- String result = client.sayHello("haha");
- Assertions.assertTrue(server.isCalled());
- Assertions.assertEquals("Hello, haha", result);
- invoker.destroy();
- exporter.unexport();
- }
-
- @Test
- public void testTimeOut() {
- HttpServiceImpl server = new HttpServiceImpl();
- ProxyFactory proxyFactory = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension();
- Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension();
- URL url = URL.valueOf("http-invoker://127.0.0.1:5342/" + HttpService.class.getName() + "?release=2.7.0&timeout=10");
- Exporter<HttpService> exporter = protocol.export(proxyFactory.getInvoker(server, HttpService.class, url));
- Invoker<HttpService> invoker = protocol.refer(HttpService.class, url);
- HttpService client = proxyFactory.getProxy(invoker);
- try {
- client.timeOut(6000);
- fail();
- } catch (RpcException expected) {
- Assertions.assertTrue(expected.isTimeout());
- } finally {
- invoker.destroy();
- exporter.unexport();
- }
-
- }
-
- @Test
- public void testCustomException() {
- HttpServiceImpl server = new HttpServiceImpl();
- ProxyFactory proxyFactory = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension();
- Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension();
- URL url = URL.valueOf("http-invoker://127.0.0.1:5342/" + HttpService.class.getName() + "?release=2.7.0");
- Exporter<HttpService> exporter = protocol.export(proxyFactory.getInvoker(server, HttpService.class, url));
- Invoker<HttpService> invoker = protocol.refer(HttpService.class, url);
- HttpService client = proxyFactory.getProxy(invoker);
- try {
- client.customException();
- fail();
- } catch (HttpServiceImpl.MyException expected) {
- }
- invoker.destroy();
- exporter.unexport();
- }
-
-}
diff --git a/dubbo-rpc/dubbo-rpc-http-invoker/src/test/java/org/apache/dubbo/rpc/protocol/httpinvoker/HttpService.java b/dubbo-rpc/dubbo-rpc-http-invoker/src/test/java/org/apache/dubbo/rpc/protocol/httpinvoker/HttpService.java
deleted file mode 100644
index 5205dc6..0000000
--- a/dubbo-rpc/dubbo-rpc-http-invoker/src/test/java/org/apache/dubbo/rpc/protocol/httpinvoker/HttpService.java
+++ /dev/null
@@ -1,35 +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.protocol.httpinvoker;
-
-
-/**
- * HttpService
- */
-public interface HttpService {
-
- String sayHello(String name);
-
- String sayHello(String name, int times);
-
- void timeOut(int millis);
-
- String customException();
-
- String getRemoteApplicationName();
-
-}
diff --git a/dubbo-rpc/dubbo-rpc-http-invoker/src/test/java/org/apache/dubbo/rpc/protocol/httpinvoker/HttpServiceImpl.java b/dubbo-rpc/dubbo-rpc-http-invoker/src/test/java/org/apache/dubbo/rpc/protocol/httpinvoker/HttpServiceImpl.java
deleted file mode 100644
index d47e813..0000000
--- a/dubbo-rpc/dubbo-rpc-http-invoker/src/test/java/org/apache/dubbo/rpc/protocol/httpinvoker/HttpServiceImpl.java
+++ /dev/null
@@ -1,71 +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.protocol.httpinvoker;
-
-import org.apache.dubbo.rpc.RpcContext;
-
-/**
- * HttpServiceImpl
- */
-public class HttpServiceImpl implements HttpService {
-
- private boolean called;
-
- public String sayHello(String name) {
- called = true;
- return "Hello, " + name;
- }
-
- public String sayHello(String name, int times) {
- called = true;
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < times; i++) {
- sb.append("Hello, " + name + ". ");
- }
- return sb.toString();
- }
-
- public boolean isCalled() {
- return called;
- }
-
- public void timeOut(int millis) {
- try {
- Thread.sleep(millis);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
-
- @Override
- public String getRemoteApplicationName() {
- return RpcContext.getContext().getRemoteApplicationName();
- }
-
- public String customException() {
- throw new MyException("custom exception");
- }
-
- static class MyException extends RuntimeException {
-
- private static final long serialVersionUID = -3051041116483629056L;
-
- public MyException(String message) {
- super(message);
- }
- }
-}