use of org.apache.knox.gateway.topology.Application in project knox by apache.
the class DeploymentFactoryFuncTest method testDeploymentWithApplication.
@Test(timeout = MEDIUM_TIMEOUT)
public void testDeploymentWithApplication() throws Exception {
LOG_ENTER();
GatewayConfig config = new GatewayTestConfig();
File targetDir = new File(System.getProperty("user.dir"), "target");
File gatewayDir = new File(targetDir, "gateway-home-" + UUID.randomUUID());
gatewayDir.mkdirs();
((GatewayTestConfig) config).setGatewayHomeDir(gatewayDir.getAbsolutePath());
File deployDir = new File(config.getGatewayDeploymentDir());
deployDir.mkdirs();
URL serviceUrl = TestUtils.getResourceUrl(DeploymentFactoryFuncTest.class, "test-apps/minimal-test-app/service.xml");
File serviceFile = new File(serviceUrl.toURI());
File appsDir = serviceFile.getParentFile().getParentFile();
((GatewayTestConfig) config).setGatewayApplicationsDir(appsDir.getAbsolutePath());
DefaultGatewayServices srvcs = new DefaultGatewayServices();
Map<String, String> options = new HashMap<>();
options.put("persist-master", "false");
options.put("master", "password");
try {
DeploymentFactory.setGatewayServices(srvcs);
srvcs.init(config, options);
} catch (ServiceLifecycleException e) {
// I18N not required.
e.printStackTrace();
}
Topology topology = new Topology();
topology.setName("test-topology");
Application app;
app = new Application();
app.setName("minimal-test-app");
app.addUrl("/minimal-test-app-path");
topology.addApplication(app);
EnterpriseArchive archive = DeploymentFactory.createDeployment(config, topology);
assertThat(archive, notNullValue());
Document doc;
doc = XmlUtils.readXml(archive.get("META-INF/topology.xml").getAsset().openStream());
assertThat(doc, notNullValue());
doc = XmlUtils.readXml(archive.get("%2Fminimal-test-app-path/WEB-INF/gateway.xml").getAsset().openStream());
assertThat(doc, notNullValue());
// dump( doc );
assertThat(doc, hasXPath("/gateway/resource/pattern", equalTo("/**?**")));
assertThat(doc, hasXPath("/gateway/resource/filter[1]/role", equalTo("xforwardedheaders")));
assertThat(doc, hasXPath("/gateway/resource/filter[1]/name", equalTo("XForwardedHeaderFilter")));
assertThat(doc, hasXPath("/gateway/resource/filter[1]/class", equalTo(XForwardedHeaderFilter.class.getName())));
assertThat(doc, hasXPath("/gateway/resource/filter[2]/role", equalTo("rewrite")));
assertThat(doc, hasXPath("/gateway/resource/filter[2]/name", equalTo("url-rewrite")));
assertThat(doc, hasXPath("/gateway/resource/filter[2]/class", equalTo(UrlRewriteServletFilter.class.getName())));
LOG_EXIT();
}
use of org.apache.knox.gateway.topology.Application in project knox by apache.
the class TopologyRulesModuleTest method testParseTopologyWithApplication.
@Test
public void testParseTopologyWithApplication() throws IOException, SAXException {
Digester digester = loader.newDigester();
String name = "topology-with-application.xml";
URL url = TestUtils.getResourceUrl(TopologyRulesModuleTest.class, name);
assertThat("Failed to find URL for resource " + name, url, notNullValue());
File file = new File(url.getFile());
TopologyBuilder topologyBuilder = digester.parse(url);
Topology topology = topologyBuilder.build();
assertThat("Failed to parse resource " + name, topology, notNullValue());
topology.setTimestamp(file.lastModified());
Application app = topology.getApplications().iterator().next();
assertThat("Failed to find application", app, notNullValue());
assertThat(app.getName(), is("test-app-name"));
assertThat(app.getUrl(), is("test-app-path"));
assertThat(app.getUrls().get(0), is("test-app-path"));
assertThat(app.getParams().get("test-param-name"), is("test-param-value"));
}
use of org.apache.knox.gateway.topology.Application in project knox by apache.
the class TopologyMarshallerTest method testTopologyMarshalling.
@Test
public void testTopologyMarshalling() throws Exception {
Topology topology = new Topology();
Application app = new Application();
app.setName("test-app-name");
topology.addApplication(app);
StringWriter writer = new StringWriter();
String xml;
Map<String, Object> properties = new HashMap<>(2);
properties.put("eclipselink-oxm-xml", "org/apache/knox/gateway/topology/topology_binding-xml.xml");
properties.put("eclipselink.media-type", "application/xml");
JAXBContext jaxbContext = JAXBContext.newInstance(Topology.class.getPackage().getName(), Topology.class.getClassLoader(), properties);
Marshaller marshaller = jaxbContext.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.marshal(topology, writer);
writer.close();
xml = writer.toString();
assertThat(the(xml), hasXPath("/topology/application/name", returningAString(), is("test-app-name")));
}
use of org.apache.knox.gateway.topology.Application in project knox by apache.
the class DeploymentFactory method contributeApplications.
private static void contributeApplications(DeploymentContext context, Topology topology, Map.Entry<String, ServiceDeploymentContributor> applications) {
if (applications != null) {
ServiceDeploymentContributor contributor = applications.getValue();
if (contributor != null) {
try {
log.contributeApplication(contributor.getName());
Application applicationDesc = topology.getApplication(applications.getKey());
contributor.contributeService(context, applicationDesc);
} catch (Exception e) {
log.failedToInitializeContribution(e);
throw new DeploymentException("Failed to contribution application.", e);
}
}
}
}
use of org.apache.knox.gateway.topology.Application in project knox by apache.
the class BeanPropertyTopologyBuilder method build.
public Topology build() {
Topology topology = new Topology();
topology.setName(name);
topology.setDefaultServicePath(defaultService);
topology.setGenerated(isGenerated);
for (Provider provider : providers) {
topology.addProvider(provider);
}
for (Service service : services) {
topology.addService(service);
}
for (Application application : applications) {
topology.addApplication(application);
}
return topology;
}
Aggregations