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);
}
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;
}
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
}
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;
}
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());
}
Aggregations