package cn.reghao.tnb.oss.store.tomcat;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.Writer;

/**
 * @author reghao
 * @date 2024-12-19 11:39:47
 */
@Slf4j
@Component
public class GlobalServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        String uri = request.getRequestURI();
        log.info("request uri -> {}", uri);

        response.setCharacterEncoding("UTF-8");
        response.setContentType("text/plain");
        response.setHeader("Server", "Embedded Tomcat");
        try (Writer writer = response.getWriter()) {
            writer.write("Hello, Embedded Tomcat!");
            writer.flush();
        }
    }
}
