use of org.apache.camel.component.atmos.util.AtmosException in project camel by apache.
the class AtmosEndpoint method createProducer.
/**
* Create one of the camel producer available based on the configuration
*
* @return the camel producer
* @throws Exception
*/
public Producer createProducer() throws Exception {
LOG.debug("resolve producer atmos endpoint {" + configuration.getOperation().toString() + "}");
LOG.debug("resolve producer atmos attached client: " + configuration.getClient());
if (configuration.getOperation() == AtmosOperation.put) {
return new AtmosPutProducer(this, configuration);
} else if (this.configuration.getOperation() == AtmosOperation.del) {
return new AtmosDelProducer(this, configuration);
} else if (this.configuration.getOperation() == AtmosOperation.get) {
return new AtmosGetProducer(this, configuration);
} else if (this.configuration.getOperation() == AtmosOperation.move) {
return new AtmosMoveProducer(this, configuration);
} else {
throw new AtmosException("operation specified is not valid for producer!");
}
}
use of org.apache.camel.component.atmos.util.AtmosException in project camel by apache.
the class AtmosAPIFacade method downloadSingleFile.
private void downloadSingleFile(String path, Map<String, ByteArrayOutputStream> resultEntries) throws AtmosException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] content = null;
try {
content = AtmosAPIFacade.client.readObject(new ObjectPath(path), byte[].class);
baos.write(content);
} catch (IOException e) {
throw new AtmosException(path + " cannot obtain a stream", e);
}
if (content != null) {
resultEntries.put(path, baos);
LOG.debug("Downloaded path: {} size:", path, baos.size());
}
}
use of org.apache.camel.component.atmos.util.AtmosException in project camel by apache.
the class AtmosConfiguration method createClient.
/**
* Obtain a new instance of AtmosApi client and store it in configuration.
*
* @throws AtmosException
*/
public void createClient() throws AtmosException {
AtmosConfig config = null;
try {
config = new AtmosConfig(fullTokenId, secretKey, new URI(uri));
} catch (URISyntaxException use) {
throw new AtmosException("wrong syntax for Atmos URI!", use);
}
if (!enableSslValidation) {
config.setDisableSslValidation(true);
}
AtmosApi atmosclient = new AtmosApiClient(config);
this.client = atmosclient;
}
use of org.apache.camel.component.atmos.util.AtmosException in project camel by apache.
the class AtmosEndpoint method createConsumer.
/**
* Create one of the camel consumer available based on the configuration
*
* @param processor the given processor
* @return the camel consumer
* @throws Exception
*/
public Consumer createConsumer(Processor processor) throws Exception {
LOG.debug("resolve consumer atmos endpoint {" + configuration.getOperation().toString() + "}");
LOG.debug("resolve consumer atmos attached client:" + configuration.getClient());
AtmosScheduledPollConsumer consumer;
if (this.configuration.getOperation() == AtmosOperation.get) {
consumer = new AtmosScheduledPollGetConsumer(this, processor, configuration);
consumer.setDelay(POLL_CONSUMER_DELAY);
return consumer;
} else {
throw new AtmosException("operation specified is not valid for consumer!");
}
}
use of org.apache.camel.component.atmos.util.AtmosException in project camel by apache.
the class AtmosAPIFacade method downloadFilesInFolder.
private void downloadFilesInFolder(String atmosPath, Map<String, ByteArrayOutputStream> resultEntries) throws AtmosException {
ObjectPath atmosEntry = new ObjectPath(atmosPath);
if (AtmosAPIFacade.client.getSystemMetadata(atmosEntry) == null) {
throw new AtmosException(atmosPath + " does not exist or cannot obtain metadata");
}
if (!atmosEntry.isDirectory()) {
LOG.debug("downloading a single file...");
downloadSingleFile(atmosPath, resultEntries);
return;
}
ListDirectoryRequest listRequest = new ListDirectoryRequest().path(atmosEntry);
AtmosAPIFacade.client.listDirectory(listRequest);
for (DirectoryEntry entry : AtmosAPIFacade.client.listDirectory(listRequest).getEntries()) {
if (!entry.isDirectory()) {
try {
//get the baos of the file
downloadSingleFile(atmosEntry.getPath().concat(entry.getFilename()), resultEntries);
} catch (AtmosException e) {
LOG.warn("Cannot download from " + entry.getFilename());
}
} else {
//iterate on folder
downloadFilesInFolder(atmosEntry.getPath().concat(entry.getFilename()), resultEntries);
}
}
}
Aggregations