检查Alfresco端点URL在Java中是否可用



嗨,我创建了一个 Lambda 函数,并尝试检查我的一个端点 URL(Alfresco进程(是否可用,同时检查 URL 可用性的代码完美适用于 http URL,而不是 HTTP。

我的要求是,如果端点 URL 不可用,我必须使用 SES 发送邮件,同时检查可用性,我得到以下 Https URL 的错误

错误:java.net.Connect异常:连接被拒绝:连接

这是我的示例代码


package com.Firstlambda;
import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.regions.Regions;
import com.amazonaws.services.simpleemail.AmazonSimpleEmailService;
import com.amazonaws.services.simpleemail.AmazonSimpleEmailServiceClientBuilder;
import com.amazonaws.services.simpleemail.model.*;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
public class test {
public static void main(String[] args) throws IOException {
BasicAWSCredentials creds = new BasicAWSCredentials("xxxxxxx",
"xxxxxxxx");
final String FROM = "xxxxxx";
final String TO = "xxxxxx";
//        final String CONFIGSET = "xxxxx";
final String SUBJECT = "Amazon SES test (AWS SDK for Java)";

final String HTMLBODY = "<h1>Amazon SES test (AWS SDK for Java)</h1>"
+ "<p>This email was sent with <a href='https://aws.amazon.com/ses/'>"
+ "Amazon SES</a> using the <a href='https://aws.amazon.com/sdk-for-java/'>"
+ "AWS SDK for Java</a>";

final String TEXTBODY = "This email was sent through Amazon SES "
+ "using the AWS SDK for Java.";
//String GetStaus = getStatus("https://www.youtube.com");
String GetStaus = getStatus("http://localhost:9020/OCR/test");
if (GetStaus.toLowerCase().equals("green")) {
AmazonSimpleEmailService client =
AmazonSimpleEmailServiceClientBuilder.standard()
.withCredentials(new AWSStaticCredentialsProvider(creds))
.withRegion(Regions.US_EAST_1).build();
SendEmailRequest request = new SendEmailRequest()
.withDestination(
new Destination().withToAddresses(TO))
.withMessage(new Message()
.withBody(new Body()
.withHtml(new Content()
.withCharset("UTF-8").withData(HTMLBODY))
.withText(new Content()
.withCharset("UTF-8").withData(TEXTBODY)))
.withSubject(new Content()
.withCharset("UTF-8").withData(SUBJECT)))
.withSource(FROM);
client.sendEmail(request);
}
System.out.println("Email sent!");
}

public static String getStatus(String url) throws IOException {
String result = "";
try {
URL siteURL = new URL(url);
HttpURLConnection connection = (HttpURLConnection) siteURL
.openConnection();
connection.setRequestMethod("GET");
connection.connect();
int code = connection.getResponseCode();
if (code == 200) {
result = "Green";
}
} catch (Exception e) {
result = "->Red<-";
}
return result;
}
}

谁能帮我如何在我的 Spring 启动 java 应用程序中检查 http 的 URL 的可用性?如果解决,我也必须在我的 java 服务中使用相同的。 提前致谢

按照要求,我已经放置了我的整个堆栈

java.net.ConnectException: Connection refused: connect
at java.base/java.net.PlainSocketImpl.connect0(Native Method)
at java.base/java.net.PlainSocketImpl.socketConnect(PlainSocketImpl.java:101)
at java.base/java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:399)
at java.base/java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:242)
at java.base/java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:224)
at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:403)
at java.base/java.net.Socket.connect(Socket.java:591)
at java.base/sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:285)
at java.base/sun.security.ssl.BaseSSLSocketImpl.connect(BaseSSLSocketImpl.java:173)
at java.base/sun.net.NetworkClient.doConnect(NetworkClient.java:182)
at java.base/sun.net.www.http.HttpClient.openServer(HttpClient.java:474)
at java.base/sun.net.www.http.HttpClient.openServer(HttpClient.java:569)
at java.base/sun.net.www.protocol.https.HttpsClient.<init>(HttpsClient.java:265)
at java.base/sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:372)
at java.base/sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:191)
at java.base/sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1181)
at java.base/sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:1075)
at java.base/sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:177)
at java.base/sun.net.www.protocol.https.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:163)
at com.Firstlambda.test.getStatus(test.java:70)
at com.Firstlambda.test.main(test.java:35)

上面的代码工作正常。这是我组织的代理问题。如果有人遇到同样的问题,请联系您组织的管理团队以检查是否存在任何防火墙问题

相关内容

  • 没有找到相关文章

最新更新