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

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

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

Client.create介绍

[英]Create a default client.
[中]创建一个默认客户端。

代码示例

代码示例来源:origin: pentaho/pentaho-kettle

/**
 * Template method to allow tooling to override Client factory
 * 
 */
private static com.sun.jersey.api.client.Client createClientInstance( ClientConfig cc ) {
 return com.sun.jersey.api.client.Client.create( cc );
}

代码示例来源:origin: apache/incubator-druid

public OpentsdbSender(
  String host,
  int port,
  int connectionTimeout,
  int readTimeout,
  int flushThreshold,
  int maxQueueSize,
  long consumeDelay
)
{
 this.flushThreshold = flushThreshold;
 this.consumeDelay = consumeDelay;
 eventQueue = new ArrayBlockingQueue<>(maxQueueSize);
 scheduler = Executors.newScheduledThreadPool(2, new ThreadFactoryBuilder()
   .setDaemon(true)
   .setNameFormat("OpentsdbEventSender-%s")
   .build());
 eventConsumer = new EventConsumer();
 client = Client.create();
 client.setConnectTimeout(connectionTimeout);
 client.setReadTimeout(readTimeout);
 webResource = client.resource("http://" + host + ":" + port + PATH);
}

代码示例来源:origin: pentaho/pentaho-kettle

@Override
 public Object call() throws Exception {
  ClientConfig clientConfig = new DefaultClientConfig();
  Client client = Client.create( clientConfig );
  client.addFilter( new HTTPBasicAuthFilter( username, password ) );
  Class<?>[] parameterTypes = new Class<?>[] { Client.class, URI.class };
  String factoryClassName = webServiceSpecification.getServiceClass().getName();
  factoryClassName = factoryClassName.substring( 0, factoryClassName.lastIndexOf( "$" ) );
  Class<?> factoryClass = Class.forName( factoryClassName );
  Method method =
    factoryClass.getDeclaredMethod( webServiceSpecification.getServiceName(), parameterTypes );
  T port = (T) method.invoke( null, new Object[] { client, new URI( baseUrl + "/plugin" ) } );
  return port;
 }
} );

代码示例来源:origin: apache/usergrid

public AbstractRestOperation( HttpOp op, String path, Runner runner ) {
  Preconditions.checkNotNull( op, "The 'op' MUST NOT be null." );
  Preconditions.checkNotNull( path, "The 'path' MUST NOT be null." );
  Preconditions.checkNotNull( runner, "The 'runner' MUST NOT be null." );
  this.path = path;
  this.op = op;
  this.resource = Client.create().resource( runner.getUrl() ).path( getPath() );
  resource = RestRequests.addParams(resource, runner);
}

代码示例来源:origin: signalapp/BitHub

public GithubClient(String user, String token) {
 this.authorizationHeader = getAuthorizationHeader(user, token);
 this.client              = Client.create(getClientConfig());
}

代码示例来源:origin: apache/usergrid

@Override
  public int getNextRunNumber( final Project project ) {
    WebResource resource = Client.create().resource( coordinatorFig.getEndpoint() );
    resource = addQueryParameters( resource, project, me );
    Integer result = resource.path( coordinatorFig.getRunNextPath() )
                 .type( MediaType.APPLICATION_JSON_TYPE )
                 .get( Integer.class );

    LOG.debug( "Got back result from next run number get = {}", result );

    return result;
  }
}

代码示例来源:origin: apache/usergrid

@Override
public void register( final Runner runner ) {
  WebResource resource = Client.create().resource( coordinatorFig.getEndpoint() );
  resource = addQueryParameters( resource, project, runner );
  Boolean result = resource.path( coordinatorFig.getRunnersRegisterPath() )
              .type( MediaType.APPLICATION_JSON ).post( Boolean.class, runner );
  LOG.debug( "Got back results from register post = {}", result );
}

代码示例来源:origin: pentaho/pentaho-kettle

/**
 * Use REST API to authenticate provided credentials
 * 
 * @throws Exception
 */
@VisibleForTesting
void authenticateLoginCredentials() throws Exception {
 KettleClientEnvironment.init();
 if ( client == null ) {
  ClientConfig clientConfig = new DefaultClientConfig();
  clientConfig.getFeatures().put( JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE );
  client = Client.create( clientConfig );
  client.addFilter( new HTTPBasicAuthFilter( username, Encr.decryptPasswordOptionallyEncrypted( password ) ) );
 }
 WebResource resource = client.resource( url + AUTHENTICATION + AdministerSecurityAction.NAME );
 String response = resource.get( String.class );
 if ( !response.equals( "true" ) ) {
  throw new Exception( Messages.getInstance().getString( "REPOSITORY_CLEANUP_UTIL.ERROR_0012.ACCESS_DENIED" ) );
 }
}

代码示例来源:origin: apache/usergrid

