检查 Alfresco Endpoint URL 在 Java 中是否可用
Check the Alfresco Endpoint URL is available or not in Java
您好,我创建了一个 Lambda 函数,并尝试检查我的端点之一 URL(Alfresco 进程)是否可用,同时检查 URL 可用性代码完美适用于 http URL 不适用于 HTTP。
我的要求是,如果在检查可用性时端点 URL 不可用,我必须使用 SES 发送邮件我收到 Https URL 的
错误消息
错误:java.net.ConnectException:连接refused: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 服务中使用相同的方法。
提前致谢
根据要求,我已经放置了整个 stackrace
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)
以上代码运行良好。这是我组织的代理问题。如果有人遇到同样的问题,请联系您组织的管理团队,检查是否存在任何防火墙问题
您好,我创建了一个 Lambda 函数,并尝试检查我的端点之一 URL(Alfresco 进程)是否可用,同时检查 URL 可用性代码完美适用于 http URL 不适用于 HTTP。
我的要求是,如果在检查可用性时端点 URL 不可用,我必须使用 SES 发送邮件我收到 Https URL 的
错误消息错误:java.net.ConnectException:连接refused: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 服务中使用相同的方法。 提前致谢
根据要求,我已经放置了整个 stackrace
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)
以上代码运行良好。这是我组织的代理问题。如果有人遇到同样的问题,请联系您组织的管理团队,检查是否存在任何防火墙问题