Search in sources :

Example 31 with WebClient

use of org.apache.cxf.jaxrs.client.WebClient in project ddf by codice.

the class SendEventTest method setUp.

@Before
public void setUp() throws Exception {
    System.setProperty("ddf.home", ".");
    callbackURI = new URL("https://localhost:12345/services/csw/subscription/event");
    ObjectFactory objectFactory = new ObjectFactory();
    request = new GetRecordsType();
    request.setOutputSchema(CswConstants.CSW_OUTPUT_SCHEMA);
    request.setResultType(ResultType.RESULTS);
    request.getResponseHandler().add(callbackURI.toString());
    queryType = new QueryType();
    elementSetNameType = new ElementSetNameType();
    elementSetNameType.setValue(ElementSetType.BRIEF);
    queryType.setElementSetName(elementSetNameType);
    request.setAbstractQuery(objectFactory.createAbstractQuery(queryType));
    transformerManager = mock(TransformerManager.class);
    transformer = mock(QueryResponseTransformer.class);
    binaryContent = mock(BinaryContent.class);
    when(transformerManager.getTransformerBySchema(Matchers.contains(CswConstants.CSW_OUTPUT_SCHEMA))).thenReturn(transformer);
    when(transformer.transform(any(SourceResponse.class), anyMap())).thenReturn(binaryContent);
    when(binaryContent.getByteArray()).thenReturn("byte array with message contents".getBytes());
    query = mock(QueryRequest.class);
    metacard = mock(Metacard.class);
    webclient = mock(WebClient.class);
    mockCxfClientFactory = mock(SecureCxfClientFactory.class);
    response = mock(Response.class);
    subject = mock(Subject.class);
    mockSecurity = mock(Security.class);
    headers.put(Subject.class.toString(), Arrays.asList(new Subject[] { subject }));
    AccessPlugin accessPlugin = mock(AccessPlugin.class);
    accessPlugins.add(accessPlugin);
    when(mockCxfClientFactory.getWebClient()).thenReturn(webclient);
    when(webclient.invoke(anyString(), any(QueryResponse.class))).thenReturn(response);
    when(response.getHeaders()).thenReturn(headers);
    when(accessPlugin.processPostQuery(any(QueryResponse.class))).thenAnswer(invocationOnMock -> invocationOnMock.getArguments()[0]);
    sendEvent = new SendEventExtension(transformerManager, request, query, mockCxfClientFactory);
    sendEvent.setSubject(subject);
}
Also used : TransformerManager(org.codice.ddf.spatial.ogc.csw.catalog.common.transformer.TransformerManager) SourceResponse(ddf.catalog.operation.SourceResponse) QueryRequest(ddf.catalog.operation.QueryRequest) SecureCxfClientFactory(org.codice.ddf.cxf.SecureCxfClientFactory) AccessPlugin(ddf.catalog.plugin.AccessPlugin) GetRecordsType(net.opengis.cat.csw.v_2_0_2.GetRecordsType) BinaryContent(ddf.catalog.data.BinaryContent) Security(org.codice.ddf.security.common.Security) WebClient(org.apache.cxf.jaxrs.client.WebClient) URL(java.net.URL) Subject(ddf.security.Subject) QueryResponse(ddf.catalog.operation.QueryResponse) SourceResponse(ddf.catalog.operation.SourceResponse) Response(javax.ws.rs.core.Response) Metacard(ddf.catalog.data.Metacard) ObjectFactory(net.opengis.cat.csw.v_2_0_2.ObjectFactory) QueryResponseTransformer(ddf.catalog.transform.QueryResponseTransformer) QueryResponse(ddf.catalog.operation.QueryResponse) ElementSetNameType(net.opengis.cat.csw.v_2_0_2.ElementSetNameType) QueryType(net.opengis.cat.csw.v_2_0_2.QueryType) Before(org.junit.Before)

Example 32 with WebClient

use of org.apache.cxf.jaxrs.client.WebClient in project ddf by codice.

the class RestReplicatorPlugin method process.

@Override
public UpdateResponse process(UpdateResponse input) throws PluginExecutionException {
    if (Requests.isLocal(input.getRequest()) && client != null && transformer != null) {
        WebClient updateClient = WebClient.fromClient(client);
        updateClient.type(MediaType.APPLICATION_JSON);
        List<Update> updates = input.getUpdatedMetacards();
        if (updates == null) {
            return input;
        }
        UpdateRequest request = input.getRequest();
        if (request != null && !Metacard.ID.equals(request.getAttributeName())) {
            throw new PluginExecutionException(new UnsupportedOperationException("Cannot replicate records that are not updated by " + Metacard.ID));
        }
        for (int i = 0; i < updates.size(); i++) {
            Update update = updates.get(i);
            if (request != null && request.getUpdates() != null && request.getUpdates().get(i) != null && request.getUpdates().get(i).getKey() != null) {
                updateClient.path(request.getUpdates().get(i).getKey());
                Metacard newMetacard = update.getNewMetacard();
                String newData = transform(newMetacard, updateClient);
                Response r = updateClient.put(newData);
                LOGGER.debug("RESPONSE: [{}]", ToStringBuilder.reflectionToString(r));
            }
        }
    }
    return input;
}
Also used : DeleteResponse(ddf.catalog.operation.DeleteResponse) Response(javax.ws.rs.core.Response) CreateResponse(ddf.catalog.operation.CreateResponse) UpdateResponse(ddf.catalog.operation.UpdateResponse) Metacard(ddf.catalog.data.Metacard) UpdateRequest(ddf.catalog.operation.UpdateRequest) Update(ddf.catalog.operation.Update) WebClient(org.apache.cxf.jaxrs.client.WebClient) PluginExecutionException(ddf.catalog.plugin.PluginExecutionException)

