• 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 think Sequoia will be the last stop for my old 2012 Mac mini (with 16GB RAM & 512MB SSD). It runs Sonoma OK, so perhaps Sequoia will work well too. I don't have high hopes for Tahoe, however - that looks to be a GPU-intense OS.
    • The blobby, bouncy UI effects seem like they would get old really fast. https://www.youtube.com/watch?v=jGztGfRujSE
    • Samsung Galaxy Watch8 Classic allegedly leaked through eBay listing by David Uzondu A new eBay listing (archived) just casually dropped the entire Samsung Galaxy Watch8 Classic on the internet. As spotted by OnLeaks, someone in Wilmington, Illinois, is trying to offload what looks like a genuine, unreleased unit for a "buy it now" price of around $570. To be clear, that is the seller's asking price, not the official figure from Samsung. The listing's title is simple: "Samsung Galaxy Watch8 Classic SM-L505U 64GB LTE 46mm Silver unreleased NOB". You really have to appreciate the audacity of just posting it for the world to see, weeks before its official debut. The photos themselves are a goldmine, showing the SM-L505U model looking exactly like the renders that leaked last month. We are getting a proper physical rotating bezel, which is a big deal for a lot of people. The case itself has this interesting squircle shape, sort of like the icon shapes in OneUI, while the screen inside remains perfectly round. Image via amonste_92 on eBay The watch has a prominent crown nestled between two physical buttons, with a speaker grille visible on the opposite side. The whole package, shown with its leather strap and the usual magnetic charging puck. Image via amonste_92 on eBay That "64GB" in the listing title is a huge detail if it's accurate, as it's double the 32GB of storage as we saw with the Watch 7. Spec-wise, the Watch 8 is rumored to run on the same Exynos W1000 chip that debuted in the Watch 7 last year, which means we might not see a leap in processing power. So you get more space for music and apps, but the core engine remains the same. The Watch8 Classic is rumored to debut with a 435mAh battery, a 1.5-inch display, and One UI 8 Watch.
    • Your own genitals unmatch right toes.
    • I wonder why they jumped from 0.1 to 0.4?
  • Recent Achievements

    • Explorer
      MusicLover2112 went up a rank
      Explorer
    • Dedicated
      MadMung0 earned a badge
      Dedicated
    • Rookie
      CHUNWEI went up a rank
      Rookie
    • Enthusiast
      the420kid went up a rank
      Enthusiast
    • Conversation Starter
      NeoToad777 earned a badge
      Conversation Starter
  • Popular Contributors

    1. 1
      +primortal
      504
    2. 2
      ATLien_0
      268
    3. 3
      +FloatingFatMan
      257
    4. 4
      Edouard
      202
    5. 5
      snowy owl
      177
  • Tell a friend

    Love Neowin? Tell a friend!