Search in sources :

Example 1 with SecureCxfClientFactory

use of org.codice.ddf.cxf.SecureCxfClientFactory in project ddf by codice.

the class WfsSource method setWfsUrl.

public void setWfsUrl(String wfsUrl) throws SecurityServiceException {
    this.wfsUrl = wfsUrl;
    factory = new SecureCxfClientFactory(wfsUrl, Wfs.class);
}
Also used : SecureCxfClientFactory(org.codice.ddf.cxf.SecureCxfClientFactory) Wfs(org.codice.ddf.spatial.ogc.wfs.v2_0_0.catalog.common.Wfs)

Example 2 with SecureCxfClientFactory

use of org.codice.ddf.cxf.SecureCxfClientFactory in project ddf by codice.

the class TestOpenSearchSource method testQueryQueryByMetacardIdFollowedByAnyTextQuery.

// DDF-161
@Test
public void testQueryQueryByMetacardIdFollowedByAnyTextQuery() throws Exception {
    WebClient client = mock(WebClient.class);
    Response clientResponse = mock(Response.class);
    when(clientResponse.getStatus()).thenReturn(Response.Status.OK.getStatusCode());
    when(client.get()).thenReturn(clientResponse);
    when(clientResponse.getEntity()).thenReturn(getSampleXmlStream()).thenReturn(getSampleAtomStream());
    SecureCxfClientFactory factory = getMockFactory(client);
    OverriddenOpenSearchSource source = new OverriddenOpenSearchSource(FILTER_ADAPTER, encryptionService);
    source.setLocalQueryOnly(true);
    source.setInputTransformer(getMockInputTransformer());
    source.setEndpointUrl("http://localhost:8181/services/catalog/query");
    source.init();
    source.setParameters(DEFAULT_PARAMETERS);
    source.factory = factory;
    // Metacard ID filter
    Filter idFilter = filterBuilder.attribute(Metacard.ID).equalTo().text(SAMPLE_ID);
    // Any text filter
    Filter anyTextFilter = filterBuilder.attribute(Metacard.ANY_TEXT).like().text(SAMPLE_SEARCH_PHRASE);
    // Perform Test (Query by ID followed by Any Text Query)
    SourceResponse response1 = source.query(new QueryRequestImpl(new QueryImpl(idFilter)));
    SourceResponse response2 = source.query(new QueryRequestImpl(new QueryImpl(anyTextFilter)));
    // Verification - Verify that we don't see any exceptions when
    // processing the input stream from the endpoint.
    // Verify 1 metacard is in the results
    assertThat(response1.getResults().size(), is(1));
    // Verify that the atom feed is converted into 1 metacard result
    assertThat(response2.getResults().size(), is(1));
}
Also used : Response(javax.ws.rs.core.Response) ResourceResponse(ddf.catalog.operation.ResourceResponse) SourceResponse(ddf.catalog.operation.SourceResponse) QueryImpl(ddf.catalog.operation.impl.QueryImpl) SourceResponse(ddf.catalog.operation.SourceResponse) 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 3 with SecureCxfClientFactory

use of org.codice.ddf.cxf.SecureCxfClientFactory in project ddf by codice.

the class TestOpenSearchSource method testQueryQueryByMetacardIdFollowedByAnyTextQueryRss.

// DDF-161
@Test
public void testQueryQueryByMetacardIdFollowedByAnyTextQueryRss() throws Exception {
    WebClient client = mock(WebClient.class);
    Response clientResponse = mock(Response.class);
    when(clientResponse.getStatus()).thenReturn(Response.Status.OK.getStatusCode());
    when(clientResponse.getEntity()).thenReturn(getSampleXmlStream()).thenReturn(getSampleRssStream());
    when(client.get()).thenReturn(clientResponse);
    SecureCxfClientFactory factory = getMockFactory(client);
    OverriddenOpenSearchSource source = new OverriddenOpenSearchSource(FILTER_ADAPTER, encryptionService);
    source.setLocalQueryOnly(true);
    source.setInputTransformer(getMockInputTransformer());
    source.setEndpointUrl("http://localhost:8181/services/catalog/query");
    source.init();
    source.setParameters(DEFAULT_PARAMETERS);
    source.factory = factory;
    // Metacard ID filter
    Filter idFilter = filterBuilder.attribute(Metacard.ID).equalTo().text(SAMPLE_ID);
    // Any text filter
    Filter anyTextFilter = filterBuilder.attribute(Metacard.ANY_TEXT).like().text(SAMPLE_SEARCH_PHRASE);
    // Perform Test (Query by ID followed by Any Text Query)
    SourceResponse response1 = source.query(new QueryRequestImpl(new QueryImpl(idFilter)));
    SourceResponse response2 = source.query(new QueryRequestImpl(new QueryImpl(anyTextFilter)));
    // Verification - Verify that we don't see any exceptions when
    // processing the input stream from the endpoint.
    // Verify 1 metacard is in the results
    assertThat(response1.getResults().size(), is(1));
    // Verify that the atom feed is converted into 1 metacard result
    assertThat(response2.getResults().size(), is(1));
}
Also used : Response(javax.ws.rs.core.Response) ResourceResponse(ddf.catalog.operation.ResourceResponse) SourceResponse(ddf.catalog.operation.SourceResponse) QueryImpl(ddf.catalog.operation.impl.QueryImpl) SourceResponse(ddf.catalog.operation.SourceResponse) 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 4 with SecureCxfClientFactory