Example 33 with WebClient

use of org.apache.cxf.jaxrs.client.WebClient in project ddf by codice.

the class TestPlugin method waitForWADL.

// Optional step - may be needed to ensure that by the time individual
// tests start running the endpoint has been fully initialized
private static void waitForWADL() throws InterruptedException {
    LOGGER.info("Waiting for wadl");
    WebClient client = WebClient.create(WADL_ADDRESS);
    // wait for 20 secs or so
    for (int i = 0; i < 20; i++) {
        Thread.currentThread().sleep(200);
        Response response = client.get();
        if (response.getStatus() == 200) {
            break;
        }
    }
// no WADL is available yet - throw an exception or give tests a chance
// to run anyway
}
Also used : DeleteResponse(ddf.catalog.operation.DeleteResponse) CreateResponse(ddf.catalog.operation.CreateResponse) Response(javax.ws.rs.core.Response) UpdateResponse(ddf.catalog.operation.UpdateResponse) WebClient(org.apache.cxf.jaxrs.client.WebClient)

Example 34 with WebClient

use of org.apache.cxf.jaxrs.client.WebClient in project ddf by codice.

the class RestReplicatorPlugin method process.

@Override
public DeleteResponse process(DeleteResponse input) throws PluginExecutionException {
    if (input != null && Requests.isLocal(input.getRequest()) && client != null) {
        WebClient updateClient = WebClient.fromClient(client);
        updateClient.type(MediaType.APPLICATION_JSON);
        if (input.getDeletedMetacards() == null || input.getDeletedMetacards().isEmpty()) {
            return input;
        }
        for (int i = 0; i < input.getDeletedMetacards().size(); i++) {
            Metacard metacard = input.getDeletedMetacards().get(i);
            if (metacard != null && metacard.getId() != null) {
                updateClient.path(metacard.getId());
                Response r = updateClient.delete();
                LOGGER.debug("RESPONSE: [{}]", ToStringBuilder.reflectionToString(r));
            }
        }
    }
    return input;
}
Also used : DeleteResponse(ddf.catalog.operation.DeleteResponse) Response(javax.ws.rs.core.Response) CreateResponse(ddf.catalog.operation.CreateResponse) UpdateResponse(ddf.catalog.operation.UpdateResponse) Metacard(ddf.catalog.data.Metacard) WebClient(org.apache.cxf.jaxrs.client.WebClient)

Example 35 with WebClient

use of org.apache.cxf.jaxrs.client.WebClient in project ddf by codice.

the class TestGeoNamesWebService method prepareWebClient.

private void prepareWebClient(String webResponse) {
    WebClient mockWebClient = mock(WebClient.class);
    when(mockWebClient.acceptEncoding(anyString())).thenReturn(mockWebClient);
    when(mockWebClient.accept(anyString())).thenReturn(mockWebClient);
    when(mockWebClient.get(String.class)).thenReturn(webResponse);
    doReturn(mockWebClient).when(webServiceSpy).createWebClient(anyString());
}
Also used : WebClient(org.apache.cxf.jaxrs.client.WebClient)

Aggregations

WebClient (org.apache.cxf.jaxrs.client.WebClient)723 Test (org.junit.Test)400 Response (javax.ws.rs.core.Response)351 URL (java.net.URL)198 HashMap (java.util.HashMap)100 Book (org.apache.cxf.systest.jaxrs.security.Book)94 ArrayList (java.util.ArrayList)88 JacksonJsonProvider (com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider)87 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)77 ClientAccessToken (org.apache.cxf.rs.security.oauth2.common.ClientAccessToken)60 Bus (org.apache.cxf.Bus)48 SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)46 Test (org.testng.annotations.Test)46 Form (javax.ws.rs.core.Form)44 JwtToken (org.apache.cxf.rs.security.jose.jwt.JwtToken)42 JwtClaims (org.apache.cxf.rs.security.jose.jwt.JwtClaims)40 JwtAuthenticationClientFilter (org.apache.cxf.rs.security.jose.jaxrs.JwtAuthenticationClientFilter)32 InputStream (java.io.InputStream)28 ResponseProcessingException (javax.ws.rs.client.ResponseProcessingException)28 Document (org.w3c.dom.Document)27