use of org.apache.cxf.jaxrs.client.WebClient in project ddf by codice.
the class TestOpenSearchSiteUtil method populateLatLonRadGeospatial.
@Test
public void populateLatLonRadGeospatial() throws Exception {
String lat = "43.25";
String lon = "-123.45";
String radius = "10000";
String wktPoint = "POINT(" + lon + " " + lat + ")";
SpatialDistanceFilter spatial = new SpatialDistanceFilter(wktPoint, radius);
WebClient webClient = WebClient.create(url.toString());
OpenSearchSiteUtil.populateGeospatial(webClient, spatial, false, Arrays.asList("q,src,mr,start,count,mt,dn,lat,lon,radius,bbox,polygon,dtstart,dtend,dateName,filter,sort".split(",")));
String urlStr = webClient.getCurrentURI().toString();
assertTrue(urlStr.indexOf(lat) != -1);
assertTrue(urlStr.indexOf(lon) != -1);
assertTrue(urlStr.indexOf(radius) != -1);
assertTrue(urlStr.indexOf(OpenSearchSiteUtil.GEO_LAT) != -1);
assertTrue(urlStr.indexOf(OpenSearchSiteUtil.GEO_LON) != -1);
assertTrue(urlStr.indexOf(OpenSearchSiteUtil.GEO_RADIUS) != -1);
try {
new URL(urlStr.toString());
} catch (MalformedURLException mue) {
fail("URL is not valid: " + mue.getMessage());
}
LOGGER.info("URL after lat lon geospatial population: {}", urlStr.toString());
}
use of org.apache.cxf.jaxrs.client.WebClient in project ddf by codice.
the class TestOpenSearchSource method testQueryBySearchPhraseRss.
@Test
public void testQueryBySearchPhraseRss() throws UnsupportedQueryException, URISyntaxException, IOException {
WebClient client = mock(WebClient.class);
Response clientResponse = mock(Response.class);
when(client.get()).thenReturn(clientResponse);
when(clientResponse.getStatus()).thenReturn(Response.Status.OK.getStatusCode());
when(clientResponse.getEntity()).thenReturn(getSampleRssStream());
SecureCxfClientFactory factory = getMockFactory(client);
OverriddenOpenSearchSource source = new OverriddenOpenSearchSource(FILTER_ADAPTER, encryptionService);
source.setInputTransformer(getMockInputTransformer());
source.setEndpointUrl("http://localhost:8181/services/catalog/query");
source.init();
source.setParameters(DEFAULT_PARAMETERS);
source.factory = factory;
Filter filter = filterBuilder.attribute(Metacard.METADATA).like().text(SAMPLE_SEARCH_PHRASE);
// when
QueryRequestImpl queryRequest = new QueryRequestImpl(new QueryImpl(filter));
Map<String, Serializable> properties = new HashMap<>();
properties.put(SecurityConstants.SECURITY_SUBJECT, mock(Subject.class));
queryRequest.setProperties(properties);
SourceResponse response = source.query(queryRequest);
Assert.assertEquals(1, response.getHits());
List<Result> results = response.getResults();
Assert.assertTrue(results.size() == 1);
Result result = results.get(0);
Metacard metacard = result.getMetacard();
Assert.assertNotNull(metacard);
Assert.assertEquals("Resource", metacard.getContentTypeName());
}
use of org.apache.cxf.jaxrs.client.WebClient in project ddf by codice.
the class TestOpenSearchSource method testQueryBadResponse.
@Test(expected = UnsupportedQueryException.class)
public void testQueryBadResponse() throws UnsupportedQueryException, IOException {
Response clientResponse = mock(Response.class);
WebClient client = mock(WebClient.class);
//ClientResponse
doReturn(clientResponse).when(client).get();
doReturn(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).when(clientResponse).getStatus();
SecureCxfClientFactory factory = getMockFactory(client);
OverriddenOpenSearchSource source = new OverriddenOpenSearchSource(FILTER_ADAPTER, encryptionService);
source.setInputTransformer(getMockInputTransformer());
source.setEndpointUrl("http://localhost:8181/services/catalog/query");
source.init();
source.setParameters(DEFAULT_PARAMETERS);
source.factory = factory;
Filter filter = filterBuilder.attribute(Metacard.ANY_TEXT).like().text(SAMPLE_SEARCH_PHRASE);
source.query(new QueryRequestImpl(new QueryImpl(filter)));
}
use of org.apache.cxf.jaxrs.client.WebClient in project ddf by codice.
the class SendEvent method send.
private boolean send(String operation, CswRecordCollection recordCollection) {
WebClient webClient = cxfClientFactory.getWebClient();
try {
Response response = webClient.invoke(operation, recordCollection);
Subject pingSubject = (Subject) response.getHeaders().getFirst(Subject.class.toString());
if (pingSubject == null && ip != null) {
subject = security.getGuestSubject(ip);
} else {
subject = pingSubject;
}
lastPing = System.currentTimeMillis();
retryCount.set(0);
return true;
} catch (Exception e) {
LOGGER.debug("Error contacting event callback url {}", callbackUrl, e);
lastPing = System.currentTimeMillis();
retryCount.incrementAndGet();
}
return false;
}
use of org.apache.cxf.jaxrs.client.WebClient in project ddf by codice.
the class SecureCxfClientFactoryTest method testWebClient.
@Test
public void testWebClient() {
PropertyResolver mockPropertyResolver = mock(PropertyResolver.class);
when(mockPropertyResolver.getResolvedString()).thenReturn(SECURE_ENDPOINT);
// positive case
SecureCxfClientFactory<WebClient> secureCxfClientFactory = new SecureCxfClientFactory<>(SECURE_ENDPOINT, WebClient.class, null, null, false, false, mockPropertyResolver);
WebClient client = secureCxfClientFactory.getWebClient();
assertThat(client, notNullValue());
}
Aggregations