Search in sources :

Example 96 with WebClient

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());
}
Also used : MalformedURLException(java.net.MalformedURLException) SpatialDistanceFilter(ddf.catalog.impl.filter.SpatialDistanceFilter) Matchers.containsString(org.hamcrest.Matchers.containsString) WebClient(org.apache.cxf.jaxrs.client.WebClient) URL(java.net.URL) Test(org.junit.Test)

Example 97 with WebClient

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());
}
Also used : Serializable(java.io.Serializable) SourceResponse(ddf.catalog.operation.SourceResponse) SecureCxfClientFactory(org.codice.ddf.cxf.SecureCxfClientFactory) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) Matchers.containsString(org.hamcrest.Matchers.containsString) WebClient(org.apache.cxf.jaxrs.client.WebClient) Subject(ddf.security.Subject) Result(ddf.catalog.data.Result) Response(javax.ws.rs.core.Response) ResourceResponse(ddf.catalog.operation.ResourceResponse) SourceResponse(ddf.catalog.operation.SourceResponse) QueryImpl(ddf.catalog.operation.impl.QueryImpl) Metacard(ddf.catalog.data.Metacard) Filter(org.opengis.filter.Filter) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) Test(org.junit.Test)

Example 98 with WebClient

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)));
}
Also used : Response(javax.ws.rs.core.Response) ResourceResponse(ddf.catalog.operation.ResourceResponse) SourceResponse(ddf.catalog.operation.SourceResponse) QueryImpl(ddf.catalog.operation.impl.QueryImpl) SecureCxfClientFactory(org.codice.ddf.cxf.SecureCxfClientFactory) Filter(org.opengis.filter.Filter) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) WebClient(org.apache.cxf.jaxrs.client.WebClient) Test(org.junit.Test)

Example 99 with WebClient

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;
}
Also used : QueryResponse(ddf.catalog.operation.QueryResponse) Response(javax.ws.rs.core.Response) WebClient(org.apache.cxf.jaxrs.client.WebClient) Subject(ddf.security.Subject) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) CswException(org.codice.ddf.spatial.ogc.csw.catalog.common.CswException) MalformedURLException(java.net.MalformedURLException) StopProcessingException(ddf.catalog.plugin.StopProcessingException) UnknownHostException(java.net.UnknownHostException)

Example 100 with WebClient

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());
}
Also used : PropertyResolver(org.codice.ddf.configuration.PropertyResolver) WebClient(org.apache.cxf.jaxrs.client.WebClient) Test(org.junit.Test)

Aggregations

WebClient (org.apache.cxf.jaxrs.client.WebClient)107 Response (javax.ws.rs.core.Response)82 Test (org.testng.annotations.Test)46 Test (org.junit.Test)35 SourceResponse (ddf.catalog.operation.SourceResponse)16 Matchers.containsString (org.hamcrest.Matchers.containsString)14 ResourceResponse (ddf.catalog.operation.ResourceResponse)12 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)11 SecureCxfClientFactory (org.codice.ddf.cxf.SecureCxfClientFactory)11 QueryImpl (ddf.catalog.operation.impl.QueryImpl)10 Filter (org.opengis.filter.Filter)10 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)9 Metacard (ddf.catalog.data.Metacard)8 Subject (ddf.security.Subject)8 InputStream (java.io.InputStream)7 Result (ddf.catalog.data.Result)5 IOException (java.io.IOException)5 MalformedURLException (java.net.MalformedURLException)5 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)4 CatalogTransformerException (ddf.catalog.transform.CatalogTransformerException)4