Magnetic field in infinite cylinder with current density The problem read as follows,

Consider an infinite cylinder (in $z$) and with external radius also infinite. In the cylinder flows a current defined by a superficial current density given by:

$$J(r, \theta) = \frac{J_{0} R^2}{r^2}\cos(\theta) \qquad \left[\text{with unit }\frac{\rm A}{\rm m^2}\right]$$

Evaluate the $x$ and $y$ components of the magnetic field in point $P$.

The schematic is,


Here are my attempts:
If I get the idea correctly, there is no current flowing in the inside wire, i.e., $r \leq R$, only for $r > R$. 
I have drawn an amperian loop $\mathscr{C}$ with radius $r$, such that $r > R$ and applied Ampere's Law to it. 
$$\nabla \times \vec{H} = \vec{J}$$
$$\oint_\mathscr{C} \vec{H} \cdot d\vec{l} = \int_S \vec{J} \cdot d\vec{S}$$
$$I_\text{enclosed} \equiv  \int_S \vec{J} \cdot d\vec{S}$$.
Ok, so changing to polar coordinates, we will have $dS = r\ dr\ d\theta$. If I define $d\vec{S}$ outwards the cross section as is $\vec{J}$, we get 
$$I_\text{enclosed} \equiv  \int_S J dS = \int \int \frac{J_{0} R^2}{r^2}\cos(\theta)\cdot r\ dr\ d\theta$$
Here's the issue: should I integrate $r$ for $R < r < +\infty$? If so, then the integral diverges. Should I integrate $\theta$ for $0 < \theta < 2 \pi$? Then the magnetic field is null, which is inconsistent, since in that region there is a current enclosed by the Amperian loop.
 A: Neat problem. In the spirit of our homework policy I'm going to try to give you an answer that addresses your conceptual issue without depriving you of finding your own solution to the problem.
Note that your current distribution has a "supply" current where $0<|\theta|<\frac{2\pi}4$ and an opposing "return" current on the other side of the cylinder.  That current distribution has a different set of symmetries than your Amperian loop that's a circle at constant $r$, so unlike in the straight-wire case, you can't assume that $\oint \vec H \cdot d\vec\ell = 0$ corresponds to $\vec H = 0$.  Your circle has rotational symmetry, but your current distribution has reflection (anti-)symmetry about the $x$- and $y$-axes.  That suggests that sections of the curves $x=0$ and $y=0$ would be interesting to include as segments in your Amperian loop.
A: For starters you need to define the directions for x and y.  I would assume that x is radial in the direction of: θ = 0 degrees and y at 90 degrees with θ measured clockwise in your sketch. In this problem you are not looking for the magnetic field around a symmetrical  loop, but Ampere's law does give the field near a long straight current carrying wire. You will need to add the contributions from a large number of such wires, each of cross-sectional area of (dr)(rdθ).
