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

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

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

Client.addFilter介绍

暂无

代码示例

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

/**
 * @param config              REST Client configuration
 * @param clientConfiguration Specific properties configured for the client, see {@link ConductorClientConfiguration}
 * @param handler             Jersey client handler. Useful when plugging in various http client interaction modules (e.g. ribbon)
 * @param filters             Chain of client side filters to be applied per request
 */
public MetadataClient(ClientConfig config, ConductorClientConfiguration clientConfiguration, ClientHandler handler, ClientFilter... filters) {
  super(config, clientConfiguration, handler);
  for (ClientFilter filter : filters) {
    super.client.addFilter(filter);
  }
}

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

/**
 * @param config              REST Client configuration
 * @param clientConfiguration Specific properties configured for the client, see {@link ConductorClientConfiguration}
 * @param handler             Jersey client handler. Useful when plugging in various http client interaction modules (e.g. ribbon)
 * @param filters             Chain of client side filters to be applied per request
 */
public TaskClient(ClientConfig config, ConductorClientConfiguration clientConfiguration, ClientHandler handler, ClientFilter... filters) {
  super(config, clientConfiguration, handler);
  for (ClientFilter filter : filters) {
    super.client.addFilter(filter);
  }
}

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

/**
 * @param config              REST Client configuration
 * @param clientConfiguration Specific properties configured for the client, see {@link ConductorClientConfiguration}
 * @param handler             Jersey client handler. Useful when plugging in various http client interaction modules (e.g. ribbon)
 * @param filters             Chain of client side filters to be applied per request
 */
public WorkflowClient(ClientConfig config, ConductorClientConfiguration clientConfiguration, ClientHandler handler, ClientFilter... filters) {
  super(config, clientConfiguration, handler);
  for (ClientFilter filter : filters) {
    super.client.addFilter(filter);
  }
}

代码示例来源:origin: stackoverflow.com

Client client = Client.create();
client.addFilter(new LoggingFilter());

代码示例来源:origin: stackoverflow.com

Client client = Client.create();
client.addFilter(new LoggingFilter(System.out));
WebResource webResource = client.resource("http://localhost:9998/");
ClientResponse response = webResource.accept(MediaType.APPLICATION_JSON)
                     .get(ClientResponse.class);

代码示例来源:origin: stackoverflow.com

Client client = Client.create();
WebResource resource = client.resource(BASE_URI);
client.addFilter(new HTTPBasicAuthFilter("peeskillet", "pass"));
String response = resource.get(String.class);

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

private void initManaged( PurRepositoryMeta repositoryMeta, IUser userInfo ) throws JSONException {
 String baseUrl = repositoryMeta.getRepositoryLocation().getUrl();
 String webService = baseUrl + ( baseUrl.endsWith( "/" ) ? "" : "/" ) + "api/system/authentication-provider";
 HTTPBasicAuthFilter authFilter = new HTTPBasicAuthFilter( userInfo.getLogin(), userInfo.getPassword() );
 Client client = new Client();
 client.addFilter( authFilter );
 WebResource.Builder resource = client.resource( webService ).accept( MediaType.APPLICATION_JSON_TYPE );
 /**
  * if set, _trust_user_ needs to be considered. See other places in pur-plugin's:
  *
  * @link https://github.com/pentaho/pentaho-kettle/blob/8.0.0.0-R/plugins/pur/core/src/main/java/org/pentaho/di/repository/pur/PurRepositoryConnector.java#L97-L101
  * @link https://github.com/pentaho/pentaho-kettle/blob/8.0.0.0-R/plugins/pur/core/src/main/java/org/pentaho/di/repository/pur/WebServiceManager.java#L130-L133
  */
 if ( StringUtils.isNotBlank( System.getProperty( "pentaho.repository.client.attemptTrust" ) ) ) {
  resource = resource.header( TRUST_USER, userInfo.getLogin() );
 }
 String response = resource.get( String.class );
 String provider = new JSONObject( response ).getString( "authenticationType" );
 managed = "jackrabbit".equals( provider );
}

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

Client client = Client.create( clientConfig );
client.addFilter( new HTTPBasicAuthFilter( username, Encr.decryptPasswordOptionallyEncrypted( password ) ) );

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

OAuthParameters params = new OAuthParameters().consumerKey(input.oauthConsumerKey).signatureMethod("HMAC-SHA1").version("1.0");
OAuthSecrets secrets = new OAuthSecrets().consumerSecret(input.oauthConsumerSecret);
client.addFilter(new OAuthClientFilter(client.getProviders(), params, secrets));

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

client.addFilter( data.basicAuthentication );

代码示例来源:origin: stackoverflow.com

ClientConfig config = new DefaultClientConfig();
Client client = Client.create(config);
client.addFilter(new LoggingFilter());
WebResource service = client.resource(getBaseURI());
JSONObject inputJsonObj = new JSONObject();
inputJsonObj.put("input", "Value");
System.out.println(service.path("rest").path("hello").accept(MediaType.APPLICATION_JSON).post(JSONObject.class, inputJsonObj));

代码示例来源:origin: uber/AthenaX

/**
 * Build the Client used to make HTTP requests with the latest settings,
 * i.e. objectMapper and debugging.
 * TODO: better to use the Builder Pattern?
 * @return API client
 */
public ApiClient rebuildHttpClient() {
 // Add the JSON serialization support to Jersey
 JacksonJsonProvider jsonProvider = new JacksonJsonProvider(objectMapper);
 DefaultClientConfig conf = new DefaultClientConfig();
 conf.getSingletons().add(jsonProvider);
 Client client = Client.create(conf);
 client.addFilter(new GZIPContentEncodingFilter(false));
 if (debugging) {
  client.addFilter(new LoggingFilter());
 }
 this.httpClient = client;
 return this;
}

代码示例来源:origin: magefree/mage

public static boolean sendMessage(String email, String subject, String text) {
    if (email.isEmpty()) {
      logger.info("Email is not sent because the address is empty");
      return false;
    }
    Client client = Client.create();
    client.addFilter(new HTTPBasicAuthFilter("api", ConfigSettings.instance.getMailgunApiKey()));
    String domain = ConfigSettings.instance.getMailgunDomain();
    WebResource webResource = client.resource("https://api.mailgun.net/v3/" + domain + "/messages");
    MultivaluedMapImpl formData = new MultivaluedMapImpl();
    formData.add("from", "XMage <postmaster@" + domain + '>');
    formData.add("to", email);
    formData.add("subject", subject);
    formData.add("text", text);
    ClientResponse response =  webResource.type(MediaType.APPLICATION_FORM_URLENCODED).post(ClientResponse.class, formData);
    boolean succeeded = response.getStatus() == 200;
    if (!succeeded) {
      logger.error("Error sending message to " + email + ". Status code: " + response.getStatus());
    }
    return succeeded;
  }
}

代码示例来源:origin: org.ow2.xlcloud/openstack-commons

/**
 * Producess Client with default filters
 * @param client
 */
private void attachDefaultFilters(Client client) {
  client.addFilter(new ClientLoggingFilter());
  client.addFilter(new ExceptionHandlingFilter());
  client.addFilter(new PerformanceMonitorFilter());
}

代码示例来源:origin: com.aspose/aspose-cloud-barcode

private Client getClient(String host) {
   if (!hostMap.containsKey(host)) {
  Client client = Client.create();
     if (isDebug){ 
   client.addFilter(new LoggingFilter());
     }
  hostMap.put(host, client);
 }
 return hostMap.get(host);
}

相关文章