alibaba / spring-cloud-alibaba

Spring Cloud Alibaba provides a one-stop solution for application development for the distributed solutions of Alibaba middleware.
https://sca.aliyun.com
Apache License 2.0
27.73k stars 8.28k forks source link

consumer can not work(get http error:500) when protocol choose hessian, but choose dubbo it works #1598

Open enjoysun opened 4 years ago

enjoysun commented 4 years ago

Environment

spring-cloud:Hoxton.SR3
spring-boot:2.2.5.RELEASE
spring-cloud-alibaba-version:2.2.1.RELEASE

Configuration

provider
server:
  port: 8080
  servlet:
    jsp:
      class-name: org.apache.dubbo.remoting.http.servlet.DispatcherServlet

#dubbo configuration
#
# scan base package
dubbo:
  scan:
    base-packages: com.yjcloud.material.collection.server.service
  protocols:
    dubbo:
      name: dubbo
      port: -1 # -1 
      payload: 11557050
      server: netty
      accepts: 1000
    hessian:
      name: hessian
      port: -1
      server: jetty # servlet
  application:
    qos-enable: false
  registry:
    address: spring-cloud://localhost
    group: collection-server
  provider:
    version: 1.0.0
    delay: -1
    timeout: 6000
    loadbalance: leastactive
    connections: 3  
@Service(protocol = "hessian")
public class FooImpl implements FooService {
    @Override
    public String say(byte[] bytes) {
        return String.format("hello %s", bytes.length);
    }
}
consumer
dubbo:
  registry:
    address: spring-cloud://localhost
  cloud:
    subscribed-services: ${provider.application.name}
  consumer:
    check: false
    version: 1.0.0
  application:
    qos-enable: false

server:
  port: 8082

provider:
  application:
    name: material-collection-server  
@RestController
    public class BarController {

        @Reference(protocol = "hessian")
        private FooService FooImpl;

        @GetMapping("/say")
        public String say() {
            File file = new File("/Users/myou/Downloads/apache-maven-3.5.4.zip");
            byte[] bytes = new byte[(int) file.length()];
            try {
                FileInputStream fileInputStream = new FileInputStream(file);
                fileInputStream.read(bytes);
                fileInputStream.close();
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
            String say = FooImpl.say(bytes);
            return say;
        }
    }

Provider Pom

<dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-web</artifactId>
                </exclusion>
<!--                <exclusion>-->
<!--                    <groupId>org.springframework.boot</groupId>-->
<!--                    <artifactId>spring-boot-starter-tomcat</artifactId>-->
<!--                </exclusion>-->
            </exclusions>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-actuator</artifactId>
        </dependency>

        <dependency>
            <groupId>com.yjcloud</groupId>
            <artifactId>material-api</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <!-- Dubbo Spring Cloud Starter -->
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-dubbo</artifactId>
        </dependency>

        <!-- Spring Cloud Nacos Service Discovery -->
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
        </dependency>

        <!--dubbo:hessian//-->
        <dependency>
            <groupId>com.caucho</groupId>
            <artifactId>hessian</artifactId>
        </dependency>

<!--        <dependency>-->
<!--            <groupId>org.springframework.boot</groupId>-->
<!--            <artifactId>spring-boot-starter-jetty</artifactId>-->
<!--        </dependency>-->

        <dependency>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-servlet</artifactId>
        </dependency>
    </dependencies>

Consumer Instance Error

"status":500,"error":"Internal Server Error","message":"Failed to invoke the method say in the service com.yjcloud.service.demo.FooService. Tried 3 times of the providers [192.168.99.61:80] (1/1) from the registry localhost:9090 on the consumer 127.0.0.1 using the dubbo version 2.7.6. Last error is: Failed to invoke remote service: interface com.yjcloud.service.demo.FooService, method: say, cause: 500: java.io.IOException: Server returned HTTP response code: 500 for URL: http://192.168.99.61:80?anyhost=true&application=demo-consumer&check=false&connections=3&delay=-1&deprecated=false&dubbo=2.0.2&dynamic=true&generic=false&init=false&interface=com.yjcloud.service.demo.FooService&loadbalance=leastactive&methods=say&pid=9432&protocol=hessian&qos.enable=false&register.ip=127.0.0.1&release=2.7.6&remote.application=material-collection-server&server=jetty&side=consumer&sticky=false&timeout=6000&timestamp=1595409800752&version=1.0.0","path":"/say"}

2020-07-22 17:23:56.652:WARN:oejs.HttpChannel:qtp951868096-50: / javax.servlet.ServletException: java.lang.NullPointerException at org.apache.dubbo.rpc.protocol.hessian.HessianProtocol$HessianHandler.handle(HessianProtocol.java:195) at org.apache.dubbo.remoting.http.servlet.DispatcherServlet.service(DispatcherServlet.java:61) at javax.servlet.http.HttpServlet.service(HttpServlet.java:741) at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:755) at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:547) at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:233) at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1607) at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:233) at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1297) at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:188) at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:485) at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1577) at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:186) at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1212) at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141) at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127) at org.eclipse.jetty.server.Server.handle(Server.java:500) at org.eclipse.jetty.server.HttpChannel.lambda$handle$1(HttpChannel.java:383) at org.eclipse.jetty.server.HttpChannel.dispatch(HttpChannel.java:547) at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:375) at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:270) at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:311) at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:103) at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:117) at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.runTask(EatWhatYouKill.java:336) at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:313) at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce(EatWhatYouKill.java:171) at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.produce(EatWhatYouKill.java:135) at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:806) at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:938) at java.lang.Thread.run(Thread.java:748) Caused by: java.lang.NullPointerException at org.apache.dubbo.rpc.protocol.hessian.HessianProtocol$HessianHandler.handle(HessianProtocol.java:193) at org.apache.dubbo.remoting.http.servlet.DispatcherServlet.service(DispatcherServlet.java:61) at javax.servlet.http.HttpServlet.service(HttpServlet.java:741) at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:755) at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:547) at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:233) at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1607) at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:233) at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1297) at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:188) at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:485) at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1577) at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:186) at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1212) at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141) at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127) at org.eclipse.jetty.server.Server.handle(Server.java:500) at org.eclipse.jetty.server.HttpChannel.lambda$handle$1(HttpChannel.java:383) at org.eclipse.jetty.server.HttpChannel.dispatch(HttpChannel.java:547) at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:375) at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:270) at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:311) at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:103) at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:117) at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.runTask(EatWhatYouKill.java:336) at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:313) at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce(EatWhatYouKill.java:171) at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.produce(EatWhatYouKill.java:135) at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:806) at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:938) at java.lang.Thread.run(Thread.java:748)

if protocol 'hessian convert to 'dubbo', it works

enjoysun commented 4 years ago

update yml like this,but not works

yml

server:
  port: 8080
  servlet:
    jsp:
      class-name: org.apache.dubbo.remoting.http.servlet.DispatcherServlet

#dubbo configuration
#
# scan base package
dubbo:
  scan:
    base-packages: com.yjcloud.material.collection.server.service
  protocols:
    dubbo:
      name: dubbo
      port: -1 
      payload: 11557050
      server: netty
      accepts: 1000
    hessian:
      name: hessian
      port: -1
      server: jetty # servlet
      serialization: hessian2
  application:
    qos-enable: false
  registry:
    address: spring-cloud://localhost
    group: collection-server
  provider:
    version: 1.0.0
    delay: -1
    timeout: 6000
    loadbalance: leastactive
    connections: 3  
hzdjulytech commented 3 years ago

+1