Skip to content

3.2.5 rest协议使用apache-http-client出现NPE #12916

@lucky-xin

Description

@lucky-xin
  • I have searched the issues of this repository and believe that this is not a duplicate.

Environment

  • Dubbo version: 3.2.5
  • Operating System version: MAC OS
  • Java version: 17

Steps to reproduce this issue

  1. 定义rest接口并配置client=apache-http-client
**
 * 文件管理服务接口
 *
 * @author chaoxin.lu
 * @since 2018/6/28
 */
@RequestMapping("/oss")
public interface FileSvc {

    /**
     * 获取文件
     *
     * @param bucket
     * @param key   
     * @return
     */
    @GetMapping
    @ResponseBody
    R<FileEntry> getObject(@RequestParam("bucket") String bucket,
                           @RequestParam("key") String key);

}
dubbo:
    protocol:
        id: ${DUBBO_PROTOCOL:rest}
        name: ${DUBBO_PROTOCOL:rest}
        client: ${DUBBO_CLIENT:apache-http-client}
        port: ${DUBBO_PORT:20895}
        server: ${DUBBO_PROTOCOL_SERVER:netty}
  1. 服务消费者如下
    image

Pls. provide [GitHub address] to reproduce this issue.

Expected Behavior

Actual Behavior

If there is an exception, please attach the exception trace:

Caused by: java.lang.NullPointerException: Cannot invoke "org.apache.http.Header.getValue()" because the return value of "org.apache.http.client.methods.CloseableHttpResponse.getFirstHeader(String)" is null
	at org.apache.dubbo.remoting.http.restclient.HttpClientRestClient$1.getContentType(HttpClientRestClient.java:96)
	at org.apache.dubbo.rpc.protocol.rest.RestInvoker.lambda$doInvoke$0(RestInvoker.java:105)
	at java.base/java.util.concurrent.CompletableFuture.uniWhenComplete(CompletableFuture.java:863)
	at java.base/java.util.concurrent.CompletableFuture.uniWhenCompleteStage(CompletableFuture.java:887)
	at java.base/java.util.concurrent.CompletableFuture.whenComplete(CompletableFuture.java:2325)
	at org.apache.dubbo.rpc.protocol.rest.RestInvoker.doInvoke(RestInvoker.java:87)
	at org.apache.dubbo.rpc.protocol.AbstractInvoker.doInvokeAndReturn(AbstractInvoker.java:243)
	at org.apache.dubbo.rpc.protocol.AbstractInvoker.invoke(AbstractInvoker.java:187)
	... 97 more

NPE点如下
image
使用默认的okhttp则没有该问题
image

Metadata

Metadata

Assignees

No one assigned

    Labels

    type/bugBugs to being fixed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions