Search in sources :

Example 6 with GatewayDescriptor

use of org.apache.knox.gateway.descriptor.GatewayDescriptor in project knox by apache.

the class XmlGatewayDescriptorImporter method load.

@Override
public GatewayDescriptor load(Reader reader) throws IOException {
    Digester digester = loader.newDigester(new ExtendedBaseRules());
    digester.setValidating(false);
    try {
        GatewayDescriptor descriptor = digester.parse(reader);
        return descriptor;
    } catch (SAXException e) {
        throw new IOException(e);
    }
}
Also used : ExtendedBaseRules(org.apache.commons.digester3.ExtendedBaseRules) GatewayDescriptor(org.apache.knox.gateway.descriptor.GatewayDescriptor) Digester(org.apache.commons.digester3.Digester) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException)

Example 7 with GatewayDescriptor

use of org.apache.knox.gateway.descriptor.GatewayDescriptor in project knox by apache.

the class DeploymentFactory method createDeploymentContext.

private static DeploymentContext createDeploymentContext(GatewayConfig config, String archivePath, Topology topology, Map<String, List<ProviderDeploymentContributor>> providers) {
    archivePath = Urls.encode(archivePath);
    WebArchive webArchive = ShrinkWrap.create(WebArchive.class, archivePath);
    WebAppDescriptor webAppDesc = Descriptors.create(WebAppDescriptor.class);
    GatewayDescriptor gateway = GatewayDescriptorFactory.create();
    DeploymentContext context = new DeploymentContextImpl(config, topology, gateway, webArchive, webAppDesc, providers);
    return context;
}
Also used : WebAppDescriptor(org.jboss.shrinkwrap.descriptor.api.webapp30.WebAppDescriptor) GatewayDescriptor(org.apache.knox.gateway.descriptor.GatewayDescriptor) WebArchive(org.jboss.shrinkwrap.api.spec.WebArchive)

Example 8 with GatewayDescriptor

use of org.apache.knox.gateway.descriptor.GatewayDescriptor in project knox by apache.

the class GatewayFactory method createParams.

private static Map<String, String> createParams(FilterDescriptor filter) {
    Map<String, String> paramMap = new HashMap<>();
    ResourceDescriptor resource = filter.up();
    GatewayDescriptor gateway = resource.up();
    for (GatewayParamDescriptor param : gateway.params()) {
        paramMap.put(param.name(), param.value());
    }
    for (ResourceParamDescriptor param : resource.params()) {
        paramMap.put(param.name(), param.value());
    }
    // TODO: Should all elements of the resource and gateway descriptor somehow be added to the filter params?
    // TODO: Should we use some composite params object instead of copying all these name value pairs?
    paramMap.put("pattern", resource.pattern());
    List<FilterParamDescriptor> paramList = filter.params();
    for (FilterParamDescriptor param : paramList) {
        paramMap.put(param.name(), param.value());
    }
    return paramMap;
}
Also used : HashMap(java.util.HashMap) GatewayDescriptor(org.apache.knox.gateway.descriptor.GatewayDescriptor) FilterParamDescriptor(org.apache.knox.gateway.descriptor.FilterParamDescriptor) GatewayParamDescriptor(org.apache.knox.gateway.descriptor.GatewayParamDescriptor) ResourceParamDescriptor(org.apache.knox.gateway.descriptor.ResourceParamDescriptor) ResourceDescriptor(org.apache.knox.gateway.descriptor.ResourceDescriptor)

Example 9 with GatewayDescriptor

use of org.apache.knox.gateway.descriptor.GatewayDescriptor in project knox by apache.

the class XmlGatewayDescriptorImporterTest method testXmlGatewayDescriptorLoad.

