BufferedReader bufferedReader = org.mockito.Mockito.mock(BufferedReader.class); when(bufferedReader.readLine()).thenReturn("first line").thenReturn("second line"); org.junit.Assert.when(new Client(bufferedReader).parseLine()).thenEquals(IsEqual.equalTo("1"));
HttpClient apacheClient = HttpClientBuilder.create().build(); Client client = new Client(new ApacheHttpClient4Handler(apacheClient, new BasicCookieStore(), true)); WebResource webResource = client.resource("http://localhost:8080/path"); ClientResponse response = webResource.accept("application/json") .get(ClientResponse.class);
public static class UsesExternalResource { Server myServer = new Server(); @Rule public ExternalResource resource = new ExternalResource() { @Override protected void before() throws Throwable { myServer.connect(); }; @Override protected void after() { myServer.disconnect(); }; }; @Test public void testFoo() { new Client().run(myServer); } }
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 ); }
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); }
Client client = new Client(); ClientResponse response = client.handle( request ); if ( response.hasEntity() && response.getStatus() != 204 )
var postRequest = function(url, args, callback) { var client = new Client(); var responseData = {}; client.post(url, args, function(data, response) { responseData = data; callback(responseData); }); };
final String response = in.nextLine(); EventQueue.invokeLater(new Runnable() { @Override public void run() { new Client(response); } });
public static void main(String args[]) throws InterruptedException { Server server = new Server(); Client client = new Client(); Thread tServer = new Thread(server); tServer.start(); //here you can wait some time to Server started Thread tClient = new Thread(client); tClient.start(); }
/** * Create a default client. * * @return a default client. */ public static Client create() { return new Client(createDefaultClientHander()); }
/** * Create a default client with client configuration. * * @param cc the client configuration. * @return a default client. */ public static Client create(ClientConfig cc) { return new Client(createDefaultClientHander(), cc); }
/** * Create a default client with client configuration and component provider. * * @param cc the client configuration. * @param provider the IoC component provider factory. * @return a default client. */ public static Client create(ClientConfig cc, IoCComponentProviderFactory provider) { return new Client(createDefaultClientHander(), cc, provider); }
async void btn_click(string username,string password) { // This should be an async method as well Client myClient = new Client(); // added await string content = await myClient.authenticate(username, password); Console.Out.WriteLine(content); }
Client client = new Client(); client.setA(56); System.out.println(client.getA()); client.setA(98); System.out.println(client.getA());
private Client getHttpClient() { if (httpClient == null) { ClientConfig config = new DefaultClientConfig(JSONRootElementProvider.App.class); HttpURLConnectionFactory urlFactory = new PseudoAuthenticatedURLConnectionFactory(); return new Client(new URLConnectionClientHandler(urlFactory), config); } return httpClient; }
@Override public Client getHttpClient() { ClientConfig config = new DefaultClientConfig(JSONRootElementProvider.App.class); HttpURLConnectionFactory urlFactory = new PseudoAuthenticatedURLConnectionFactory(connectionConf); Client httpClient = new Client(new URLConnectionClientHandler(urlFactory), config); return httpClient; }
private ObjectNode getMetadataResource(String url){ return new Client().resource(restMetaURL + url ) .header(ACCEPT, MediaType.APPLICATION_JSON) .header(CONTENT_TYPE, MediaType.APPLICATION_JSON) .get(ObjectNode.class); }
private void getMetadataResource( ){ new Client().resource(restURL ) .header(ACCEPT, MediaType.APPLICATION_JSON) .header(CONTENT_TYPE, MediaType.APPLICATION_JSON) .post(GenericCreateAPIResponseEntity.class, requestJson); }
private static Client createClient() { ClientConfig cfg = new DefaultClientConfig(); cfg.getClasses().add(YarnJacksonJaxbJsonProvider.class); return new Client(new URLConnectionClientHandler( new DummyURLConnectionFactory()), cfg); }