Search in sources :

Example 1 with XForwardedHeaderFilter

use of org.apache.knox.gateway.filter.XForwardedHeaderFilter 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)

Aggregations

File (java.io.File)1 URL (java.net.URL)1 HashMap (java.util.HashMap)1 GatewayTestConfig (org.apache.knox.gateway.GatewayTestConfig)1 GatewayConfig (org.apache.knox.gateway.config.GatewayConfig)1 XForwardedHeaderFilter (org.apache.knox.gateway.filter.XForwardedHeaderFilter)1 UrlRewriteServletFilter (org.apache.knox.gateway.filter.rewrite.api.UrlRewriteServletFilter)1 DefaultGatewayServices (org.apache.knox.gateway.services.DefaultGatewayServices)1 ServiceLifecycleException (org.apache.knox.gateway.services.ServiceLifecycleException)1 Application (org.apache.knox.gateway.topology.Application)1 Topology (org.apache.knox.gateway.topology.Topology)1 EnterpriseArchive (org.jboss.shrinkwrap.api.spec.EnterpriseArchive)1 Test (org.junit.Test)1 Document (org.w3c.dom.Document)1