Expansion and contraction cylinder with rotary joint