从本地JAR运行以下代码时:
public static List<Message> getMessages(AmazonSQS sqs, String queueUrl) throws IOException {
ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest(queueUrl).withWaitTimeSeconds(5);
List<Message> messages = sqs.receiveMessage(receiveMessageRequest).getMessages();
return messages;
}
它运作得很好。但是当尝试在EC2实例上远程运行它时,我得到以下异常:
2014年4月15日8:30:48 com.amazonaws.http.AmazonHttpClient executeHelper INFO:无法执行HTTP请求:peer not not 经过身份验证的javax.net.ssl.SSLPeerUnverifiedException:peer not 认证 at sun.security.ssl.SSLSessionImpl.getPeerCertificates(SSLSessionImpl.java:371) at org.apache.http.conn.ssl.AbstractVerifier.verify(AbstractVerifier.java:126) at org.apache.http.conn.ssl.SSLSocketFactory.connectSocket(SSLSocketFactory.java:572) at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:1 80) at org.apache.http.impl.conn.ManagedClientConnectionImpl.open(ManagedClientConnectionImpl.java:294) at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:645) 在org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:480) at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:906) 在org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:805) 在com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:384) 在com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:232) 在com.amazonaws.services.sqs.AmazonSQSClient.invoke(AmazonSQSClient.java:2170) 在com.amazonaws.services.sqs.AmazonSQSClient.receiveMessage(AmazonSQSClient.java:942) 在Utils.getMessages(Utils.java:80) 在Manager.run(Manager.java:51) 在Main.main(Main.java:10) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 在java.lang.reflect.Method.invoke(Method.java:616) 在org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
搜索这些异常只会提出明确使用HttpClient的人提出的问题,以及与我的使用情况无关的解决方案。
答案 0 :(得分:1)
问题是我使用了错误的AMI,使用了不兼容的JRE。