问题描述
我有一个Java 1.8应用程序,试图与节点v8.10应用程序进行通信。 两者都在同一台(AWS EC2 ubuntu 18.04)服务器上运行。 Java应用程序在带有https的tomcat 8容器中的8443端口上运行。 节点应用程序也在8888端口上使用https在pm2容器v4.4.1中运行。
Java应用程序使用带有某些请求正文参数的POST调用节点应用程序的路由。
如果我使用邮递员发布查询,或者将我的本地dev java服务器插入prod节点应用程序,则一切正常。 但是当两者都在prod服务器上运行时,出现此错误:
Internal Connector Error (1002) - The calling thread timed out while waiting for a response to unblock it.
at org.restlet.resource.ClientResource.handle(ClientResource.java:870)
at org.restlet.resource.ClientResource.post(ClientResource.java:1209)
...
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
这是我使用的Maven仓库:
<dependency>
<groupId>org.restlet.jee</groupId>
<artifactId>org.restlet</artifactId>
<version>2.0.14</version>
</dependency>
这是Java端的代码:
Form form = new Form();
Client client = null;
ClientResource resource = null;
Representation response = null;
form.add("something","somevalue");
try {
client = new Client(new Context(),Protocol.HTTPS);
resource = new ClientResource(resourceURI);
resource.setNext(client);
response = resource.post(form.getWebRepresentation());
} finally {
try {
response.exhaust();
} catch(IOException ioe) {
ioe.printstacktrace();
}
response.release();
resource.release();
}
解决方法
解决方案是在服务器端编辑/ etc / hosts文件,并将DNS添加到localhost定义。 这样,DNS解析是在本地完成的,而无需通过互联网并再次在AWS服务器上循环,这似乎阻止了这种情况。
sudo nano /etc/hosts
127.0.0.1 localhost www.mysite.xyz