sarxos / webcam-capture

The goal of this project is to allow integrated or USB-connected webcams to be accessed directly from Java. Using provided libraries users are able to read camera images and detect motion. Main project consist of several sub projects - the root one, which contains required classes, build-in webcam driver compatible with Windows, Linux and Mac OS, which can stream images as fast as your camera can serve them (up to 50 FPS). Main project can be used standalone, but user is able to replace build-in driver with different one - such as OpenIMAJ, GStreamer, V4L4j, JMF, LTI-CIVIL, FMJ, etc.
http://webcam-capture.sarxos.pl
MIT License
2.27k stars 1.11k forks source link

[ipcam][lib-inside-exception] how capture internal exception when ip cam device not exits #855

Open xlinx opened 2 years ago

xlinx commented 2 years ago

How capture internal exception when ip cam device does not exits when app-start or disconnect auto re-connect? I try to extends IpCamDevice class, but still can't catch the exception from lib inside.


com.github.sarxos.webcam.WebcamException: Cannot download image. Connect to xpad.local:8080 [xpad.local/192.168.51.220, xpad.local/fe80:0:0:0:8a4:3a69:851a:9bba%12] failed: Connection refused (Connection refused)
    at com.github.sarxos.webcam.ds.ipcam.IpCamDevice$PushImageReader.request(IpCamDevice.java:83)
    at com.github.sarxos.webcam.ds.ipcam.IpCamDevice$PushImageReader.run(IpCamDevice.java:94)
Caused by: org.apache.http.conn.HttpHostConnectException: Connect to xpad.local:8080 [xpad.local/192.168.51.220, xpad.local/fe80:0:0:0:8a4:3a69:851a:9bba%12] failed: Connection refused (Connection refused)
Caused by: org.apache.http.conn.HttpHostConnectException: Connect to xpad.local:8080 [xpad.local/192.168.51.220, xpad.local/fe80:0:0:0:8a4:3a69:851a:9bba%12] failed: Connection refused (Connection refused)

    at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:159)
    at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:359)
    at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:381)
    at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:237)
    at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:185)
    at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89)
    at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:111)
    at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:56)
    at com.github.sarxos.webcam.ds.ipcam.IpCamDevice.get(IpCamDevice.java:287)
    at com.github.sarxos.webcam.ds.ipcam.IpCamDevice.access$000(IpCamDevice.java:50)
    at com.github.sarxos.webcam.ds.ipcam.IpCamDevice$PushImageReader.request(IpCamDevice.java:81)
    ... 1 more
Caused by: java.net.ConnectException: Connection refused (Connection refused)
Caused by: java.net.ConnectException: Connection refused (Connection refused)

    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    at java.net.Socket.connect(Socket.java:607)
    at org.apache.http.conn.socket.PlainConnectionSocketFactory.connectSocket(PlainConnectionSocketFactory.java:75)
    at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:142)
xlinx commented 2 years ago

HOW to capture those exceptions that happen from inside

`com.github.sarxos.webcam.WebcamException: Cannot download image. xpad.local: nodename nor servname provided, or not known at com.github.sarxos.webcam.ds.ipcam.IpCamDevice$PushImageReader.request(IpCamDevice.java:83) at com.github.sarxos.webcam.ds.ipcam.IpCamDevice$PushImageReader.run(IpCamDevice.java:94) Caused by: java.net.UnknownHostException: xpad.local: nodename nor servname provided, or not known at java.base/java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method) at java.base/java.net.InetAddress$PlatformNameService.lookupAllHostAddr(InetAddress.java:933) at java.base/java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1519) at java.base/java.net.InetAddress$NameServiceAddresses.get(InetAddress.java:852) at java.base/java.net.InetAddress.getAllByName0(InetAddress.java:1509) at java.base/java.net.InetAddress.getAllByName(InetAddress.java:1367) at java.base/java.net.InetAddress.getAllByName(InetAddress.java:1301) at org.apache.http.impl.conn.SystemDefaultDnsResolver.resolve(SystemDefaultDnsResolver.java:45) at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:112) at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:376) at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:393) at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236) Caused by: java.net.UnknownHostException: xpad.local: nodename nor servname provided, or not known

at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:186) at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89) at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110) at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185) at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83) at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:56) at com.github.sarxos.webcam.ds.ipcam.IpCamDevice.get(IpCamDevice.java:287) at com.github.sarxos.webcam.ds.ipcam.IpCamDevice.access$000(IpCamDevice.java:50) at com.github.sarxos.webcam.ds.ipcam.IpCamDevice$PushImageReader.request(IpCamDevice.java:81) ... 1 more`