use of org.mitre.taxii.messages.xml11.DiscoveryResponse in project metron by apache.
the class TaxiiHandler method discoverPollingClient.
private static DiscoveryResults discoverPollingClient(URL proxy, URL endpoint, String username, String password, HttpClientContext context, String defaultCollection) throws Exception {
DiscoveryResults results = new DiscoveryResults();
{
HttpClient discoverClient = buildClient(proxy, username, password);
String sessionID = MessageHelper.generateMessageId();
// Prepare the message to send.
DiscoveryRequest request = messageFactory.get().createDiscoveryRequest().withMessageId(sessionID);
DiscoveryResponse response = call(discoverClient, endpoint.toURI(), request, context, DiscoveryResponse.class);
for (ServiceInstanceType serviceInstance : response.getServiceInstances()) {
if (serviceInstance.isAvailable() && serviceInstance.getServiceType() == ServiceTypeEnum.POLL) {
results.pollEndpoint = new URL(serviceInstance.getAddress());
} else if (serviceInstance.isAvailable() && serviceInstance.getServiceType() == ServiceTypeEnum.COLLECTION_MANAGEMENT) {
results.collectionManagementEndpoint = new URL(serviceInstance.getAddress());
}
}
if (results.pollEndpoint == null) {
throw new RuntimeException("Unable to discover a poll TAXII feed");
}
}
if (defaultCollection == null) // get collections
{
HttpClient discoverClient = buildClient(proxy, username, password);
String sessionID = MessageHelper.generateMessageId();
CollectionInformationRequest request = messageFactory.get().createCollectionInformationRequest().withMessageId(sessionID);
CollectionInformationResponse response = call(discoverClient, results.collectionManagementEndpoint.toURI(), request, context, CollectionInformationResponse.class);
LOG.info("Unable to find the default collection; available collections are:");
for (CollectionRecordType c : response.getCollections()) {
LOG.info(c.getCollectionName());
results.collections.add(c.getCollectionName());
}
System.exit(0);
}
return results;
}
Aggregations