mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-10 15:11:59 +01:00
[ipcamera] Make sure created Servlet supports async (#14552)
Fixes the folowing errors: ``` HTTP ERROR 500 java.lang.IllegalStateException: !asyncSupported: NotAsync:org.ops4j.pax.web.service.spi.servlet.OsgiInitializedServlet@536b0858 URI: /ipcamera/192168493/ipcamera.jpg STATUS: 500 MESSAGE: java.lang.IllegalStateException: !asyncSupported: NotAsync:org.ops4j.pax.web.service.spi.servlet.OsgiInitializedServlet@536b0858 SERVLET: org.openhab.binding.ipcamera.internal.servlet.CameraServlet CAUSED BY: java.lang.IllegalStateException: !asyncSupported: NotAsync:org.ops4j.pax.web.service.spi.servlet.OsgiInitializedServlet@536b0858 Powered by Jetty:// 9.4.50.v20221201 ``` See: * https://community.openhab.org/t/openhab-4-0-snapshot-discussion/142322/226 * https://groups.google.com/g/ops4j/c/E9p7tPydPmo * https://github.com/ops4j/org.ops4j.pax.web/issues/1767 Signed-off-by: Wouter Born <github@maindrain.net>
This commit is contained in:
parent
5c0b5711a8
commit
50cdd02447
@ -17,6 +17,9 @@ import static org.openhab.binding.ipcamera.internal.IpCameraBindingConstants.HLS
|
||||
import java.io.IOException;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.util.Dictionary;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.AsyncContext;
|
||||
import javax.servlet.ServletInputStream;
|
||||
@ -41,13 +44,16 @@ import org.osgi.service.http.HttpService;
|
||||
@NonNullByDefault
|
||||
public class CameraServlet extends IpCameraServlet {
|
||||
private static final long serialVersionUID = -134658667574L;
|
||||
private static final Dictionary<Object, Object> INIT_PARAMETERS = new Hashtable<>(
|
||||
Map.of("async-supported", "true"));
|
||||
|
||||
private final IpCameraHandler handler;
|
||||
public OpenStreams openStreams = new OpenStreams();
|
||||
private OpenStreams openSnapshotStreams = new OpenStreams();
|
||||
private OpenStreams openAutoFpsStreams = new OpenStreams();
|
||||
|
||||
public CameraServlet(IpCameraHandler handler, HttpService httpService) {
|
||||
super(handler, httpService);
|
||||
super(handler, httpService, INIT_PARAMETERS);
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
@ -183,8 +189,7 @@ public class CameraServlet extends IpCameraServlet {
|
||||
} else {
|
||||
output = new StreamOutput(resp, handler.mjpegContentType);
|
||||
}
|
||||
} else {
|
||||
if (handler.mjpegUri.isEmpty() || "ffmpeg".equals(handler.mjpegUri)) {
|
||||
} else if (handler.mjpegUri.isEmpty() || "ffmpeg".equals(handler.mjpegUri)) {
|
||||
output = new StreamOutput(resp);
|
||||
} else {
|
||||
ChannelTracking tracker = handler.channelTrackingMap.get(handler.getTinyUrl(handler.mjpegUri));
|
||||
@ -194,7 +199,6 @@ public class CameraServlet extends IpCameraServlet {
|
||||
}
|
||||
output = new StreamOutput(resp, handler.mjpegContentType);
|
||||
}
|
||||
}
|
||||
openStreams.addStream(output);
|
||||
do {
|
||||
try {
|
||||
|
@ -17,6 +17,8 @@ import java.io.BufferedOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Dictionary;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.annotation.WebServlet;
|
||||
@ -42,16 +44,22 @@ public abstract class IpCameraServlet extends HttpServlet {
|
||||
private static final long serialVersionUID = 1L;
|
||||
protected final ThingHandler handler;
|
||||
protected final HttpService httpService;
|
||||
protected final Dictionary<Object, Object> initParameters;
|
||||
|
||||
public IpCameraServlet(ThingHandler handler, HttpService httpService) {
|
||||
this(handler, httpService, new Properties());
|
||||
}
|
||||
|
||||
public IpCameraServlet(ThingHandler handler, HttpService httpService, Dictionary<Object, Object> initParameters) {
|
||||
this.handler = handler;
|
||||
this.httpService = httpService;
|
||||
this.initParameters = initParameters;
|
||||
startListening();
|
||||
}
|
||||
|
||||
public void startListening() {
|
||||
try {
|
||||
httpService.registerServlet("/ipcamera/" + handler.getThing().getUID().getId(), this, null,
|
||||
httpService.registerServlet("/ipcamera/" + handler.getThing().getUID().getId(), this, initParameters,
|
||||
httpService.createDefaultHttpContext());
|
||||
} catch (Exception e) {
|
||||
logger.warn("Registering servlet failed:{}", e.getMessage());
|
||||
|
Loading…
Reference in New Issue
Block a user