Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SpringBoot: use interceptors with Katharsis? #420

Open
adhamhf opened this issue Apr 28, 2017 · 5 comments
Open

SpringBoot: use interceptors with Katharsis? #420

adhamhf opened this issue Apr 28, 2017 · 5 comments

Comments

@adhamhf
Copy link

adhamhf commented Apr 28, 2017

Is it possible to use Spring interceptors with Katharsis? It seems unlikely since Katharsis ends up bypassing Spring MVC which is what provides interceptors, but I thought I would ask.

@jianglibo
Copy link

Katharsis has own interceptors too. For your question, Spring interceptors are sitting in spring dispatch servlet. when you configuring Katharsis as a filter, they are in the different branches, so the answer is no. But it's easy to setup Katharsis as a spring controller and make interceptor work. In most case, it's not necessary. Katharsis is focused on Jsonapi, it solves the problem about jsonapi and does it well.

@adhamhf
Copy link
Author

adhamhf commented May 1, 2017

@jianglibo do you have an example of how to setup Katharsis as a Spring Controller and/or how to use Katharsis interceptors?

@jianglibo
Copy link

Reference the KatharsisFilterV2 class and look at the doFilter code, copy all code to your new created class, for example, named "KatharsisProcessor". Because Katharsis's code is clean and tidy, It's a simple job. after that, create a controller like below.

@Controller
public class KatharsisController {

	@Autowired
	private KatharsisProcessor processor;
	
	@RequestMapping(value="/jsonapi/**")
	public void process(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
		try {
			processor.process(request, response);
		} catch (Exception e) {
			e.printStackTrace();
			throw(e);
		}
	}
}

@chb0github
Copy link
Contributor

Hmm, That's interesting.

@adhamhf
Copy link
Author

adhamhf commented May 4, 2017

@jianglibo this is great. It's not quite as easy as you suggest, but generally it looks to work. It also solves my other issue because I can have more specific paths for endpoints I want to bypass katharsis. This might be a good example.

Here's the documentation on @RequestMapping and regexes. http://docs.spring.io/spring/docs/current/spring-framework-reference/html/mvc.html#mvc-ann-requestmapping-uri-templates-regex

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants