use of org.apache.synapse.registry.RegistryEntryImpl in project wso2-synapse by wso2.
the class SimpleURLRegistry method getChildren.
public RegistryEntry[] getChildren(RegistryEntry entry) {
URL url;
if (entry == null) {
RegistryEntryImpl entryImpl = new RegistryEntryImpl();
entryImpl.setKey("");
entry = entryImpl;
}
url = SynapseConfigUtils.getURLFromPath(root + entry.getKey(), properties.get(SynapseConstants.SYNAPSE_HOME) != null ? properties.get(SynapseConstants.SYNAPSE_HOME).toString() : "");
if (url == null) {
return null;
}
if (url.getProtocol().equals("file")) {
File file = new File(url.getFile());
if (!file.isDirectory()) {
return null;
}
BufferedReader reader = null;
try {
reader = new BufferedReader(new InputStreamReader((InputStream) url.getContent()));
ArrayList<RegistryEntry> entryList = new ArrayList<RegistryEntry>();
String key;
while ((key = reader.readLine()) != null) {
RegistryEntryImpl registryEntryImpl = new RegistryEntryImpl();
if (entry.getKey().equals("")) {
registryEntryImpl.setKey(key);
} else {
if (entry.getKey().endsWith("/")) {
registryEntryImpl.setKey(entry.getKey() + key);
} else {
registryEntryImpl.setKey(entry.getKey() + "/" + key);
}
}
entryList.add(registryEntryImpl);
}
RegistryEntry[] entries = new RegistryEntry[entryList.size()];
for (int i = 0; i < entryList.size(); i++) {
entries[i] = entryList.get(i);
}
return entries;
} catch (Exception e) {
throw new SynapseException("Error in reading the URL.");
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException ignored) {
}
}
}
} else {
throw new SynapseException("Invalid protocol.");
}
}
use of org.apache.synapse.registry.RegistryEntryImpl in project wso2-synapse by wso2.
the class SimpleURLRegistry method getRegistryEntry.
public RegistryEntry getRegistryEntry(String key) {
if (log.isDebugEnabled()) {
log.debug("Perform RegistryEntry lookup for key : " + key);
}
URL url = SynapseConfigUtils.getURLFromPath(root + key, properties.get(SynapseConstants.SYNAPSE_HOME) != null ? properties.get(SynapseConstants.SYNAPSE_HOME).toString() : "");
if (url == null) {
return null;
}
URLConnection connection = SynapseConfigUtils.getURLConnection(url);
if (connection == null) {
if (log.isDebugEnabled()) {
log.debug("Cannot create a URLConnection for given URL : " + url);
}
return null;
}
RegistryEntryImpl wre = new RegistryEntryImpl();
wre.setKey(key);
wre.setName(url.getFile());
wre.setType(connection.getContentType());
wre.setDescription("Resource at : " + url.toString());
wre.setLastModified(connection.getLastModified());
wre.setVersion(connection.getLastModified());
if (connection.getExpiration() > 0) {
wre.setCachableDuration(connection.getExpiration() - System.currentTimeMillis());
} else {
wre.setCachableDuration(getCachableDuration());
}
return wre;
}
Aggregations