com.sun.jersey.api.client.Client.setFollowRedirects()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(9.4k)|赞(0)|评价(0)|浏览(225)

本文整理了Java中com.sun.jersey.api.client.Client.setFollowRedirects()方法的一些代码示例,展示了Client.setFollowRedirects()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Client.setFollowRedirects()方法的具体详情如下:
包路径:com.sun.jersey.api.client.Client
类名称:Client
方法名:setFollowRedirects

Client.setFollowRedirects介绍

[英]Set if redirection should be performed or not. This method is the functional equivalent to setting the property ClientConfig#PROPERTY_FOLLOW_REDIRECTS on the property bag returned from #getProperties
[中]设置是否应执行重定向。此方法的功能相当于在从#getProperties返回的属性包上设置属性ClientConfig#property _FOLLOW_重定向

代码示例

代码示例来源:origin: neo4j/neo4j

@Test
  public void shouldLogStartup()
  {
    // Check the logs
    String logContent = out.toString();
    assertThat( logContent.length(), is( greaterThan( 0 ) ) );
    assertThat( logContent, containsString( NEO4J_IS_STARTING_MESSAGE ) );
    // Check the server is alive
    Client nonRedirectingClient = Client.create();
    nonRedirectingClient.setFollowRedirects( false );
    final JaxRsResponse response = new RestRequest( server.baseUri(), nonRedirectingClient ).get();
    assertThat( response.getStatus(), is( greaterThan( 199 ) ) );

  }
}

代码示例来源:origin: neo4j/neo4j

@Test
public void shouldRedirectOnHtmlRequest()
{
  Client nonRedirectingClient = Client.create();
  nonRedirectingClient.setFollowRedirects( false );
  JaxRsResponse clientResponse =
      new RestRequest( null, nonRedirectingClient ).get( server().baseUri().toString(), TEXT_HTML_TYPE );
  assertEquals( 303, clientResponse.getStatus() );
}

代码示例来源:origin: neo4j/neo4j

@Test
public void shouldRedirectToBrowser() throws Exception
{
  Client nonRedirectingClient = Client.create();
  nonRedirectingClient.setFollowRedirects( false );
  final JaxRsResponse response = new RestRequest( server.baseUri(), nonRedirectingClient ).accept( MediaType
      .TEXT_HTML_TYPE ).get( server.baseUri().toString() );
  assertEquals( 303, response.getStatus() );
  assertEquals( new URI( server.baseUri() + "browser/" ), response.getLocation() );
  response.close();
}

代码示例来源:origin: neo4j/neo4j

@Test
  public void shouldRedirectToBrowserUsingXForwardedHeaders() throws Exception
  {
    Client nonRedirectingClient = Client.create();
    nonRedirectingClient.setFollowRedirects( false );
    final JaxRsResponse response = new RestRequest( server.baseUri(), nonRedirectingClient ).accept( MediaType
        .TEXT_HTML_TYPE ).header( "X-Forwarded-Host", "foo.bar:8734" ).header( "X-Forwarded-Proto",
        "https" ).get( server.baseUri().toString() );

    assertEquals( 303, response.getStatus() );
    assertEquals( new URI( "https://foo.bar:8734/browser/" ), response.getLocation() );
    response.close();
  }
}

代码示例来源:origin: ORCID/ORCID-Source

public DoiBibtexCacheEntryFactory(){
  client.setFollowRedirects(true);
}

代码示例来源:origin: org.apache.apex/malhar-library

@Override
public void setup(OperatorContext context)
{
 wsClient = Client.create();
 wsClient.setFollowRedirects(true);
 logger.debug("URL: {}", url);
}

代码示例来源:origin: org.apache.apex/malhar-library

@Override
public void setup(OperatorContext context)
{
 wsClient = Client.create();
 wsClient.setFollowRedirects(true);
 wsClient.setReadTimeout(readTimeoutMillis);
 resource = wsClient.resource(url.toString()); // side step "not absolute URL" after serialization
 LOG.info("URL: {}", url);
}

