use of org.apache.knox.gateway.filter.rewrite.api.UrlRewriteRulesDescriptor in project knox by apache.
the class InboundUrlFunctionProcessorTest method testQueryParam.
@Test
public void testQueryParam() throws Exception {
GatewayServices gatewayServices = EasyMock.createNiceMock(GatewayServices.class);
UrlRewriteEnvironment environment = EasyMock.createNiceMock(UrlRewriteEnvironment.class);
EasyMock.expect(environment.getAttribute(GatewayServices.GATEWAY_SERVICES_ATTRIBUTE)).andReturn(gatewayServices).anyTimes();
EasyMock.expect(environment.resolve("cluster.name")).andReturn(Collections.singletonList("test-cluster-name")).anyTimes();
Resolver resolver = EasyMock.createNiceMock(Resolver.class);
EasyMock.expect(resolver.resolve("query.param.host")).andReturn(Lists.newArrayList("http://foo:50075")).anyTimes();
EasyMock.replay(gatewayServices, environment, resolver);
UrlRewriteRulesDescriptor descriptor = UrlRewriteRulesDescriptorFactory.create();
UrlRewriteRuleDescriptor rule = descriptor.addRule("test-location");
rule.pattern("{*}://{*}:{*}/{**}/?{**}");
UrlRewriteActionRewriteDescriptorExt rewrite = rule.addStep("rewrite");
rewrite.template("{$inboundurl[host]}");
UrlRewriteProcessor rewriter = new UrlRewriteProcessor();
rewriter.initialize(environment, descriptor);
Template input = Parser.parseLiteral("https://localhost:8443/gateway/default/datanode/?host=http://foo:50075");
Template output = rewriter.rewrite(resolver, input, UrlRewriter.Direction.OUT, "test-location");
assertThat(output.toString(), is("http://foo:50075"));
}
use of org.apache.knox.gateway.filter.rewrite.api.UrlRewriteRulesDescriptor in project knox by apache.
the class UrlRewriteRequest method getRewriteFilterConfig.
private UrlRewriteFilterContentDescriptor getRewriteFilterConfig(String filterName, MimeType mimeType) {
UrlRewriteFilterContentDescriptor filterContentConfig = null;
UrlRewriteRulesDescriptor rewriteConfig = rewriter.getConfig();
if (rewriteConfig != null) {
UrlRewriteFilterDescriptor filterConfig = rewriteConfig.getFilter(filterName);
if (filterConfig != null) {
filterContentConfig = filterConfig.getContent(mimeType);
}
}
return filterContentConfig;
}
use of org.apache.knox.gateway.filter.rewrite.api.UrlRewriteRulesDescriptor in project knox by apache.
the class UrlRewriteDeploymentContributor method finalizeContribution.
public void finalizeContribution(DeploymentContext context) {
// Write the descriptor into the archive.
UrlRewriteRulesDescriptor descriptor = context.getDescriptor(getRole());
StringWriter writer = new StringWriter();
try {
UrlRewriteRulesDescriptorFactory.store(descriptor, "xml", writer);
} catch (IOException e) {
LOG.failedToWriteRulesDescriptor(e);
}
String asset = writer.toString();
context.getWebArchive().addAsWebInfResource(new StringAsset(asset), UrlRewriteServletContextListener.DESCRIPTOR_DEFAULT_FILE_NAME);
// Tell the provider the location of the descriptor.
context.getWebAppDescriptor().createListener().listenerClass(UrlRewriteServletContextListener.class.getName());
context.getWebAppDescriptor().createContextParam().paramName(UrlRewriteServletContextListener.DESCRIPTOR_LOCATION_INIT_PARAM_NAME).paramValue(UrlRewriteServletContextListener.DESCRIPTOR_DEFAULT_LOCATION);
// ServletType<WebAppDescriptor> servlet = findServlet( context, context.getTopology().getName() );
// servlet.createInitParam()
// .paramName( UrlRewriteServletContextListener.DESCRIPTOR_LOCATION_INIT_PARAM_NAME )
// .paramValue( DESCRIPTOR_FILE_NAME );
}
use of org.apache.knox.gateway.filter.rewrite.api.UrlRewriteRulesDescriptor in project knox by apache.
the class ApplicationDeploymentContributor method loadRewriteRules.
private static UrlRewriteRulesDescriptor loadRewriteRules(Application application, File file) throws IOException {
UrlRewriteRulesDescriptor rules;
if (!file.exists()) {
rules = UrlRewriteRulesDescriptorFactory.load("xml", new StringReader("<rules/>"));
} else {
FileReader reader = new FileReader(file);
rules = UrlRewriteRulesDescriptorFactory.load("xml", reader);
reader.close();
}
return rules;
}
use of org.apache.knox.gateway.filter.rewrite.api.UrlRewriteRulesDescriptor in project knox by apache.
the class ServiceDefinitionDeploymentContributor method contributeRewriteRules.
private void contributeRewriteRules(DeploymentContext context, Service service) {
if (serviceRules != null) {
UrlRewriteRulesDescriptor clusterRules = context.getDescriptor("rewrite");
clusterRules.addRules(serviceRules);
}
}
Aggregations