3

I am struggling to get a Jersey client that follows redirects, even though "I know I had this working earlier." (Haven't looked at the code in a while).

I thought had a complex case where it was failing when the redirect was from HTTP to HTTPS. But I cannot get even this simple test below to run:

package com.soliantconsulting.jira.test;

import static org.junit.Assert.*;
import com.sun.jersey.api.client.*;
import org.junit.Test;

public class JerseyClientTest {
    public void test() {
        Client c = Client.create();
        c.setFollowRedirects( true );
        WebResource r = c.resource("http://www.yahoo.com");
        String response = r.get(String.class);
        System.out.println( response );
    }
}

When run, this code throws:

com.sun.jersey.api.client.UniformInterfaceException: GET http://www.yahoo.com returned a response status of 301 Moved Permanently

I've tried a couple different flavors of setting the redirect-follow option, so I must be doing something fundamentally wrong, I think.

Mac OS 10.9.4, JDK 1.7.0_65, Jersey 1.18.1, Eclipse Luna, Maven 3.2.3.

Steve Lane
  • 759
  • 1
  • 5
  • 13

0 Answers0