use of org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFunctionDescriptor in project knox by apache.
the class XmlUrlRewriteRulesExporter method store.
@Override
public void store(UrlRewriteRulesDescriptor descriptor, Writer writer) throws IOException {
try {
Document document = XmlUtils.createDocument();
Element root = document.createElement(ROOT);
document.appendChild(root);
if (!descriptor.getFunctions().isEmpty()) {
Element functionsElement = document.createElement(FUNCTIONS);
root.appendChild(functionsElement);
for (UrlRewriteFunctionDescriptor function : descriptor.getFunctions()) {
Element functionElement = createElement(document, function.name(), function);
functionsElement.appendChild(functionElement);
}
}
if (!descriptor.getRules().isEmpty()) {
for (UrlRewriteRuleDescriptor rule : descriptor.getRules()) {
Element ruleElement = createRule(document, rule);
root.appendChild(ruleElement);
}
}
if (!descriptor.getFilters().isEmpty()) {
for (UrlRewriteFilterDescriptor filter : descriptor.getFilters()) {
Element filterElement = createFilter(document, filter);
root.appendChild(filterElement);
}
}
XmlUtils.writeXml(document, writer);
} catch (ParserConfigurationException e) {
throw new IOException(e);
} catch (TransformerException e) {
throw new IOException(e);
} catch (InvocationTargetException e) {
LOG.failedToWriteRulesDescriptor(e);
} catch (NoSuchMethodException e) {
LOG.failedToWriteRulesDescriptor(e);
} catch (IntrospectionException e) {
LOG.failedToWriteRulesDescriptor(e);
} catch (IllegalAccessException e) {
LOG.failedToWriteRulesDescriptor(e);
}
}
use of org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFunctionDescriptor in project knox by apache.
the class HtmlPrefixProcessor method initialize.
@Override
public void initialize(final UrlRewriteEnvironment environment, final HtmlPrefixDescriptor descriptor) throws Exception {
final UrlRewriteFunctionDescriptor frontendDescriptor = UrlRewriteFunctionDescriptorFactory.create(FrontendFunctionDescriptor.FUNCTION_NAME);
frontend = UrlRewriteFunctionProcessorFactory.create(FrontendFunctionDescriptor.FUNCTION_NAME, frontendDescriptor);
frontend.initialize(environment, frontendDescriptor);
}
use of org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFunctionDescriptor in project knox by apache.
the class UrlRewriteFunctionProcessorFactory method loadProcessors.
private static Map<Class<? extends UrlRewriteFunctionDescriptor>, Map<String, Class<? extends UrlRewriteFunctionProcessor>>> loadProcessors() {
Map<Class<? extends UrlRewriteFunctionDescriptor>, Map<String, Class<? extends UrlRewriteFunctionProcessor>>> descriptorMap = new HashMap<>();
ServiceLoader<UrlRewriteFunctionProcessor> processors = ServiceLoader.load(UrlRewriteFunctionProcessor.class);
for (UrlRewriteFunctionProcessor processor : processors) {
Class<? extends UrlRewriteFunctionDescriptor> descriptorInterface = getDescriptorInterface(processor);
Map<String, Class<? extends UrlRewriteFunctionProcessor>> typeMap = descriptorMap.get(descriptorInterface);
if (typeMap == null) {
typeMap = new HashMap<>();
descriptorMap.put(descriptorInterface, typeMap);
}
String functionName = processor.name();
typeMap.put(functionName, processor.getClass());
}
return descriptorMap;
}
use of org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFunctionDescriptor in project knox by apache.
the class HtmlImportFunctionProcessor method initialize.
@Override
public void initialize(UrlRewriteEnvironment environment, HtmlImportFunctionDescriptor descriptor) throws Exception {
UrlRewriteFunctionDescriptor frontendDescriptor = UrlRewriteFunctionDescriptorFactory.create(FrontendFunctionDescriptor.FUNCTION_NAME);
frontend = UrlRewriteFunctionProcessorFactory.create(FrontendFunctionDescriptor.FUNCTION_NAME, frontendDescriptor);
frontend.initialize(environment, frontendDescriptor);
}
Aggregations