• 0

HttpServletResponse is missing


Question

I have a Java Spring Boot project that uses React as a front end. In order to allow web crawlers to index the site I (with the help of examples found by googling) decided to implement a HandlerInterceptorAdapter where I would match the requested URI and redirect to my default controller if needed. I got stuck very quickly though. This is my entire interceptor as of now:

 

import org.apache.catalina.servlet4preview.http.HttpServletRequest;
import org.apache.catalina.servlet4preview.http.HttpServletResponse;
import org.apache.catalina.servlet4preview.http.ServletMapping;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;


public class Interceptor extends HandlerInterceptorAdapter {

    @Override
    public boolean preHandle(HttpServletRequest request,
                             HttpServletResponse response,
                             Object handler) throws Exception {

        ServletMapping mapping = request.getServletMapping();
        String uri = request.getRequestURI();
        System.out.println("uri:"+uri+"; servletName:"+mapping.getServletName()+"; class:"+mapping.getClass());
        return true;
    }
}

As you can see I am trying to make it compile at least. The second argument of preHandle() expects HttpServletResponse which needs to be imported from org.apache.catalina.servlet4preview.http. The one from javax.servlet.http doesn't count. Right now HttpServletResponse doesn't exist inside the catalina package.

To make things worse there is not logical connections between the import statements and the artifact ids. I can only guess. I have in project's pom.xml dependencies for tomcat-servlet-api and org.apache.catalina. Catalina cannot even be resolved (even though I have https://mvnrepository.com set as a secondary repository)

 

        <dependency>
            <groupId>org.apache.catalina</groupId>
            <artifactId>catalina</artifactId>
            <version>6.0.26</version>
        </dependency>
        <dependency>
            <groupId>org.apache.tomcat</groupId>
            <artifactId>tomcat-servlet-api</artifactId>
            <version>7.0.52</version>
            <scope>provided</scope>
        </dependency>

 

P.S. This project is to be deployed to a Tomcat server, so I need to use Catalina/Tomcat variants of the libraries

Link to comment
https://www.neowin.net/forum/topic/1393373-httpservletresponse-is-missing/
Share on other sites

1 answer to this question

Recommended Posts

  • 0

Ok, this is my mistake - even though the project goes to a standalone Tomcat server that doesn't mean that Tomcat/Catalina specific imports need to be used. javax.servlet.http package is to be used. Going like this the code compiles fine

 

 

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;


public class DefaultController extends HandlerInterceptorAdapter {

    @Override
    public boolean preHandle(HttpServletRequest request,
                             HttpServletResponse response,
                             Object handler) throws Exception {

        String uri = request.getRequestURI();
        System.out.println("uri:"+uri+"; servletPath:"+request.getServletPath()+"; class:"+request.getClass());
        return true;
    }
}

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Posts

    • Secret Changelog: New Features: Settings > Start, home, and new tab page > New tab page > Copilot new tab page (Chat, search, and navigate with a modern new tab page inspired by Copilot) Settings > AI innovations (Explore Copilot Mode)
    • Microsoft is adding some very useful features to Word, Teams, Outlook, and more by Usama Jawad Image via Microsoft Microsoft 365 is the Redmond tech firm's premier solution for Office apps and cloud storage, among other things. Microsoft offers both consumer- and enterprise-oriented subscriptions for this solution, enabling customers to take full advantage of cloud-powered capabilities, in contrast to the LTSC versions of Office. Microsoft 365 apps and services regularly receive new updates and the good thing is that Microsoft tracks them in a very transparent way on its public roadmap. The Redmond company has updated its Microsoft 365 Roadmap with a lot of items in the past week or so, and there are several interesting features there that may excite its customers. For starters, Word is getting a very useful utility that will likely help people writing detailed documents using the software. Microsoft is integrating third-party citation providers in the Reference tab, so that users can quickly add citations. This is being made available to GCC, GCC High, and Department of Defense (DoD) customers on desktop and web this month. There are several improvements on the way for Copilot Notebooks too. Users can customize the format, style, and duration of Audio Overviews in the application through natural language prompts. These Audio Overviews can then be saved on OneDrive so that they can be shared with others too. All of these capabilities are landing on the web next month. Speaking of Copilot, Microsoft is moving the navigation pane for Copilot Chat from the right side of the app to the left. Apart from retaining the existing features, this repositioning allows Microsoft to add new capabilities such as an All Conversations tab, while also streamlining the overall navigation experience. This is being implemented for all customers using Outlook and Teams on the web from next month. In the latter software, Microsoft is also introducing regional settings that gives controls over the app's language and datetime formats. This is being made available for all Teams customers on Android, iOS, desktop, and the web from next month. Meanwhile, the desktop version of Teams is exclusively gaining the ability next month to search for meetings and participants in the search bar and take actions directly from there. Available actions include viewing recaps, accessing the dedicated meetings tab, and RSVP-ing. Microsoft added 39 items to the Microsoft 365 Roadmap, so you can understand that the selection of items described above is only scratching the tip of the iceberg. Check out other upcoming capabilities like Universal Print enhancements and more Copilot improvements on the dedicated webpage here.
    • PC to remote Android phone possible?
    • The same idiots that provide their phone numbers and id to discord channels.
  • Recent Achievements

    • Week One Done
      hhgygy earned a badge
      Week One Done
    • One Month Later
      hhgygy earned a badge
      One Month Later
    • One Year In
      NIKI77 earned a badge
      One Year In
    • Week One Done
      artistro08 earned a badge
      Week One Done
    • Dedicated
      Balaji Kumar earned a badge
      Dedicated
  • Popular Contributors

    1. 1
      +primortal
      639
    2. 2
      ATLien_0
      237
    3. 3
      Xenon
      166
    4. 4
      neufuse
      144
    5. 5
      +FloatingFatMan
      122
  • Tell a friend

    Love Neowin? Tell a friend!