Search in sources :

Example 6 with Application

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();
}
Also used : EnterpriseArchive(org.jboss.shrinkwrap.api.spec.EnterpriseArchive) HashMap(java.util.HashMap) ServiceLifecycleException(org.apache.knox.gateway.services.ServiceLifecycleException) UrlRewriteServletFilter(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteServletFilter) Topology(org.apache.knox.gateway.topology.Topology) Document(org.w3c.dom.Document) GatewayTestConfig(org.apache.knox.gateway.GatewayTestConfig) URL(java.net.URL) XForwardedHeaderFilter(org.apache.knox.gateway.filter.XForwardedHeaderFilter) DefaultGatewayServices(org.apache.knox.gateway.services.DefaultGatewayServices) File(java.io.File) Application(org.apache.knox.gateway.topology.Application) GatewayConfig(org.apache.knox.gateway.config.GatewayConfig) Test(org.junit.Test)

Example 7 with Application

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"));
}
Also used : TopologyBuilder(org.apache.knox.gateway.topology.builder.TopologyBuilder) Digester(org.apache.commons.digester3.Digester) Topology(org.apache.knox.gateway.topology.Topology) File(java.io.File) Application(org.apache.knox.gateway.topology.Application) URL(java.net.URL) Test(org.junit.Test)

Example 8 with Application

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")));
}
Also used : Marshaller(javax.xml.bind.Marshaller) StringWriter(java.io.StringWriter) HashMap(java.util.HashMap) JAXBContext(javax.xml.bind.JAXBContext) Topology(org.apache.knox.gateway.topology.Topology) XpathReturnType.returningAString(org.xmlmatchers.xpath.XpathReturnType.returningAString) Application(org.apache.knox.gateway.topology.Application) Test(org.junit.Test)

Example 9 with Application

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);
            }
        }
    }
}
Also used : Application(org.apache.knox.gateway.topology.Application) IOException(java.io.IOException) JAXBException(javax.xml.bind.JAXBException)

Example 10 with Application

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;
}
Also used : Service(org.apache.knox.gateway.topology.Service) Topology(org.apache.knox.gateway.topology.Topology) Application(org.apache.knox.gateway.topology.Application) Provider(org.apache.knox.gateway.topology.Provider)

Aggregations

Application (org.apache.knox.gateway.topology.Application)11 Topology (org.apache.knox.gateway.topology.Topology)7 Test (org.junit.Test)6 HashMap (java.util.HashMap)4 File (java.io.File)3 URL (java.net.URL)3 Service (org.apache.knox.gateway.topology.Service)3 GatewayTestConfig (org.apache.knox.gateway.GatewayTestConfig)2 GatewayConfig (org.apache.knox.gateway.config.GatewayConfig)2 DefaultGatewayServices (org.apache.knox.gateway.services.DefaultGatewayServices)2 ServiceLifecycleException (org.apache.knox.gateway.services.ServiceLifecycleException)2 EnterpriseArchive (org.jboss.shrinkwrap.api.spec.EnterpriseArchive)2 Document (org.w3c.dom.Document)2 IOException (java.io.IOException)1 StringWriter (java.io.StringWriter)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 JAXBContext (javax.xml.bind.JAXBContext)1 JAXBException (javax.xml.bind.JAXBException)1 Marshaller (javax.xml.bind.Marshaller)1