@Test
public void testXmlGatewayDescriptorLoad() throws IOException {
    String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" + "<gateway>\n" + "  <resource>\n" + "    <pattern>resource1-source</pattern>\n" + // "    <target>resource1-target</target>\n" +
    "    <filter>\n" + "      <role>resource1-filter1-role</role>\n" + "      <class>resource1-filter1-impl</class>\n" + "      <param>\n" + "        <name>resource1-filter1-param1-name</name>\n" + "        <value>resource1-filter1-param1-value</value>\n" + "      </param>\n" + "      <param>\n" + "        <name>resource1-filter1-param2-name</name>\n" + "        <value>resource1-filter1-param2-value</value>\n" + "      </param>\n" + "    </filter>\n" + "    <filter>\n" + "      <role>resource1-filter2-role</role>\n" + "      <class>resource1-filter2-impl</class>\n" + "    </filter>\n" + "  </resource>\n" + "  <resource>\n" + "    <pattern>resource2-source</pattern>\n" + // "    <target>resource2-target</target>\n" +
    "  </resource>\n" + "</gateway>";
    Reader reader = new StringReader(xml);
    GatewayDescriptor descriptor = GatewayDescriptorFactory.load("xml", reader);
    assertThat(descriptor, notNullValue());
    assertThat(descriptor.resources().size(), is(2));
    ResourceDescriptor resource1 = descriptor.resources().get(0);
    assertThat(resource1, notNullValue());
    assertThat(resource1.pattern(), is("resource1-source"));
    assertThat(resource1.filters().size(), is(2));
    FilterDescriptor filter1 = resource1.filters().get(0);
    assertThat(filter1, notNullValue());
    assertThat(filter1.role(), is("resource1-filter1-role"));
    assertThat(filter1.impl(), is("resource1-filter1-impl"));
    assertThat(filter1.params().size(), is(2));
    FilterParamDescriptor param1 = filter1.params().get(0);
    assertThat(param1, notNullValue());
    assertThat(param1.name(), is("resource1-filter1-param1-name"));
    assertThat(param1.value(), is("resource1-filter1-param1-value"));
    FilterParamDescriptor param2 = filter1.params().get(1);
    assertThat(param2, notNullValue());
    assertThat(param2.name(), is("resource1-filter1-param2-name"));
    assertThat(param2.value(), is("resource1-filter1-param2-value"));
    FilterDescriptor filter2 = resource1.filters().get(1);
    assertThat(filter2, notNullValue());
    assertThat(filter2.role(), is("resource1-filter2-role"));
    assertThat(filter2.impl(), is("resource1-filter2-impl"));
    ResourceDescriptor resource2 = descriptor.resources().get(1);
    assertThat(resource2, notNullValue());
    assertThat(resource2.pattern(), is("resource2-source"));
}
Also used : FilterDescriptor(org.apache.knox.gateway.descriptor.FilterDescriptor) GatewayDescriptor(org.apache.knox.gateway.descriptor.GatewayDescriptor) FilterParamDescriptor(org.apache.knox.gateway.descriptor.FilterParamDescriptor) StringReader(java.io.StringReader) Reader(java.io.Reader) StringReader(java.io.StringReader) Matchers.containsString(org.hamcrest.Matchers.containsString) ResourceDescriptor(org.apache.knox.gateway.descriptor.ResourceDescriptor) Test(org.junit.Test)

Example 10 with GatewayDescriptor

use of org.apache.knox.gateway.descriptor.GatewayDescriptor in project knox by apache.

the class XmlGatewayDescriptorImporterTest method testXmlGatewayDescriptorLoadEmpty.

@Test
public void testXmlGatewayDescriptorLoadEmpty() throws IOException {
    String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" + "<gateway>\n" + "  <resource>\n" + "    <filter>\n" + "      <param>\n" + "      </param>\n" + "    </filter>\n" + "  </resource>\n" + "</gateway>";
    Reader reader = new StringReader(xml);
    GatewayDescriptor descriptor = GatewayDescriptorFactory.load("xml", reader);
    assertThat(descriptor, notNullValue());
    assertThat(descriptor.resources().size(), is(1));
    ResourceDescriptor resource1 = descriptor.resources().get(0);
    assertThat(resource1, notNullValue());
    assertThat(resource1.filters().size(), is(1));
    FilterDescriptor filter1 = resource1.filters().get(0);
    assertThat(filter1, notNullValue());
    assertThat(filter1.params().size(), is(1));
    FilterParamDescriptor param1 = filter1.params().get(0);
    assertThat(param1, notNullValue());
}
Also used : FilterDescriptor(org.apache.knox.gateway.descriptor.FilterDescriptor) GatewayDescriptor(org.apache.knox.gateway.descriptor.GatewayDescriptor) FilterParamDescriptor(org.apache.knox.gateway.descriptor.FilterParamDescriptor) StringReader(java.io.StringReader) Reader(java.io.Reader) StringReader(java.io.StringReader) Matchers.containsString(org.hamcrest.Matchers.containsString) ResourceDescriptor(org.apache.knox.gateway.descriptor.ResourceDescriptor) Test(org.junit.Test)

Aggregations

GatewayDescriptor (org.apache.knox.gateway.descriptor.GatewayDescriptor)10 Test (org.junit.Test)6 StringReader (java.io.StringReader)4 FilterParamDescriptor (org.apache.knox.gateway.descriptor.FilterParamDescriptor)4 ResourceDescriptor (org.apache.knox.gateway.descriptor.ResourceDescriptor)4 Matchers.containsString (org.hamcrest.Matchers.containsString)4 IOException (java.io.IOException)3 FilterDescriptor (org.apache.knox.gateway.descriptor.FilterDescriptor)3 CharArrayWriter (java.io.CharArrayWriter)2 Reader (java.io.Reader)2 WebArchive (org.jboss.shrinkwrap.api.spec.WebArchive)2 Document (org.w3c.dom.Document)2 InputSource (org.xml.sax.InputSource)2 InputStreamReader (java.io.InputStreamReader)1 URISyntaxException (java.net.URISyntaxException)1 HashMap (java.util.HashMap)1 List (java.util.List)1 ServletException (javax.servlet.ServletException)1 Digester (org.apache.commons.digester3.Digester)1 ExtendedBaseRules (org.apache.commons.digester3.ExtendedBaseRules)1