RetentionExpirationExporterWebClient extends DataBridgeWebClient { BusinessObjectDataSearchResult searchBusinessObjectData(BusinessObjectDataSearchRequest businessObjectDataSearchRequest, Integer pageNum) throws IOException, JAXBException, URISyntaxException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException { LOGGER.info("Sending business object data search request to the registration server..."); URIBuilder uriBuilder = new URIBuilder().setScheme(getUriScheme()).setHost(regServerAccessParamsDto.getRegServerHost()).setPort(regServerAccessParamsDto.getRegServerPort()) .setPath(HERD_APP_REST_URI_PREFIX + "/businessObjectData/search").setParameter("pageNum", pageNum.toString()); URI uri = uriBuilder.build(); JAXBContext requestContext = JAXBContext.newInstance(BusinessObjectDataSearchRequest.class); Marshaller requestMarshaller = requestContext.createMarshaller(); requestMarshaller.setProperty(Marshaller.JAXB_ENCODING, StandardCharsets.UTF_8.name()); requestMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); StringWriter stringWriter = new StringWriter(); requestMarshaller.marshal(businessObjectDataSearchRequest, stringWriter); try (CloseableHttpClient client = httpClientHelper .createHttpClient(regServerAccessParamsDto.isTrustSelfSignedCertificate(), regServerAccessParamsDto.isDisableHostnameVerification())) { HttpPost request = new HttpPost(uri); request.addHeader("Content-Type", DEFAULT_CONTENT_TYPE); request.addHeader("Accepts", DEFAULT_ACCEPT); if (regServerAccessParamsDto.isUseSsl()) { request.addHeader(getAuthorizationHeader()); } request.setEntity(new StringEntity(stringWriter.toString())); LOGGER.info(String.format(" HTTP POST URI: %s", request.getURI().toString())); LOGGER.info(String.format(" HTTP POST Entity Content:%n%s", stringWriter.toString())); BusinessObjectDataSearchResult businessObjectDataSearchResult = getBusinessObjectDataSearchResult(httpClientOperations.execute(client, request)); LOGGER.info("Successfully received search business object data response from the registration server."); return businessObjectDataSearchResult; } }    }
@Test public void testSearchBusinessObjectDataException() throws Exception { retentionExpirationExporterWebClient.getRegServerAccessParamsDto().setRegServerHost(MockHttpClientOperationsImpl.HOSTNAME_THROW_IO_EXCEPTION); try { retentionExpirationExporterWebClient.searchBusinessObjectData(new BusinessObjectDataSearchRequest(), 1); } catch (IOException e) { assertEquals("testThrowIoException", e.getMessage()); } }
@Test public void testSearchBusinessObjectDataPageNum1() throws Exception { retentionExpirationExporterWebClient.getRegServerAccessParamsDto().setUseSsl(false); BusinessObjectDataSearchResult result = retentionExpirationExporterWebClient.searchBusinessObjectData(new BusinessObjectDataSearchRequest(), 1); assertNotNull(result); assertEquals(2, CollectionUtils.size(result.getBusinessObjectDataElements())); }
@Test public void testSearchBusinessObjectDataPageNum2() throws Exception { retentionExpirationExporterWebClient.getRegServerAccessParamsDto().setUseSsl(false); BusinessObjectDataSearchResult result = retentionExpirationExporterWebClient.searchBusinessObjectData(new BusinessObjectDataSearchRequest(), 2); assertNotNull(result); assertEquals(0, CollectionUtils.size(result.getBusinessObjectDataElements())); }
@Test public void testSearchBusinessObjectDataUseSsl() throws Exception { retentionExpirationExporterWebClient.getRegServerAccessParamsDto().setUseSsl(true); BusinessObjectDataSearchResult result = retentionExpirationExporterWebClient.searchBusinessObjectData(new BusinessObjectDataSearchRequest(), 1); assertNotNull(result); }