• 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

    • I am using Waterfox Private Search now that I started using the Waterfox browser on my PC and Android. Both work great* search waterfox net with full stops in between. * I have an issue where making comments on articles on various websites is difficult with Waterfox on Android as it randomly adds spaces and doubles up on text.
    • I can't believe it was only two years since the last time MS raised their prices and now they think they can do it again so soon. Of course they needed to backtrack on this. I hope Nintendo is next.
    • I guess I gotta be even more specific then since I'm looking for an absolute confirmation.  The mini PC has never booted up or powered on by me. I'm assuming it'll be like buying a new PC from a store. Nothing is set up. Like absolutely nothing on the mini PC because I can't emphasize this enough. My USB drive already has Windows set up on it from my other desktop so I know it's clean. So now I connect it to the mini PC before it's even booted up or go to the desktop. I then turn on the mini PC and boot into the USB drive. I should see an existing partition. I'll delete it and then install Windows again over the entire drive. I don't necessarily want to create a separate partition. Once it installs and boots to the desktop, I'm assuming the drive is "clean" and free of any malware/viruses. Basically, this process will eliminate any potential for malware/viruses to still somehow hide in the SSD and then potentially affect me later.  I'm being very anal about this because I really don't trust anything bought from AliExpress, but the price was very tempting.  Is Windows Defender reliable? Afterwards, if I do a full scan and it doesn't find anything in the SSD and the USB drive, can I be confident the mini PC is now safe and secured to enter my banking credentials? If not, what else can I do to be absolutely certain?
    • I got an ESR Qi2 vent charger for my car and it's fantastic. It's very strong magnet and holds the phone securely over the worst potholes/roads, and my iPhone does charge. In Summer, the AC blows on the vent keeps and keeps the phone cold. In winter, I just close that vent, so it still stays cold. I agree with you on the Android front. Why not just build in the magnets like Apple does? It's frustrating to buy a case that adds magnets.
    • Hey, I've been using Windows since I was a little tyke. But for the last 15 years, I have been using Linux. I'm using EndeavourOS/Arch atm. wipe it, as in deleting anything from the SSD in the computer. Make a new partition. USB booting device should be free of malware, as long as you download it directly friom MS. Not some XYZ company.
  • Recent Achievements

    • Collaborator
      fernan99 earned a badge
      Collaborator
    • Collaborator
      MikeK13 earned a badge
      Collaborator
    • One Month Later
      Alexander 001 earned a badge
      One Month Later
    • One Month Later
      Antonio Barboza earned a badge
      One Month Later
    • Week One Done
      Antonio Barboza earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      581
    2. 2
      ATLien_0
      217
    3. 3
      Michael Scrip
      168
    4. 4
      Xenon
      136
    5. 5
      +FloatingFatMan
      124
  • Tell a friend

    Love Neowin? Tell a friend!