@Override public String insertEntity(String sessionToken, String entityStr, String entityClassName) { log.debug("\n\nInserting Entity..."); WebResource.Builder insertBuilder = webResource.path(Constants.KUNDERA_API_PATH + "/crud/" + entityClassName).type(mediaType).accept(mediaType) .header(Constants.SESSION_TOKEN_HEADER_NAME, sessionToken); StringBuffer sb = new StringBuffer().append(entityStr); ClientResponse insertResponse = (ClientResponse) insertBuilder.post(ClientResponse.class, sb.toString()); log.debug("Response From Insert Entity: " + insertResponse); return insertResponse.toString(); }
@Override public String insertPerson(String sessionToken, String personStr) { log.debug("\n\nInserting Entity..."); WebResource.Builder insertBuilder = webResource.path(Constants.KUNDERA_API_PATH + "/crud/PersonnelUni1ToM").type(mediaType).accept(mediaType) .header(Constants.SESSION_TOKEN_HEADER_NAME, sessionToken); StringBuffer sb = new StringBuffer().append(personStr); ClientResponse insertResponse = (ClientResponse) insertBuilder.post(ClientResponse.class, sb.toString()); log.debug("Response From Insert person: " + insertResponse); return insertResponse.toString(); }
/** * Construct a uniform interface exception. * * @param r the client response. The message of the exception is set to * r.toString(); * @param bufferResponseEntity if true buffer the client response entity by calling * {@link ClientResponse#bufferEntity() }. */ public UniformInterfaceException(ClientResponse r, boolean bufferResponseEntity) { super(r.toString()); if (bufferResponseEntity) r.bufferEntity(); this.r = r; }
/** * Construct a uniform interface exception. * * @param r the client response. The message of the exception is set to * r.toString(); * @param bufferResponseEntity if true buffer the client response entity by calling * {@link ClientResponse#bufferEntity() }. */ public UniformInterfaceException(ClientResponse r, boolean bufferResponseEntity) { super(r.toString()); if (bufferResponseEntity) r.bufferEntity(); this.r = r; }
String callString = "http://api.pemiluapi.org/calonpresiden/api/caleg/jk?apiKey=56513c05217f73e6be82d5542368ae4f"; Client client = Client.create(); WebResource webResource = client.resource(callString); ClientResponse clientResponse = webResource.accept("application/json").get(ClientResponse.class); if (clientResponse.getStatus() != 200) { throw new RuntimeException("Failed"+ clientResponse.toString()); } JSONObject resObj = (JSONObject)new JSONParser().parse(clientResponse.getEntity(String.class)); JSONObject data_obj = (JSONObject) resObj.get("data"); JSONObject results_obj = (JSONObject) data_obj.get("results"); JSONArray caleg_array = (JSONArray) results_obj.get("caleg");
Client client = Client.create(); WebResource webResource = client .resource("http://localhost:8080/activiti-rest/service/login"); LoginInfo loginInfo = new LoginInfo(); loginInfo.userId = "kermit"; loginInfo.password = "kermit"; ClientResponse response; try { response = webResource.type("application/json").post(ClientResponse.class, loginInfo); System.out.print(response.toString()); } catch (UniformInterfaceException ue) { System.out.print(ue.getMessage()); }
@Override public void setTopologyTemplate(QName serviceTemplate, TTopologyTemplate topologyTemplate) throws Exception { WebResource r = WineryRepositoryClient.getTopologyTemplateWebResource(this.primaryWebResource, serviceTemplate); String xmlAsString = Util.getXMLAsString(TTopologyTemplate.class, topologyTemplate); ClientResponse response = r.type(MediaType.TEXT_XML).put(ClientResponse.class, xmlAsString); LOGGER.debug(response.toString()); int status = response.getStatus(); if ((status < 200) || (status >= 300)) { throw new Exception(response.toString()); } }
private static String createErrorMessage(ClientResponse clientResponse) { clientResponse.bufferEntity(); String errorMessage = clientResponse.toString(); if (clientResponse.hasEntity()) { errorMessage = errorMessage + " " + clientResponse.getEntity(String.class); } return errorMessage; }
private static String createErrorMessage(ClientResponse clientResponse) { clientResponse.bufferEntity(); String errorMessage = clientResponse.toString(); if (clientResponse.hasEntity()) { errorMessage = errorMessage + " " + clientResponse.getEntity(String.class); } return errorMessage; }
public void assertStatus(int status, ClientResponse response) { assertEquals("Response status error, out: " + response.toString(), status, response.getStatus()); }
} else if (result.getStatusCode() < 400) { LOG.warn("Status code {}, not processing data. Response: {}", result.getStatusCode(), result.getClientResponse().toString()); } else { LOG.error("Status code {}, not processing data. Response: {}", result.getStatusCode(), result.getClientResponse().toString());
@Override public void ensureBucketExists() { WebResource wr = client.resource(UriBuilder.fromPath(endpoint + "/n/{arg1}/b/{arg2}") .build(region, namespace, bucketName)); wr.accept(MediaType.APPLICATION_JSON_TYPE); ClientResponse rsp = wr.head(); if (rsp.getStatus() == 404) { CreateBucketDetails createBucketDetails = CreateBucketDetails.builder() .name(bucketName) .compartmentId(compartmentId) .build(); wr = client.resource(UriBuilder.fromPath(endpoint + "/n/{arg1}/b/") .build(region, namespace)); wr.accept(MediaType.APPLICATION_JSON_TYPE); try { byte[] bytes = objectMapper.writeValueAsBytes(createBucketDetails); wr.post(new String(bytes, StandardCharsets.UTF_8)); } catch (IOException e) { throw new RuntimeException(e); } } else if (rsp.getStatus() != 200) { throw new RuntimeException(rsp.toString()); } }
OAuth.OAuthToken oAuthToken = mapper.readValue(response.getEntityInputStream(), OAuth.OAuthToken.class); if (oAuthToken.getAccessToken() == null || oAuthToken.getAccessToken() == "" || oAuthToken.getExpiresIn() <= 0) { throw new ApiException("Error while requesting an access token: " + response.toString());
LOGR.config(rsp.toString()); return null;
@Test public void testPutEntities() throws Exception { TestTimelineClient client = new TestTimelineClient(); try { client.init(conf); client.start(); TimelineEntity expectedEntity = new TimelineEntity(); expectedEntity.setEntityType("test entity type"); expectedEntity.setEntityId("test entity id"); expectedEntity.setDomainId("test domain id"); TimelineEvent event = new TimelineEvent(); event.setEventType("test event type"); event.setTimestamp(0L); expectedEntity.addEvent(event); TimelinePutResponse response = client.putEntities(expectedEntity); Assert.assertEquals(0, response.getErrors().size()); Assert.assertTrue(client.resp.toString().contains("https")); TimelineEntity actualEntity = store.getEntity( expectedEntity.getEntityId(), expectedEntity.getEntityType(), EnumSet.allOf(Field.class)); Assert.assertNotNull(actualEntity); Assert.assertEquals( expectedEntity.getEntityId(), actualEntity.getEntityId()); Assert.assertEquals( expectedEntity.getEntityType(), actualEntity.getEntityType()); } finally { client.stop(); client.close(); } }