use of org.apache.knox.gateway.hostmap.api.HostmapFunctionDescriptor in project knox by apache.
the class HostmapDeploymentContributor method contributeProvider.
// Write the provider init params to the hostmap.txt file.
// Add the function to the rewrite descriptor providing the location of the hostmap.txt file.
@Override
public void contributeProvider(DeploymentContext context, Provider provider) {
if (provider.isEnabled()) {
UrlRewriteRulesDescriptor rules = context.getDescriptor(REWRITE_ROLE_NAME);
if (rules != null) {
HostmapFunctionDescriptor func = rules.addFunction(HostmapFunctionDescriptor.FUNCTION_NAME);
if (func != null) {
Asset asset = createAsset(provider);
context.getWebArchive().addAsWebInfResource(asset, HostmapFunctionProcessor.DESCRIPTOR_DEFAULT_FILE_NAME);
func.config(HostmapFunctionProcessor.DESCRIPTOR_DEFAULT_LOCATION);
}
}
}
}
use of org.apache.knox.gateway.hostmap.api.HostmapFunctionDescriptor in project knox by apache.
the class HostmapDeploymentContributorTest method testDeployment.
@Test
public void testDeployment() throws IOException {
WebArchive webArchive = ShrinkWrap.create(WebArchive.class, "test-acrhive");
UrlRewriteRulesDescriptorImpl rewriteRules = new UrlRewriteRulesDescriptorImpl();
Map<String, String> providerParams = new HashMap<>();
providerParams.put("test-host-external", "test-host-internal");
Provider provider = new Provider();
provider.setEnabled(true);
provider.setName("hostmap");
provider.setParams(providerParams);
DeploymentContext context = EasyMock.createNiceMock(DeploymentContext.class);
EasyMock.expect(context.getDescriptor("rewrite")).andReturn(rewriteRules).anyTimes();
EasyMock.expect(context.getWebArchive()).andReturn(webArchive).anyTimes();
EasyMock.replay(context);
HostmapDeploymentContributor contributor = new HostmapDeploymentContributor();
assertThat(contributor.getRole(), is("hostmap"));
assertThat(contributor.getName(), is("static"));
// Just make sure it doesn't blow up.
contributor.contributeFilter(null, null, null, null, null);
// Just make sure it doesn't blow up.
contributor.initializeContribution(context);
contributor.contributeProvider(context, provider);
HostmapFunctionDescriptor funcDesc = rewriteRules.getFunction("hostmap");
assertThat(funcDesc.config(), is("/WEB-INF/hostmap.txt"));
Node node = webArchive.get("/WEB-INF/hostmap.txt");
String asset = IOUtils.toString(node.getAsset().openStream());
assertThat(asset, containsString("test-host-external=test-host-internal"));
// Just make sure it doesn't blow up.
contributor.finalizeContribution(context);
}
Aggregations