代码示例来源:origin: org.epics.channelfinder/cf-client-api

ChannelFinderClientImpl(URI uri, ClientConfig config,
    HTTPBasicAuthFilter httpBasicAuthFilter, ExecutorService executor) {
  Client client = Client.create(config);
  if (httpBasicAuthFilter != null) {
    client.addFilter(httpBasicAuthFilter);
  }
  client.addFilter(new RawLoggingFilter(Logger
      .getLogger(RawLoggingFilter.class.getName())));
  client.setFollowRedirects(true);
  service = client.resource(UriBuilder.fromUri(uri).build());
  this.executor = executor;
}

代码示例来源:origin: ORCID/ORCID-Source

private Client createClient() {
  Set<Class<?>> providers = new HashSet<Class<?>>();
  providers.add(JacksonJsonProvider.class);
  ClientConfig config = new DefaultClientConfig(providers);
  config.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
  Client client = ApacheHttpClient4.create(config);
  client.setFollowRedirects(true);
  client.addFilter(new ContentTypeFromTextToJsonClientFilter());
  return client;
}

代码示例来源:origin: org.opengis.cite/ets-kml22

/**
 * Initializes the HTTP client component. It is configured to follow
 * redirects (status code 3nn) and log the request/response messages to the
 * test suite logger (at INFO level).
 */
@BeforeClass
public void initHttpClient() {
  this.client = Client.create();
  this.client.setFollowRedirects(true);
  this.client.addFilter(new LoggingFilter(TestSuiteLogger.getLogger()));
}

代码示例来源:origin: hburgmeier/jerseyoauth2

@Test
  public void testAuthCodeWithImplicit() throws ClientException
  {
    String code = authClient.authorizeClient(clientEntity, "test1 test2").getCode();
    assertNotNull(code);
    restClient.setFollowRedirects(false);
    
    ResourceClient client = new ResourceClient(clientEntity.getClientId(), GrantType.AUTHORIZATION_REQUEST, ResponseType.CODE);
    String authUrl = client.getAuthUrl(null);
    
    WebResource webResource = restClient.resource(authUrl);
    ClientResponse clientResponse = webResource.get(ClientResponse.class);
    assertTrue(clientResponse.getLocation().toString().startsWith("http://localhost:9998/testsuite?error=unsupported_response_type"));
  }
}

代码示例来源:origin: hburgmeier/jerseyoauth2

@Test
public void testInvalidScopes()
{
  String code = authClient.authorizeClient(clientEntity, "test1 someScope").getCode();
  assertNotNull(code);
  restClient.setFollowRedirects(false);
  
  ResourceClient client = new ResourceClient(clientEntity.getClientId(), clientEntity.getClientSecret(), "test1 test2");
  String authUrl = client.getAuthUrl(null);
  
  WebResource webResource = restClient.resource(authUrl);
  ClientResponse clientResponse = webResource.get(ClientResponse.class);
  assertEquals(302, clientResponse.getStatus());
  assertTrue(clientResponse.getLocation().toString().startsWith("http://localhost:9998/testsuite?code="));
}

代码示例来源:origin: hburgmeier/jerseyoauth2

@Test
public void testNoRefreshToken()
{
  String code = authClient.authorizeClient(clientEntity, "test1 test2").getCode();
  assertNotNull(code);
  restClient.setFollowRedirects(false);
  
  ResourceClient client = new ResourceClient(clientEntity.getClientId(), GrantType.AUTHORIZATION_REQUEST, ResponseType.TOKEN);
  String authUrl = client.getAuthUrl(null);
  
  WebResource webResource = restClient.resource(authUrl);
  ClientResponse clientResponse = webResource.get(ClientResponse.class);
  assertEquals(302, clientResponse.getStatus());
  String fragment = clientResponse.getLocation().getFragment();
  assertNotNull(fragment);
  assertTrue(!fragment.contains("refresh_token"));
}

