// @Test public void testCreateSuspect() throws IOException { CloseableHttpClient httpclient = HttpClients.createDefault(); StringBuilder url = new StringBuilder(BASE_URL); url.append("suspect/"); HttpPost httpPost = new HttpPost(url.toString()); EntityBuilder entityBuilder = EntityBuilder.create(); entityBuilder.setContentType(ContentType.APPLICATION_JSON); Suspect aaron = createMockSuspect("982c4a67-bb39-41f9-9872-88356822b7ad", "Aaron"); JsonHelper jsonHelper = new JsonHelper(); String jsonRequest = jsonHelper.convertToJson(aaron); entityBuilder.setText(jsonRequest); httpPost.setEntity(entityBuilder.build()); CloseableHttpResponse response = httpclient.execute(httpPost); Assert.assertTrue(true); }
@SuppressWarnings("nls") private void processRESTRequest( GetFieldDataRequest request, List<Header> headers, GetFieldDataResult fullResult, FieldDataCriteria fieldDataCriteria, FieldSelection fieldSelection) { GetFieldDataResult singleResult = null; GetFieldDataRequest singleRequest = makeSingleRequest(request, fieldDataCriteria, fieldSelection); String url = fieldSelection.getFieldIdentifier().getSource(); String method = fieldSelection.getFieldIdentifier().getName(); if (url == null || !url.startsWith("http://") || !url.startsWith("https://")) throw new UnsupportedOperationException( "please set the source to the url of REST service e.g. https://myservice.com"); if ("POST".equals(method.toUpperCase())) { EntityBuilder builder = EntityBuilder.create(); builder.setText(this.mapper.toJson(singleRequest)); HttpEntity reqEntity = builder.build(); try (CloseableHttpResponse response = this.restClient.post(url, reqEntity, null, 100, 1000); ) { String res = this.restClient.getResponse(response); singleResult = this.mapper.fromJson(res, GetFieldDataResult.class); } catch (IOException e) { throw new RuntimeException("Error when performing POST to Custom Rest Service : ", e); } } else if ("GET".equals(method.toUpperCase())) { try (CloseableHttpResponse response = this.restClient.get(url, null, 100, 1000); ) { String res = this.restClient.getResponse(response); singleResult = this.mapper.fromJson(res, GetFieldDataResult.class); } catch (IOException e) { throw new RuntimeException("Error when performing GET to Custom Rest Service : ", e); } } fullResult.getFieldData().addAll(singleResult.getFieldData()); }