]> git.basschouten.com Git - openhab-addons.git/blob
f63e75e90b2db6ccf878815a836b72f31343fca1
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.io.neeo.internal.servletservices;
14
15 import java.io.IOException;
16
17 import javax.servlet.http.HttpServletRequest;
18 import javax.servlet.http.HttpServletResponse;
19
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.eclipse.jdt.annotation.Nullable;
22 import org.openhab.core.events.Event;
23 import org.openhab.core.events.EventFilter;
24
25 /**
26  * The interface definition for a servlet service. This interface describes the contract for any implemenation wanting
27  * to be a service for a servlet - which includes determining whether a route is valid for it, handling get/post and
28  * handling events.
29  *
30  * @author Tim Roberts - Initial Contribution
31  */
32 @NonNullByDefault
33 public interface ServletService extends AutoCloseable {
34
35     /**
36      * Determines if the service can handle a route
37      *
38      * @param paths the non-null, possibly empty route paths
39      * @return true if it can handle the route, false otherwise
40      */
41     boolean canHandleRoute(String[] paths);
42
43     /**
44      * Handles the get request. Will only be called if {@link #canHandleRoute(String[])} returns true
45      *
46      * @param req the non-null {@link HttpServletRequest}
47      * @param paths the non-null, possibly empty route paths
48      * @param resp the non-null {@link HttpServletResponse}
49      * @throws IOException Signals that an I/O exception has occurred.
50      */
51     void handleGet(HttpServletRequest req, String[] paths, HttpServletResponse resp) throws IOException;
52
53     /**
54      * Handles the post request. Will only be called if {@link #canHandleRoute(String[])} returns true
55      *
56      * @param req the non-null {@link HttpServletRequest}
57      * @param paths the non-null, possibly empty route paths
58      * @param resp the non-null {@link HttpServletResponse}
59      * @throws IOException Signals that an I/O exception has occurred.
60      */
61     void handlePost(HttpServletRequest req, String[] paths, HttpServletResponse resp) throws IOException;
62
63     /**
64      * Handles the event request and should return true if handled (false if not)
65      *
66      * @param event the non-null event
67      * @return true if handled, false otherwise
68      */
69     boolean handleEvent(Event event);
70
71     /**
72      * Returns the {@link EventFilter} to use to filter events
73      *
74      * @return the possibly null event filter;
75      */
76     @Nullable
77     EventFilter getEventFilter();
78 }