代码示例来源:origin: hburgmeier/jerseyoauth2

@Test
public void testInvalidCode()
{
  String code = authClient.authorizeClient(clientEntity, "test1 test2").getCode();
  assertNotNull(code);
  restClient.setFollowRedirects(false);
  
  ResourceClient client = new ResourceClient(clientEntity);
  try {
    client.getAccessToken("A"+code);
    fail();
  } catch (TokenExtractorException e) {
  }        
}

代码示例来源:origin: hburgmeier/jerseyoauth2

@Test
public void testAccessToken()
{
  String code = authClient.authorizeClient(clientEntity, "test1 test2").getCode();
  assertNotNull(code);
  restClient.setFollowRedirects(false);
  
  ResourceClient client = new ResourceClient(clientEntity.getClientId(), GrantType.AUTHORIZATION_REQUEST, ResponseType.TOKEN);
  String authUrl = client.getAuthUrl(null);
  
  WebResource webResource = restClient.resource(authUrl);
  ClientResponse clientResponse = webResource.get(ClientResponse.class);
  assertEquals(302, clientResponse.getStatus());
  String fragment = clientResponse.getLocation().getFragment();
  assertNotNull(fragment);
}

代码示例来源:origin: hburgmeier/jerseyoauth2

@Test
public void testInvalidClientSecret()
{
  String code = authClient.authorizeClient(clientEntity, "test1 test2").getCode();
  assertNotNull(code);
  restClient.setFollowRedirects(false);
  
  ResourceClient client = new ResourceClient(clientEntity.getClientId(), "Invalid", "test1 test2");
  try {
    client.getAccessToken(code);
    fail();
  } catch (TokenExtractorException e) {
  }
}

代码示例来源:origin: hburgmeier/jerseyoauth2

@Test
public void testDoubleUseOfCode()
{
  String code = authClient.authorizeClient(clientEntity, "test1 test2").getCode();
  assertNotNull(code);
  restClient.setFollowRedirects(false);
  
  ResourceClient client = new ResourceClient(clientEntity);
  client.getAccessToken(code);
  try {
    client.getAccessToken(code);
    fail();
  } catch (TokenExtractorException e) {
  }        
}

代码示例来源:origin: hburgmeier/jerseyoauth2

@Test
public void testClassAnnotation() throws ClientException
{
  String code = authClient.authorizeClient(clientEntity, "").getCode();
  assertNotNull(code);
  restClient.setFollowRedirects(false);
  
  ResourceClient client = new ResourceClient(clientEntity);
  Token oldToken = client.getAccessToken(code);
  assertNotNull(oldToken);
  assertNotNull(oldToken.getToken());
  
  client.sendTestRequestSample2(oldToken);        
}

代码示例来源:origin: hburgmeier/jerseyoauth2

@BeforeClass
public static void classSetup()
{
  ClientConfig cc = new DefaultClientConfig();
  Client restClient = Client.create(cc);
  ClientManagerClient authClient = new ClientManagerClient(restClient);
  clientEntity = authClient.createClient("confidential");		
  
  String code = authClient.authorizeClient(clientEntity, "test1 test2").getCode();
  assertNotNull(code);
  restClient.setFollowRedirects(false);
  
  client = new ResourceClient(clientEntity);
  token = client.getAccessToken(code);
}

代码示例来源:origin: hburgmeier/jerseyoauth2

@Test
public void testInvalidScopes()
{
  String code = authClient.authorizeClient(clientEntity, "test1 invalidScope").getCode();
  assertNotNull(code);
  restClient.setFollowRedirects(false);
  
  ResourceClient client = new ResourceClient(clientEntity);
  Token tok = client.getAccessToken(code);
  assertNotNull(tok);
  assertNotNull(tok.getToken());
  
  try {
    client.sendTestRequestSample1(tok);
    fail();
  } catch (ClientException cex) {
  }
}

相关文章