In der Spring Framework-Dokumentation gibt RestTemplate an, dass org.springframework.web.client.RestClientException ausgelöst wird. Wenn Sie die Ausnahme abfangen und den Inhalt überprüfen, können Sie sehen, dass die Unterklasse von RestClientException tatsächlich ausgelöst wird.
--RestClientException (die Klasse, auf der die von RestTemplate ausgelöste Ausnahme basiert) --RestClientResponseException (Klasse, für die die Ausnahme HTTP-Antwortdaten enthält) --HttpStatusCodeException (abstrakte Ausnahmeklasse basierend auf Statuscode) --HttpClientErrorException (beim Empfang von HTTP 4xx-Serien) --Jede Ausnahmeklasse (Plural) des 4xx-Serienstatuscodes --HttpServerErrorException (beim Empfang von HTTP 5xx-Serien) --Jede Ausnahmeklasse (Plural) des Statuscodes der Serie 5xx --UnknownHttpStatusCodeException (wenn der Statuscode unbekannt ist) --ResourceAccessException (wenn ein E / A-Fehler auftritt)
--Ausnahme, die aufgetreten ist: org.springframework.web.client.HttpClientErrorException $ NotFound --HttpClientErrorException.NotFound ist eine Unterklasse von org.springframework.web.client.HttpClientErrorException
--Ausnahme, die aufgetreten ist: org.springframework.web.client.HttpServerErrorException $ InternalServerError --HttpServerErrorException.InternalServerError ist eine Unterklasse von org.springframework.web.client.HttpServerErrorException
--Ausnahme, die aufgetreten ist: org.springframework.web.client.UnknownHttpStatusCodeException
--Exception: java.lang.IllegalArgumentException
--Ausnahme, die aufgetreten ist: java.net.URISyntaxException
--Ausnahme, die aufgetreten ist: org.springframework.web.client.ResourceAccessException
--Ausnahme, die aufgetreten ist: org.springframework.web.client.ResourceAccessException
--Ausnahme, die aufgetreten ist: org.springframework.web.client.ResourceAccessException
--Ausnahme, die aufgetreten ist: org.springframework.web.client.ResourceAccessException
--Ausnahme, die aufgetreten ist: org.springframework.web.client.ResourceAccessException
--Ausnahme, die aufgetreten ist: org.springframework.web.client.ResourceAccessException
├── pom.xml
└── src
└── main
└── java
└── com
└── example
└── MyHttpClient.java
Erstellen Sie dieses Mal das Beispielprogramm mit Maven. Die RestTemplate-Klasse ist im Spring Web des Spring Framework enthalten. Fügen Sie daher den Abhängigkeiten Spring-Web hinzu.
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>my-http-client</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<!-- http://maven.apache.org/plugins/maven-assembly-plugin/ -->
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>com.example.MyHttpClient</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-web -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>5.1.8.RELEASE</version>
</dependency>
</dependencies>
</project>
MyHttpClient.java
Eine Klasse zum Überprüfen verschiedener Ausnahmen, die während der HTTP-Kommunikation auftreten.
package com.example;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.RequestEntity;
import org.springframework.http.ResponseEntity;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.web.client.ResourceAccessException;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestClientResponseException;
import org.springframework.web.client.RestTemplate;
import java.net.URI;
import java.net.URISyntaxException;
public class MyHttpClient {
public static void main(String[] args) {
RestTemplate restTemplate = new RestTemplate();
//Timeout-Wert einstellen
if(restTemplate.getRequestFactory() instanceof SimpleClientHttpRequestFactory) {
SimpleClientHttpRequestFactory rf = (SimpleClientHttpRequestFactory)restTemplate.getRequestFactory();
rf.setConnectTimeout(1000); //Stellen Sie das Verbindungszeitlimit auf 1000 Millisekunden ein
rf.setReadTimeout(1000); //Stellen Sie das Lesezeitlimit auf 1000 Millisekunden ein
}
//Gibt den Klassennamen von ClientHttpRequestFactory aus, der intern von RestTemplate verwendet wird
System.out.println("ClientHttpRequestFactory: " + restTemplate.getRequestFactory().getClass().getName());
//Probieren Sie verschiedene Muster aus
get("HTTP 200 OK", restTemplate, "http://localhost:8000/");
get("HTTP 301 Moved Permanently (Weiterleitungen sollten automatisch behandelt werden)", restTemplate, "http://localhost:8000/?status=301&headers=%7B%22location%22%3A%22http%3A%2F%2Flocalhost%3A8000%2F%22%7D");
get("HTTP 404 Not Found", restTemplate, "http://localhost:8000/?status=404");
get("HTTP 500 Internal Server Error", restTemplate, "http://localhost:8000/?status=500");
get("Unbekannter Statuscode", restTemplate, "http://localhost:8000/?status=599");
get("Keine URL-Zeichenfolge", restTemplate, "foo");
get("Kann nicht als URL-Zeichenfolge analysiert werden", restTemplate, "http://local host:8000/");
get("Unbekannter URL-Schemaname", restTemplate, "foo://localhost:8000/");
get("Die IP-Adresse kann nicht vom Hostnamen abgezogen werden", restTemplate, "http://localhostlocalhost:8000/");
get("Port, an dem der Webserver nicht gestartet wird", restTemplate, "http://localhost:1234/");
get("Nicht vertrauenswürdiges SSL-Serverzertifikat(Selbstsigniertes Zertifikat,Oreore-Zertifikat)", restTemplate, "https://localhost:8443/");
get("Verbindungszeitüberschreitung(Connection Timeout)IP-Adresse, bei der das Gerät nicht vorhanden ist", restTemplate, "http://127.0.0.2/");
get("Zeitüberschreitung lesen(Read Timeout)", restTemplate, "http://localhost:8000/?wait=10");
}
/**
*Greifen Sie auf die angegebene URL zu und geben Sie die Informationen aus.
*
* @Param Titel Titel(Erklärung, welche Art von Muster)
* @param restTemplate RestTemplate-Objekt, das für die HTTP-Kommunikation verwendet wird
* @Parameter URL URL für den Zugriff
*/
private static void get(String title, RestTemplate restTemplate, String url) {
try {
System.out.println("************************************************************");
System.out.println(title);
System.out.println("URL: " + url);
URI uri = new URI(url);
RequestEntity req = RequestEntity.get(uri).build();
ResponseEntity<String> res = restTemplate.exchange(req, String.class);
HttpStatus status = res.getStatusCode();
HttpHeaders headers = res.getHeaders();
String body = res.getBody();
System.out.println("Status: " + status);
} catch (RestClientResponseException e) {
System.out.println("Class: " + e.getClass().getName());
int statusCode = e.getRawStatusCode();
String statusText = e.getStatusText();
System.out.println("StatusCode: " + statusCode);
System.out.println("StatusText: " + statusText);
e.printStackTrace();
} catch (ResourceAccessException e) {
System.out.println("Class: " + e.getClass().getName());
e.printStackTrace();
} catch (RestClientException e) {
System.out.println("Class: " + e.getClass().getName());
e.printStackTrace();
} catch (URISyntaxException e) {
System.out.println("Class: " + e.getClass().getName());
e.printStackTrace();
} catch (Exception e) {
System.out.println("Class: " + e.getClass().getName());
e.printStackTrace();
}
}
}
Generieren Sie eine JAR-Datei mit dem Befehl mvn package.
$ mvn package
Führen Sie das Beispielprogramm aus, um festzustellen, welche Ausnahmen in den einzelnen Mustern auftreten.
$ java -jar target/my-http-client-1.0-SNAPSHOT-jar-with-dependencies.jar
ClientHttpRequestFactory: org.springframework.http.client.SimpleClientHttpRequestFactory
************************************************************
HTTP 200 OK
URL: http://localhost:8000/
Status: 200 OK
************************************************************
HTTP 301 Moved Permanently (Weiterleitungen sollten automatisch behandelt werden)
URL: http://localhost:8000/?status=301&headers=%7B%22location%22%3A%22http%3A%2F%2Flocalhost%3A8000%2F%22%7D
Status: 200 OK
************************************************************
HTTP 404 Not Found
URL: http://localhost:8000/?status=404
Class: org.springframework.web.client.HttpClientErrorException$NotFound
StatusCode: 404
StatusText: Not Found
org.springframework.web.client.HttpClientErrorException$NotFound: 404 Not Found
at org.springframework.web.client.HttpClientErrorException.create(HttpClientErrorException.java:85)
at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:122)
at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:102)
at org.springframework.web.client.ResponseErrorHandler.handleError(ResponseErrorHandler.java:63)
at org.springframework.web.client.RestTemplate.handleResponse(RestTemplate.java:778)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:736)
at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:637)
at com.example.MyHttpClient.get(MyHttpClient.java:62)
at com.example.MyHttpClient.main(MyHttpClient.java:35)
************************************************************
HTTP 500 Internal Server Error
URL: http://localhost:8000/?status=500
Class: org.springframework.web.client.HttpServerErrorException$InternalServerError
StatusCode: 500
StatusText: Internal Server Error
org.springframework.web.client.HttpServerErrorException$InternalServerError: 500 Internal Server Error
at org.springframework.web.client.HttpServerErrorException.create(HttpServerErrorException.java:79)
at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:124)
at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:102)
at org.springframework.web.client.ResponseErrorHandler.handleError(ResponseErrorHandler.java:63)
at org.springframework.web.client.RestTemplate.handleResponse(RestTemplate.java:778)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:736)
at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:637)
at com.example.MyHttpClient.get(MyHttpClient.java:62)
at com.example.MyHttpClient.main(MyHttpClient.java:36)
************************************************************
Unbekannter Statuscode
URL: http://localhost:8000/?status=599
Class: org.springframework.web.client.UnknownHttpStatusCodeException
StatusCode: 599
StatusText: null
org.springframework.web.client.UnknownHttpStatusCodeException: Unknown status code [599] null
at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:100)
at org.springframework.web.client.ResponseErrorHandler.handleError(ResponseErrorHandler.java:63)
at org.springframework.web.client.RestTemplate.handleResponse(RestTemplate.java:778)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:736)
at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:637)
at com.example.MyHttpClient.get(MyHttpClient.java:62)
at com.example.MyHttpClient.main(MyHttpClient.java:37)
************************************************************
Keine URL-Zeichenfolge
URL: foo
Class: java.lang.IllegalArgumentException
java.lang.IllegalArgumentException: URI is not absolute
at java.base/java.net.URL.fromURI(URL.java:674)
at java.base/java.net.URI.toURL(URI.java:1116)
at org.springframework.http.client.SimpleClientHttpRequestFactory.createRequest(SimpleClientHttpRequestFactory.java:145)
at org.springframework.http.client.support.HttpAccessor.createRequest(HttpAccessor.java:87)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:731)
at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:637)
at com.example.MyHttpClient.get(MyHttpClient.java:62)
at com.example.MyHttpClient.main(MyHttpClient.java:38)
************************************************************
Kann nicht als URL-Zeichenfolge analysiert werden
URL: http://local host:8000/
Class: java.net.URISyntaxException
java.net.URISyntaxException: Illegal character in authority at index 7: http://local host:8000/
at java.base/java.net.URI$Parser.fail(URI.java:2915)
at java.base/java.net.URI$Parser.parseAuthority(URI.java:3249)
at java.base/java.net.URI$Parser.parseHierarchical(URI.java:3160)
at java.base/java.net.URI$Parser.parse(URI.java:3116)
at java.base/java.net.URI.<init>(URI.java:600)
at com.example.MyHttpClient.get(MyHttpClient.java:60)
at com.example.MyHttpClient.main(MyHttpClient.java:39)
************************************************************
Unbekannter URL-Schemaname
URL: foo://localhost:8000/
Class: org.springframework.web.client.ResourceAccessException
org.springframework.web.client.ResourceAccessException: I/O error on GET request for "foo://localhost:8000/": unknown protocol: foo; nested exception is java.net.MalformedURLException: unknown protocol: foo
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:744)
at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:637)
at com.example.MyHttpClient.get(MyHttpClient.java:62)
at com.example.MyHttpClient.main(MyHttpClient.java:40)
Caused by: java.net.MalformedURLException: unknown protocol: foo
at java.base/java.net.URL.<init>(URL.java:634)
at java.base/java.net.URL.fromURI(URL.java:701)
at java.base/java.net.URI.toURL(URI.java:1116)
at org.springframework.http.client.SimpleClientHttpRequestFactory.createRequest(SimpleClientHttpRequestFactory.java:145)
at org.springframework.http.client.support.HttpAccessor.createRequest(HttpAccessor.java:87)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:731)
... 3 more
************************************************************
Die IP-Adresse kann nicht vom Hostnamen abgezogen werden
URL: http://localhostlocalhost:8000/
Class: org.springframework.web.client.ResourceAccessException
org.springframework.web.client.ResourceAccessException: I/O error on GET request for "http://localhostlocalhost:8000/": localhostlocalhost; nested exception is java.net.UnknownHostException: localhostlocalhost
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:744)
at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:637)
at com.example.MyHttpClient.get(MyHttpClient.java:62)
at com.example.MyHttpClient.main(MyHttpClient.java:41)
Caused by: java.net.UnknownHostException: localhostlocalhost
at java.base/java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:220)
at java.base/java.net.Socket.connect(Socket.java:591)
at java.base/sun.net.NetworkClient.doConnect(NetworkClient.java:177)
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.http.HttpClient.<init>(HttpClient.java:242)
at java.base/sun.net.www.http.HttpClient.New(HttpClient.java:341)
at java.base/sun.net.www.http.HttpClient.New(HttpClient.java:362)
at java.base/sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:1242)
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.http.HttpURLConnection.connect(HttpURLConnection.java:1009)
at org.springframework.http.client.SimpleBufferingClientHttpRequest.executeInternal(SimpleBufferingClientHttpRequest.java:76)
at org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal(AbstractBufferingClientHttpRequest.java:48)
at org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:53)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:735)
... 3 more
************************************************************
Port, an dem der Webserver nicht gestartet wird
URL: http://localhost:1234/
Class: org.springframework.web.client.ResourceAccessException
org.springframework.web.client.ResourceAccessException: I/O error on GET request for "http://localhost:1234/": Connection refused (Connection refused); nested exception is java.net.ConnectException: Connection refused (Connection refused)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:744)
at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:637)
at com.example.MyHttpClient.get(MyHttpClient.java:62)
at com.example.MyHttpClient.main(MyHttpClient.java:42)
Caused by: java.net.ConnectException: Connection refused (Connection refused)
at java.base/java.net.PlainSocketImpl.socketConnect(Native Method)
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.Socket.connect(Socket.java:591)
at java.base/sun.net.NetworkClient.doConnect(NetworkClient.java:177)
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.http.HttpClient.<init>(HttpClient.java:242)
at java.base/sun.net.www.http.HttpClient.New(HttpClient.java:341)
at java.base/sun.net.www.http.HttpClient.New(HttpClient.java:362)
at java.base/sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:1242)
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.http.HttpURLConnection.connect(HttpURLConnection.java:1009)
at org.springframework.http.client.SimpleBufferingClientHttpRequest.executeInternal(SimpleBufferingClientHttpRequest.java:76)
at org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal(AbstractBufferingClientHttpRequest.java:48)
at org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:53)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:735)
... 3 more
************************************************************
Nicht vertrauenswürdiges SSL-Serverzertifikat(Selbstsigniertes Zertifikat,Oreore-Zertifikat)
URL: https://localhost:8443/
Class: org.springframework.web.client.ResourceAccessException
org.springframework.web.client.ResourceAccessException: I/O error on GET request for "https://localhost:8443/": PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target; nested exception is javax.net.ssl.SSLHandshakeException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:744)
at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:637)
at com.example.MyHttpClient.get(MyHttpClient.java:62)
at com.example.MyHttpClient.main(MyHttpClient.java:43)
Caused by: javax.net.ssl.SSLHandshakeException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at java.base/sun.security.ssl.Alert.createSSLException(Alert.java:128)
at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:321)
at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:264)
at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:259)
at java.base/sun.security.ssl.CertificateMessage$T12CertificateConsumer.checkServerCerts(CertificateMessage.java:642)
at java.base/sun.security.ssl.CertificateMessage$T12CertificateConsumer.onCertificate(CertificateMessage.java:461)
at java.base/sun.security.ssl.CertificateMessage$T12CertificateConsumer.consume(CertificateMessage.java:361)
at java.base/sun.security.ssl.SSLHandshake.consume(SSLHandshake.java:392)
at java.base/sun.security.ssl.HandshakeContext.dispatch(HandshakeContext.java:444)
at java.base/sun.security.ssl.HandshakeContext.dispatch(HandshakeContext.java:421)
at java.base/sun.security.ssl.TransportContext.dispatch(TransportContext.java:178)
at java.base/sun.security.ssl.SSLTransport.decode(SSLTransport.java:164)
at java.base/sun.security.ssl.SSLSocketImpl.decode(SSLSocketImpl.java:1152)
at java.base/sun.security.ssl.SSLSocketImpl.readHandshakeRecord(SSLSocketImpl.java:1063)
at java.base/sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:402)
at java.base/sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:567)
at java.base/sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)
at java.base/sun.net.www.protocol.https.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:163)
at org.springframework.http.client.SimpleBufferingClientHttpRequest.executeInternal(SimpleBufferingClientHttpRequest.java:76)
at org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal(AbstractBufferingClientHttpRequest.java:48)
at org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:53)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:735)
... 3 more
Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at java.base/sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:385)
at java.base/sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:290)
at java.base/sun.security.validator.Validator.validate(Validator.java:264)
at java.base/sun.security.ssl.X509TrustManagerImpl.validate(X509TrustManagerImpl.java:321)
at java.base/sun.security.ssl.X509TrustManagerImpl.checkTrusted(X509TrustManagerImpl.java:221)
at java.base/sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:129)
at java.base/sun.security.ssl.CertificateMessage$T12CertificateConsumer.checkServerCerts(CertificateMessage.java:626)
... 20 more
Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at java.base/sun.security.provider.certpath.SunCertPathBuilder.build(SunCertPathBuilder.java:141)
at java.base/sun.security.provider.certpath.SunCertPathBuilder.engineBuild(SunCertPathBuilder.java:126)
at java.base/java.security.cert.CertPathBuilder.build(CertPathBuilder.java:297)
at java.base/sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:380)
... 26 more
************************************************************
Verbindungszeitüberschreitung(Connection Timeout)IP-Adresse, bei der das Gerät nicht vorhanden ist
URL: http://127.0.0.2/
Class: org.springframework.web.client.ResourceAccessException
org.springframework.web.client.ResourceAccessException: I/O error on GET request for "http://127.0.0.2/": connect timed out; nested exception is java.net.SocketTimeoutException: connect timed out
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:744)
at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:637)
at com.example.MyHttpClient.get(MyHttpClient.java:62)
at com.example.MyHttpClient.main(MyHttpClient.java:44)
Caused by: java.net.SocketTimeoutException: connect timed out
at java.base/java.net.PlainSocketImpl.socketConnect(Native Method)
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.Socket.connect(Socket.java:591)
at java.base/sun.net.NetworkClient.doConnect(NetworkClient.java:177)
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.http.HttpClient.<init>(HttpClient.java:242)
at java.base/sun.net.www.http.HttpClient.New(HttpClient.java:341)
at java.base/sun.net.www.http.HttpClient.New(HttpClient.java:362)
at java.base/sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:1242)
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.http.HttpURLConnection.connect(HttpURLConnection.java:1009)
at org.springframework.http.client.SimpleBufferingClientHttpRequest.executeInternal(SimpleBufferingClientHttpRequest.java:76)
at org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal(AbstractBufferingClientHttpRequest.java:48)
at org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:53)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:735)
... 3 more
************************************************************
Zeitüberschreitung lesen(Read Timeout)
URL: http://localhost:8000/?wait=10
Class: org.springframework.web.client.ResourceAccessException
org.springframework.web.client.ResourceAccessException: I/O error on GET request for "http://localhost:8000/": Read timed out; nested exception is java.net.SocketTimeoutException: Read timed out
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:744)
at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:637)
at com.example.MyHttpClient.get(MyHttpClient.java:62)
at com.example.MyHttpClient.main(MyHttpClient.java:45)
Caused by: java.net.SocketTimeoutException: Read timed out
at java.base/java.net.SocketInputStream.socketRead0(Native Method)
at java.base/java.net.SocketInputStream.socketRead(SocketInputStream.java:115)
at java.base/java.net.SocketInputStream.read(SocketInputStream.java:168)
at java.base/java.net.SocketInputStream.read(SocketInputStream.java:140)
at java.base/java.io.BufferedInputStream.fill(BufferedInputStream.java:252)
at java.base/java.io.BufferedInputStream.read1(BufferedInputStream.java:292)
at java.base/java.io.BufferedInputStream.read(BufferedInputStream.java:351)
at java.base/sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:746)
at java.base/sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:689)
at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1604)
at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1509)
at java.base/java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:527)
at org.springframework.http.client.SimpleBufferingClientHttpRequest.executeInternal(SimpleBufferingClientHttpRequest.java:82)
at org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal(AbstractBufferingClientHttpRequest.java:48)
at org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:53)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:735)
... 3 more