【问题标题】:Spring MVC giving Connection refused when connecting to REST service with HttpsSpring MVC 在使用 Https 连接到 REST 服务时拒绝连接
【发布时间】:2015-11-05 11:28:18
【问题描述】:

服务器端: 我在我的 Ubuntu 笔记本电脑上运行了一个 REST 服务,它是一个 Spring Boot 应用程序,在应用程序属性中包含以下内容

server.port: 8443
server.ssl.key-store: keystore.p12
server.ssl.key-store-password: mypassword
server.ssl.keyStoreType: PKCS12
server.ssl.keyAlias: tomcat
server.address:<My Ip Address>

客户端代码: 我创建了一个调用 Rest 服务的 Web 应用程序,并将其配置为在 Https 上运行。Web 应用程序在 Mac 笔记本电脑上运行,我在我的 Web APP 中进行了配置。Web APP 是一个 Spring MVC 应用程序。

HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier()
        {
            public boolean verify(String hostname, SSLSession session)
            {
                // ip address of the service URL(like.23.28.244.244)
                if (hostname.equals("10.0.0.191"))
                    return true;
                return false;
            }
        });

当我单击网页上调用 REST 服务(在我的 ubuntu 笔记本电脑上运行)的按钮时,出现以下异常

org.springframework.web.client.ResourceAccessException: I/O error: Connection refused; nested exception is java.net.ConnectException: Connection refused
    at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:461)
    at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:409)
    at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:385)
    at com.pcap.webapp.HomeController.getPcapInfo(HomeController.java:172)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

简而言之,我的问题是如何从我的 Web 应用程序(Spring MVC、https、Mac 笔记本电脑)调用我的 REST 服务(即 https,在 ubuntu 上运行,Spring boot)

【问题讨论】:

  • 标准的 HTTPs 端口是 443 但你配置了 8443。这很好,但我没有看到客户端代码在哪里使用端口 8443。也许就是这样?
  • 我还没有粘贴客户端调用 REST api 的代码。这是我的客户端调用其余部分的行 HttpEntity headentity = new HttpEntity(pcap_params,headers); ResponseEntity resp=rt.exchange(uri, HttpMethod.POST, headentity, String.class);并且 uri 是 String uri=new String("10.0.0.191:8443/pcap");

标签: java spring rest spring-mvc ssl


【解决方案1】:

我认为这是防火墙问题,如果是,那么您需要添加这些行。

    System.setProperty("proxyHost", "yourproxy.server.com");
System.setProperty("proxyPort", "8080");

【讨论】:

  • 不,它不是防火墙,因为我能够从我的 mac(客户端)连接在 ubuntu(不同的笔记本电脑)上运行的 https ES 实例
猜你喜欢
  • 2019-02-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-02-21
  • 2018-06-06
  • 2015-09-09
  • 2018-10-19
  • 1970-01-01
相关资源
最近更新 更多