<commit_before>---
title: Interceptors in OSGi
summary: Discussion of the ins and outs of using proxies in OSGi
---

$$$ I am having a bit of trouble digesting the main message because of the structure of the article... Perhaps (even if it is hidden) adding a TOC would help grasp the structure better? $$$

A recurring question on OSGi forums is how to use _interceptors_. The [Spring framework] made it popular to use _aspects_ of Aspect Oriented programming and obviously the desire is then there to use the same mechanisms in OSGi, because they are so enticing. 

## What is an Interceptor?

Let's say we have a function that performs some work. In the following example we need to do some "pre work", "post work", and additionally handle exceptions in similar way:

	void doWork() {
	    preWork();
		try {
		   … do work
		   postWork();
		} catch( Throwable t) {
	       exceptionWork(t);
		   throw t;
		}
	}
	
	void doOtherWork() {
	    preWork();
		try {
		   … do other work
		   postWork();
		} catch( Throwable t) {
	       exceptionWork(t);
		   throw t;<commit_msg>Update interceptors.md<commit_after>---
title: Interceptors in OSGi
summary: Discussion of the ins and outs of using proxies in OSGi
---

A recurring question on OSGi forums is how to use _interceptors_. The [Spring framework] made it popular to use _aspects_ of Aspect Oriented programming and obviously the desire is then there to use the same mechanisms in OSGi, because they are so enticing. 

## What is an Interceptor?

Let's say we have a function that performs some work. In the following example we need to do some "pre work", "post work", and additionally handle exceptions in similar way:

	void doWork() {
	    preWork();
		try {
		   … do work
		   postWork();
		} catch( Throwable t) {
	       exceptionWork(t);
		   throw t;
		}
	}
	
	void doOtherWork() {
	    preWork();
		try {
		   … do other work
		   postWork();
		} catch( Throwable t) {
	       exceptionWork(t);
		   throw t;
{'fraction_non_alphanumeric': 0.07532861476238625, 'fraction_numerical': 0.0, 'mean_word_length': 3.122916666666667, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5905618', 'n_tokens_mistral': 619, 'n_tokens_neox': 544, 'n_words': 279}