Residue theorem. Why is my solution wrong? Question

Calculate the integral:
$$I(a) = \int_0^\infty \frac{x^a}{x^2 + 1} dx$$
for -1 < a < 1.

In my solution, I use the domain $\Omega = \{\epsilon <|z|< R, z \notin \mathbb{R}_+ \}$, where $\epsilon$ is small and $R$ is big. Then I divide $\partial \Omega$ into $\gamma_R$, $\gamma_{\epsilon}$, $l_+$ and $l_-$ with orientation, as shown in the picture (this might not be valid, so if it looks suspicious to you, please skip to the given solution).\

I. Integration: By integrating
$$f(z) = \frac{z^a}{z^2 + 1}$$
on the lines and curves, I get for the curves
$$\int_{\gamma_\epsilon}f(z)dz \quad \text{and} \quad \int_{\gamma_R}f(z)dz \to 0$$
and for the lines
$$\int_{l_+} f(z) dz \to \int_0^\infty \frac{x^a}{x^2 + 1} dx$$
$$\int_{l_-} f(z) dz \to -\int_0^\infty \frac{x^ae^{2a\pi i}}{x^2 + 1} dx$$
as $\epsilon \to 0$ and $R \to \infty$, which means
$$\int_{\partial \Omega}f(z)dz \to (1 - e^{2a\pi i})\int_0^\infty \frac{x^a}{x^2 + 1} dx$$
as $\epsilon \to 0$ and $R \to \infty$.
II.Residue Theorem: Since there are two singularities $i$ and $-i$ with order 1,
$$\int_{\partial \Omega}f(z)dz = 2\pi i (Res(f,i) + Res(f,-i)) = \pi(e^{a\pi i/2} - e^{-a\pi i/2})$$
Overall, we have
$$I(a) = \frac{\pi(e^{a\pi i/2} - e^{-a\pi i/2})}{1 - e^{2a\pi i}} = -\pi e^{-a\pi i}\frac{\sin{a\pi/2}}{\sin{a\pi}}$$
which is not even real.
Given Solution
In the solution given, the domain is the upper half disc of radius R instead. The boundary is divided into the arc, the positive real-axis and the negative real-axis. Integration on the boundary gives
$$\int_{\partial \Omega}f(z)dz = (1 + e^{a\pi i})I(a)$$
Only $i$ is included in the domain as a point for residue calculation, which gives
$$\int_{\partial \Omega}f(z)dz = 2\pi i \frac{e^{a\pi i/2}}{2i} = \pi e^{a\pi i/2}$$
Overall,
$$I(a) = \frac{\pi}{e^{-a\pi i/2} + e^{a\pi i/2}} = \frac{\pi}{2\cos(a\pi/2)}$$
Calculator has proven the above result right. So what went wrong in my solution?
Thank you all in advance!
 A: I may suppose you are doing everything allright, but you have to be careful when identifying poles. As far as I understand you are integrating (circle radius R) counter clockwise; you function should be continuous and single-valued in all plane, except for the cut along the positive part of the axis. It means that the first pole is $e^{\pi i /2}$ (you've made a quarter of full turn counter clockwise), while the second pole is $e^{\pi i3 /2}$ (you've made 3/4 a full turn counter clockwise, i.e. 3/4 of $2\pi$).
Hopefully this will be helpful.
A: As far as I can see, your error is just being inconsistent about the branch of $z^a$ that you're using. In the first part of the calculation, you used a branch that gives the real value of $z^a$ along $l_+$ and gives that real value times $e^{2\pi ia}$ along $l_-$. Then you have to use the same branch when calculating the residues.  You have the right residue at $i$, but the residue at $-i$ should not involve $e^{-a\pi i/2}$ but rather $e^{3a\pi i/2}$. If my (hurried) arithmetic is right, that correction will eliminate the $-e^{-a\pi i}$ factor and will leave you with an answer that agrees with the given solution (thanks to the double-angle formula for the sine function).
A: The function $z^a$ (and hence $\frac{z^a}{z^2 + 1}$) has a branch cut from $0$ to $\infty$.  You have to put the cut on a path somewhere.  The solution you give forces the cut to run along the positive real axis because you want to use Cauchy's results, so the function has to have only point singularities inside your path.  Since the only region you leave outside your path runs along the positive real axis, the integral you write cannot possibly represent the integral you want -- the integral you want is the integral along the branch cut, so depends sensitively on which points of the positive real axis are on this side or that side of the cut.
You want the branch cut to be outside of your path.  The provided solution leaves the entire lower half-plane for the branch cut to run through.  This allows the branch cut to be nowhere near the positive real axis.
Your path is very unlikely to give you the result you want, in general.  Without a branch cut, the lines $\ell_+$ and $\ell_-$ should cancel out, leaving a contribution of $0$ from the positive real axis.  With the branch cut, you are getting two contributions which don't cancel, only one of which is part of the integral you actually want and the other is junk that you have no leverage to remove.
So you want a path that (1) has a component that runs alon the positive $x$ axis (in either direction, but the positive direction is convenient), (2) that encloses one or both of the poles at $\pm \mathrm{i}$ (so, hopefully, you can assign all of the contribution by the residue to the integral of interest), (3) has tiny radius and huge radius circular arcs that can be shown to $\rightarrow 0$ as tiny $\rightarrow 0$ and huge $\rightarrow \infty$, and (4) ends before forcing the branch cut to land on the interval of integration in the original integral and ends on an integral you can do, that reduces to some multiple of the original integral, or has some other (perhaps symmetry) property that allows you to integrate along this path.  This means that you really have no choice on the $\ell_+$, $\gamma_\varepsilon$, and $\gamma_R$ portions of the path except "at what angle do I want this region to stop to satisfy part (4) above -- and it can't be $2\pi$ because then the branch cut stomps on your desired integral.