@Override
public void unregister( final Runner runner ) {
  if ( RunnerConfig.isTestMode() ) {
    return;
  }
  WebResource resource = Client.create().resource( coordinatorFig.getEndpoint() );
  resource = addQueryParameters( resource, project, runner );
  String result = resource.path( coordinatorFig.getRunnersUnregisterPath() )
              .type( MediaType.TEXT_PLAIN ).post( String.class );
  LOG.debug( "Got back results from unregister post = {}", result );
}

代码示例来源:origin: Netflix/conductor

protected ClientBase(ClientConfig config, ConductorClientConfiguration clientConfiguration, ClientHandler handler) {
  objectMapper = new JsonMapperProvider().get();
  JacksonJsonProvider provider = new JacksonJsonProvider(objectMapper);
  config.getSingletons().add(provider);
  if (handler == null) {
    this.client = Client.create(config);
  } else {
    this.client = new Client(handler, config);
  }
  conductorClientConfiguration = clientConfiguration;
  payloadStorage = new PayloadStorage(this);
}

代码示例来源:origin: apache/usergrid

@Override
public List<Runner> getRunners() {
  // get a list of all runners associated with this project
  WebResource resource = Client.create().resource( coordinatorFig.getEndpoint() );
  resource = addQueryParameters( resource, project, me );
  List<Runner> runners = resource.path( coordinatorFig.getRunnersListPath() )
               .type( MediaType.APPLICATION_JSON )
               .accept( MediaType.APPLICATION_JSON_TYPE )
               .get( new GenericType<List<Runner>>() {} );
  LOG.debug( "Got back runners list = {}", runners );
  return runners;
}

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

private static Client createClient() throws Exception
  {
    HostnameVerifier hostnameVerifier = HttpsURLConnection.getDefaultHostnameVerifier();
    ClientConfig config = new DefaultClientConfig();
    SSLContext ctx = SSLContext.getInstance( "TLS" );
    ctx.init( null, new TrustManager[]{new InsecureTrustManager()}, null );
    config.getProperties().put( PROPERTY_HTTPS_PROPERTIES, new HTTPSProperties( hostnameVerifier, ctx ) );
    return Client.create( config );
  }
}

代码示例来源: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

/**
 * Create a Jersey HTTP client that is able to talk HTTPS and trusts all certificates.
 *
 * @return new client.
 */
private static Client createClient()
{
  try
  {
    HostnameVerifier hostnameVerifier = HttpsURLConnection.getDefaultHostnameVerifier();
    ClientConfig config = new DefaultClientConfig();
    SSLContext ctx = SSLContext.getInstance( "TLS" );
    ctx.init( null, new TrustManager[]{new InsecureTrustManager()}, null );
    Map<String,Object> properties = config.getProperties();
    properties.put( PROPERTY_HTTPS_PROPERTIES, new HTTPSProperties( hostnameVerifier, ctx ) );
    properties.put( PROPERTY_FOLLOW_REDIRECTS, false );
    return Client.create( config );
  }
  catch ( Exception e )
  {
    throw new RuntimeException( e );
  }
}

代码示例来源:origin: pentaho/pentaho-kettle

@Test
 public void callStopCarteRestService() throws Exception {
  WebResource status = mock( WebResource.class );
  doReturn( "<serverstatus>" ).when( status ).get( String.class );

  WebResource stop = mock( WebResource.class );
  doReturn( "Shutting Down" ).when( stop ).get( String.class );

  Client client = mock( Client.class );
  doCallRealMethod().when( client ).addFilter( any( HTTPBasicAuthFilter.class ) );
  doCallRealMethod().when( client ).getHeadHandler();
  doReturn( status ).when( client ).resource( "http://localhost:8080/kettle/status/?xml=Y" );
  doReturn( stop ).when( client ).resource( "http://localhost:8080/kettle/stopCarte" );

  mockStatic( Client.class );
  when( Client.create( any( ClientConfig.class ) ) ).thenReturn( client );

  Carte.callStopCarteRestService( "localhost", "8080", "admin", "Encrypted 2be98afc86aa7f2e4bb18bd63c99dbdde" );

  // the expected value is: "Basic <base64 encoded username:password>"
  assertEquals( "Basic " + new String( Base64.getEncoder().encode( "admin:password".getBytes( "utf-8" ) ) ),
   getInternalState( client.getHeadHandler(), "authentication" ) );
 }
}

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

public RestRequest( URI baseUri, String username, String password )
{
  this.baseUri = uriWithoutSlash( baseUri );
  if ( username != null )
  {
    client = Client.create();
    client.addFilter( new HTTPBasicAuthFilter( username, password ) );
  }
  else
  {
    client = DEFAULT_CLIENT;
  }
}

代码示例来源:origin: soabase/exhibitor

public RemoteInstanceRequestClientImpl(RemoteConnectionConfiguration configuration)
{
  client = Client.create();
  client.setConnectTimeout(configuration.getConnectionTimeoutMs());
  client.setReadTimeout(configuration.getReadTimeoutMs());
  for ( ClientFilter filter : configuration.getFilters() )
  {
    client.addFilter(filter);
  }
}

代码示例来源: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();
  }
}

相关文章