2 * Copyright (c) 2010-2022 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.mielecloud.internal.config.servlet;
15 import java.io.IOException;
17 import javax.servlet.ServletException;
18 import javax.servlet.http.HttpServlet;
19 import javax.servlet.http.HttpServletRequest;
20 import javax.servlet.http.HttpServletResponse;
22 import org.eclipse.jdt.annotation.NonNullByDefault;
23 import org.eclipse.jdt.annotation.Nullable;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
28 * Base class for servlets that have no visible frontend and just serve the purpose of redirecting the user to another
31 * @author Björn Lange - Initial Contribution
34 public abstract class AbstractRedirectionServlet extends HttpServlet {
35 private static final long serialVersionUID = 4280026301732437523L;
37 private final Logger logger = LoggerFactory.getLogger(AbstractRedirectionServlet.class);
40 protected void doGet(@Nullable HttpServletRequest request, @Nullable HttpServletResponse response)
41 throws ServletException, IOException {
42 if (response == null) {
43 logger.warn("Ignoring received request without response.");
46 if (request == null) {
47 logger.warn("Ignoring illegal request.");
48 response.sendError(HttpServletResponse.SC_BAD_REQUEST);
52 response.sendRedirect(getRedirectionDestination(request));
56 * Gets the redirection destination. This can be a relative or absolute path or a link to another website.
58 * @param request The original request sent by the browser.
59 * @return The redirection destination.
61 protected abstract String getRedirectionDestination(HttpServletRequest request);