I am interested to compute the following integral
$$I=\int_{0}^{+\infty}\frac{\cos x}{a^2+x^2}dx$$
where $a\in\mathbb{R}^+$. Let me explain my first idea. As the integrand is an even function of $x$ then
$$2I=\int_{-\infty}^{+\infty}\frac{\cos x}{a^2+x^2}dx=\lim_{R\to+\infty}\int_{-R}^{R}\frac{\cos x}{a^2+x^2}dx:=\lim_{R\to+\infty}J$$
So, I first focus on computing the $J$ integral by first modifying it as follows
\begin{align*} J&=\int_{-R}^{R}\frac{\cos x}{a^2+x^2}dx=\int_{-R}^{R}\frac{\cos x}{a^2+x^2}dx+i\int_{-R}^{R}\frac{\sin x}{a^2+x^2}dx \\ &= \int_{-R}^{R}\frac{(\cos x+i\sin x)}{a^2+x^2}dx = \int_{-R}^{R}\frac{\exp(ix)}{a^2+x^2}dx \end{align*}
Then, I use the well-known techniques of complex variable theory. First, I replace the real variable $x$ in $J$ with a complex variable $z$ and consider a contour integral over $C=C_1\cup C_2$
$$K:=\int_{C}\frac{\exp(iz)}{a^2+z^2}dz$$
Then, according to the Cauchy's integral theorem and the Residue theorem, I get
\begin{align*} K=J+\int_{C_2}\frac{\exp(iz)}{a^2+z^2}dz &= \int_{C_3}\frac{\exp(iz)}{a^2+z^2}dz=\int_{C_3}\frac{\exp(iz)}{(z+ia)(z-ia)}dz \\ &=2\pi i \frac{\exp(i^2a)}{2ia}=\frac{\pi}{a}\exp(-a) \end{align*}
Next, taking the limit $R\to+\infty$ from the above relation, we obtain
$$2I+\lim_{R\to+\infty}\int_{C_2}\frac{\exp(iz)}{a^2+z^2}dz=\frac{\pi}{a}\exp(-a)$$
but, we can show that
$$\lim_{R\to+\infty}\int_{C_2}\frac{\exp(iz)}{a^2+z^2}dz=0$$
and then we can obtain the final result
$$I=\frac{\pi}{2a}\exp(-a)$$
First, please check my steps to see the final result is correct or not. Second, is there any other way to compute $I$?