Client client = Client.create(); WebResource webResource = client.resource("http://localhost:8080/helloworld"); String s = webResource.get(String.class); System.out.println(s); // prints Hello World
Client client = Client.create(); WebResource resource = client.resource(BASE_URI); client.addFilter(new HTTPBasicAuthFilter("peeskillet", "pass")); String response = resource.get(String.class);
String response = webResource.get(String.class);
/** * 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" ) ); } }
@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" ) ); } }
String response = resource.get( String.class ); if ( response == null || !response.contains( "<serverstatus>" ) ) { throw new Carte.CarteCommandException( BaseMessages.getString( PKG, "Carte.Error.NoServerFound", hostname, "" response = resource.get( String.class ); if ( response == null || !response.contains( "Shutting Down" ) ) { throw new Carte.CarteCommandException( BaseMessages.getString( PKG, "Carte.Error.NoShutdown", hostname, ""
@Test public void shouldLoadThirdPartyJaxRsClasses() throws Exception { server = CommunityServerBuilder.serverOnRandomPorts() .withThirdPartyJaxRsPackage( "org.dummy.web.service", DummyThirdPartyWebService.DUMMY_WEB_SERVICE_MOUNT_POINT ) .usingDataDir( folder.directory( name.getMethodName() ).getAbsolutePath() ) .build(); server.start(); URI thirdPartyServiceUri = new URI( server.baseUri() .toString() + DummyThirdPartyWebService.DUMMY_WEB_SERVICE_MOUNT_POINT ).normalize(); String response = CLIENT.resource( thirdPartyServiceUri.toString() ) .get( String.class ); assertEquals( "hello", response ); // Assert that extensions gets initialized int nodesCreated = createSimpleDatabase( server.getDatabase().getGraph() ); thirdPartyServiceUri = new URI( server.baseUri() .toString() + DummyThirdPartyWebService.DUMMY_WEB_SERVICE_MOUNT_POINT + "/inject-test" ).normalize(); response = CLIENT.resource( thirdPartyServiceUri.toString() ) .get( String.class ); assertEquals( String.valueOf( nodesCreated ), response ); }
@Test public void testGetKey() { WebResource r = resource().path("/druid/v1/lookups/introspect/lookupId1/keys"); String s = r.get(String.class); Assert.assertEquals("[key, key2]", s); }
@Test public void testGetValue() { WebResource r = resource().path("/druid/v1/lookups/introspect/lookupId1/values"); String s = r.get(String.class); Assert.assertEquals("[value, value2]", s); }
@Test public void testGetMap() { WebResource r = resource().path("/druid/v1/lookups/introspect/lookupId1/"); String s = r.get(String.class); Assert.assertEquals("{\"key\":\"value\",\"key2\":\"value2\"}", s); } }
public void doTest() { WebResource resource = resource().path("service"); String result = resource.get(String.class); Assert.assertEquals("Hello World!", result); System.out.println(result);
/** {@inheritDoc} */ @Override public Feature read(String uid) { if (uid == null || uid.isEmpty()) { throw new IllegalArgumentException(FEATURE_IDENTIFIER_CANNOT_BE_NULL_NOR_EMPTY); } ClientResponse cRes = getStore().path(uid).get(ClientResponse.class); if (Status.NOT_FOUND.getStatusCode() == cRes.getStatus()) { throw new FeatureNotFoundException(uid); } return parseFeature(cRes.getEntity(String.class)); }
/** {@inheritDoc} */ public Property<?> readProperty(String name) { if (name == null || name.isEmpty()) { throw new IllegalArgumentException("Property name cannot be null nor empty"); } ClientResponse cRes = getStore().path(name).get(ClientResponse.class); if (Status.NOT_FOUND.getStatusCode() == cRes.getStatus()) { throw new PropertyNotFoundException(name); } return PropertyJsonParser.parseProperty(cRes.getEntity(String.class)); }
@Test public void testGenericEntityServiceResourceSearchNullDataStorage() throws IllegalAccessException, InstantiationException, IOException, IllegalDataStorageTypeException { when(DataStorageManager.getDataStorageByEagleConfig()).thenReturn(null); GenericServiceAPIResponseEntity responseEntity = resources.client().resource("/entities/rowkey").queryParam("value", "test").queryParam("serviceName", "TestTimeSeriesAPIEntity").get(GenericServiceAPIResponseEntity.class); Assert.assertFalse(responseEntity.isSuccess()); Assert.assertEquals(null, responseEntity.getMeta()); Assert.assertEquals(null, responseEntity.getType()); Assert.assertEquals(null, responseEntity.getObj()); Assert.assertTrue(responseEntity.getException().startsWith("java.lang.Exception: org.apache.eagle.storage.exception.IllegalDataStorageException: data storage is null")); verify(dataStorage, never()).queryById(any(), any()); } }
@Test public void testGenericEntityServiceResourceSearchNullServiceName() throws IllegalAccessException, InstantiationException, IOException { GenericServiceAPIResponseEntity responseEntity = resources.client().resource("/entities/rowkey").queryParam("value", "test").get(GenericServiceAPIResponseEntity.class); Assert.assertFalse(responseEntity.isSuccess()); Assert.assertEquals(null, responseEntity.getMeta()); Assert.assertEquals(null, responseEntity.getType()); Assert.assertEquals(null, responseEntity.getObj()); Assert.assertTrue(responseEntity.getException().startsWith("java.lang.Exception: java.lang.IllegalArgumentException: serviceName is null")); verify(dataStorage, never()).queryById(any(), any()); }
@Test public void testClusterDefault() throws JSONException, Exception { WebResource r = resource(); // test with trailing "/" to make sure acts same as without slash ClientResponse response = r.path("ws").path("v1").path("cluster") .get(ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, response.getType().toString()); JSONObject json = response.getEntity(JSONObject.class); verifyClusterInfo(json); }
@Test public void testInfoDefault() throws JSONException, Exception { WebResource r = resource(); ClientResponse response = r.path("ws").path("v1").path("cluster") .path("info").get(ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, response.getType().toString()); JSONObject json = response.getEntity(JSONObject.class); verifyClusterInfo(json); }
@Test public void testClusterSchedulerDefault() throws JSONException, Exception { WebResource r = resource(); ClientResponse response = r.path("ws").path("v1").path("cluster") .path("scheduler").get(ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, response.getType().toString()); JSONObject json = response.getEntity(JSONObject.class); verifyClusterScheduler(json); }
@Test public void testSchedulerPartitionsDefault() throws JSONException, Exception { WebResource r = resource(); ClientResponse response = r.path("ws").path("v1").path("cluster") .path("scheduler").get(ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, response.getType().toString()); JSONObject json = response.getEntity(JSONObject.class); verifySchedulerInfoJson(json); }
@Test public void testAMDefault() throws JSONException, Exception { WebResource r = resource(); ClientResponse response = r.path("ws").path("v1").path("mapreduce/") .get(ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, response.getType().toString()); JSONObject json = response.getEntity(JSONObject.class); assertEquals("incorrect number of elements", 1, json.length()); verifyAMInfo(json.getJSONObject("info"), appContext); }