use of org.codice.ddf.cxf.SecureCxfClientFactory in project ddf by codice.

the class TestOpenSearchSource method testQueryById.

/**
     * Tests the proper query is sent to the remote source for query by id.
     *
     * @throws UnsupportedQueryException
     * @throws IOException
     * @throws MalformedURLException
     */
@Test
public void testQueryById() throws UnsupportedQueryException, IOException {
    Response clientResponse = mock(Response.class);
    WebClient client = mock(WebClient.class);
    //ClientResponse
    doReturn(clientResponse).when(client).get();
    doReturn(Response.Status.OK.getStatusCode()).when(clientResponse).getStatus();
    //Client functions
    doReturn(getSampleXmlStream()).when(clientResponse).getEntity();
    when(clientResponse.getHeaderString(eq(OpenSearchSource.HEADER_ACCEPT_RANGES))).thenReturn(OpenSearchSource.BYTES);
    when(client.replaceQueryParam(any(String.class), any(Object.class))).thenReturn(client);
    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.ID).equalTo().text(SAMPLE_ID);
    // when
    SourceResponse response = source.query(new QueryRequestImpl(new QueryImpl(filter)));
    // then
    Assert.assertEquals(1, response.getHits());
}
Also used : Response(javax.ws.rs.core.Response) ResourceResponse(ddf.catalog.operation.ResourceResponse) SourceResponse(ddf.catalog.operation.SourceResponse) QueryImpl(ddf.catalog.operation.impl.QueryImpl) SourceResponse(ddf.catalog.operation.SourceResponse) SecureCxfClientFactory(org.codice.ddf.cxf.SecureCxfClientFactory) Filter(org.opengis.filter.Filter) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) Matchers.containsString(org.hamcrest.Matchers.containsString) WebClient(org.apache.cxf.jaxrs.client.WebClient) Test(org.junit.Test)

Example 5 with SecureCxfClientFactory

use of org.codice.ddf.cxf.SecureCxfClientFactory in project ddf by codice.

the class TestOpenSearchSource method testQueryBySearchPhrase.

@Test
public void testQueryBySearchPhrase() throws UnsupportedQueryException, URISyntaxException, IOException {
    Response clientResponse = mock(Response.class);
    when(clientResponse.getStatus()).thenReturn(Response.Status.OK.getStatusCode());
    when(clientResponse.getEntity()).thenReturn(getSampleAtomStream());
    WebClient client = mock(WebClient.class);
    when(client.get()).thenReturn(clientResponse);
    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)

Aggregations

SecureCxfClientFactory (org.codice.ddf.cxf.SecureCxfClientFactory)13 ResourceResponse (ddf.catalog.operation.ResourceResponse)10 SourceResponse (ddf.catalog.operation.SourceResponse)10 Response (javax.ws.rs.core.Response)10 WebClient (org.apache.cxf.jaxrs.client.WebClient)10 QueryImpl (ddf.catalog.operation.impl.QueryImpl)9 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)9 Test (org.junit.Test)9 Filter (org.opengis.filter.Filter)9 Matchers.containsString (org.hamcrest.Matchers.containsString)6 Metacard (ddf.catalog.data.Metacard)4 Result (ddf.catalog.data.Result)4 Subject (ddf.security.Subject)3 HashMap (java.util.HashMap)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)3 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)2 CatalogTransformerException (ddf.catalog.transform.CatalogTransformerException)2 InputTransformer (ddf.catalog.transform.InputTransformer)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2