use of org.apache.knox.gateway.filter.rewrite.api.UrlRewriteServletEnvironment in project knox by apache.
the class OozieServiceDefinitionTest method testOozieRewriteRulesForValuesRelativeToServiceRegistry.
@Test(timeout = TestUtils.MEDIUM_TIMEOUT)
public void testOozieRewriteRulesForValuesRelativeToServiceRegistry() throws Exception {
LOG_ENTER();
// This is a unique part of this test.
String testResource = "oozie-request-relative.xml";
// Mock out the service url registry which is required for several url rewrite functions to work.
ServiceRegistry registry = EasyMock.createNiceMock(ServiceRegistry.class);
EasyMock.expect(registry.lookupServiceURL("test-cluster", "NAMENODE")).andReturn("test-scheme://test-host:42").anyTimes();
// Mock out the gateway services registry which is required for several url rewrite functions to work.
GatewayServices services = EasyMock.createNiceMock(GatewayServices.class);
EasyMock.expect(services.getService(ServiceType.SERVICE_REGISTRY_SERVICE)).andReturn(registry).anyTimes();
UrlRewriteProcessor rewriteProcessor = new UrlRewriteProcessor();
ServletContext servletContext = EasyMock.createNiceMock(ServletContext.class);
EasyMock.expect(servletContext.getAttribute(UrlRewriteServletContextListener.PROCESSOR_ATTRIBUTE_NAME)).andReturn(rewriteProcessor).anyTimes();
EasyMock.expect(servletContext.getAttribute(GatewayServices.GATEWAY_SERVICES_ATTRIBUTE)).andReturn(services).anyTimes();
EasyMock.expect(servletContext.getAttribute(GatewayServices.GATEWAY_CLUSTER_ATTRIBUTE)).andReturn("test-cluster").anyTimes();
HttpServletRequest servletRequest = EasyMock.createNiceMock(HttpServletRequest.class);
EasyMock.expect(servletRequest.getInputStream()).andReturn(new MockServletInputStream(TestUtils.getResourceStream(OozieServiceDefinitionTest.class, testResource))).anyTimes();
EasyMock.expect(servletRequest.getContentType()).andReturn("text/xml").anyTimes();
EasyMock.expect(servletRequest.getContentLength()).andReturn(-1).anyTimes();
FilterConfig filterConfig = EasyMock.createNiceMock(FilterConfig.class);
EasyMock.expect(filterConfig.getServletContext()).andReturn(servletContext).anyTimes();
EasyMock.expect(filterConfig.getInitParameter(UrlRewriteServletFilter.REQUEST_BODY_FILTER_PARAM)).andReturn("OOZIE/oozie/configuration").anyTimes();
EasyMock.replay(registry, services, servletContext, servletRequest, filterConfig);
UrlRewriteEnvironment rewriteEnvironment = new UrlRewriteServletEnvironment(servletContext);
Reader rulesReader = TestUtils.getResourceReader("services/oozie/4.0.0/rewrite.xml", StandardCharsets.UTF_8);
UrlRewriteRulesDescriptor rewriteRules = UrlRewriteRulesDescriptorFactory.load("xml", rulesReader);
rulesReader.close();
rewriteProcessor.initialize(rewriteEnvironment, rewriteRules);
UrlRewriteRequest rewriteRequest = new UrlRewriteRequest(filterConfig, servletRequest);
InputStream stream = rewriteRequest.getInputStream();
Document document = XmlUtils.readXml(stream);
assertThat(document, hasXPath("/configuration/property[name='oozie.wf.application.path']/value", equalTo("test-scheme://test-host:42/workflow.xml")));
LOG_EXIT();
}
use of org.apache.knox.gateway.filter.rewrite.api.UrlRewriteServletEnvironment in project knox by apache.
the class OozieServiceDefinitionTest method testOozieRewriteRulesForLiteralComplexTemplateValuesBugKnox394.
@Test(timeout = TestUtils.MEDIUM_TIMEOUT)
public void testOozieRewriteRulesForLiteralComplexTemplateValuesBugKnox394() throws Exception {
LOG_ENTER();
// This is a unique part of this test.
String testResource = "oozie-request-with-complex-var.xml";
// Mock out the service url registry which is required for several url rewrite functions to work.
ServiceRegistry registry = EasyMock.createNiceMock(ServiceRegistry.class);
EasyMock.expect(registry.lookupServiceURL("test-cluster", "NAMENODE")).andReturn("test-scheme://test-host:42").anyTimes();
// Mock out the gateway services registry which is required for several url rewrite functions to work.
GatewayServices services = EasyMock.createNiceMock(GatewayServices.class);
EasyMock.expect(services.getService(ServiceType.SERVICE_REGISTRY_SERVICE)).andReturn(registry).anyTimes();
UrlRewriteProcessor rewriteProcessor = new UrlRewriteProcessor();
ServletContext servletContext = EasyMock.createNiceMock(ServletContext.class);
EasyMock.expect(servletContext.getAttribute(UrlRewriteServletContextListener.PROCESSOR_ATTRIBUTE_NAME)).andReturn(rewriteProcessor).anyTimes();
EasyMock.expect(servletContext.getAttribute(GatewayServices.GATEWAY_SERVICES_ATTRIBUTE)).andReturn(services).anyTimes();
EasyMock.expect(servletContext.getAttribute(GatewayServices.GATEWAY_CLUSTER_ATTRIBUTE)).andReturn("test-cluster").anyTimes();
HttpServletRequest servletRequest = EasyMock.createNiceMock(HttpServletRequest.class);
EasyMock.expect(servletRequest.getInputStream()).andReturn(new MockServletInputStream(TestUtils.getResourceStream(OozieServiceDefinitionTest.class, testResource))).anyTimes();
EasyMock.expect(servletRequest.getContentType()).andReturn("text/xml").anyTimes();
FilterConfig filterConfig = EasyMock.createNiceMock(FilterConfig.class);
EasyMock.expect(filterConfig.getServletContext()).andReturn(servletContext).anyTimes();
EasyMock.expect(filterConfig.getInitParameter(UrlRewriteServletFilter.REQUEST_BODY_FILTER_PARAM)).andReturn("OOZIE/oozie/configuration").anyTimes();
EasyMock.replay(registry, services, servletContext, servletRequest, filterConfig);
UrlRewriteEnvironment rewriteEnvironment = new UrlRewriteServletEnvironment(servletContext);
Reader rulesReader = TestUtils.getResourceReader("services/oozie/4.0.0/rewrite.xml", StandardCharsets.UTF_8);
UrlRewriteRulesDescriptor rewriteRules = UrlRewriteRulesDescriptorFactory.load("xml", rulesReader);
rulesReader.close();
rewriteProcessor.initialize(rewriteEnvironment, rewriteRules);
UrlRewriteRequest rewriteRequest = new UrlRewriteRequest(filterConfig, servletRequest);
InputStream stream = rewriteRequest.getInputStream();
Document document = XmlUtils.readXml(stream);
assertThat(document, hasXPath("/configuration/property[name='oozie.wf.application.path']/value", equalTo("${nameNode}/user/${user.name}/${examplesRoot}/apps/hive")));
LOG_EXIT();
}
use of org.apache.knox.gateway.filter.rewrite.api.UrlRewriteServletEnvironment in project knox by apache.
the class OozieServiceDefinitionTest method testOozieRewriteRulesForLiteralTemplateValuesBugKnox394.
@Test(timeout = TestUtils.MEDIUM_TIMEOUT)
public void testOozieRewriteRulesForLiteralTemplateValuesBugKnox394() throws Exception {
LOG_ENTER();
// This is a unique part of this test.
String testResource = "oozie-request-with-var.xml";
// Mock out the service url registry which is required for several url rewrite functions to work.
ServiceRegistry registry = EasyMock.createNiceMock(ServiceRegistry.class);
EasyMock.expect(registry.lookupServiceURL("test-cluster", "NAMENODE")).andReturn("test-scheme://test-host:42").anyTimes();
// Mock out the gateway services registry which is required for several url rewrite functions to work.
GatewayServices services = EasyMock.createNiceMock(GatewayServices.class);
EasyMock.expect(services.getService(ServiceType.SERVICE_REGISTRY_SERVICE)).andReturn(registry).anyTimes();
UrlRewriteProcessor rewriteProcessor = new UrlRewriteProcessor();
ServletContext servletContext = EasyMock.createNiceMock(ServletContext.class);
EasyMock.expect(servletContext.getAttribute(UrlRewriteServletContextListener.PROCESSOR_ATTRIBUTE_NAME)).andReturn(rewriteProcessor).anyTimes();
EasyMock.expect(servletContext.getAttribute(GatewayServices.GATEWAY_SERVICES_ATTRIBUTE)).andReturn(services).anyTimes();
EasyMock.expect(servletContext.getAttribute(GatewayServices.GATEWAY_CLUSTER_ATTRIBUTE)).andReturn("test-cluster").anyTimes();
HttpServletRequest servletRequest = EasyMock.createNiceMock(HttpServletRequest.class);
EasyMock.expect(servletRequest.getInputStream()).andReturn(new MockServletInputStream(TestUtils.getResourceStream(OozieServiceDefinitionTest.class, testResource))).anyTimes();
EasyMock.expect(servletRequest.getContentType()).andReturn("text/xml").anyTimes();
FilterConfig filterConfig = EasyMock.createNiceMock(FilterConfig.class);
EasyMock.expect(filterConfig.getServletContext()).andReturn(servletContext).anyTimes();
EasyMock.expect(filterConfig.getInitParameter(UrlRewriteServletFilter.REQUEST_BODY_FILTER_PARAM)).andReturn("OOZIE/oozie/configuration").anyTimes();
EasyMock.replay(registry, services, servletContext, servletRequest, filterConfig);
UrlRewriteEnvironment rewriteEnvironment = new UrlRewriteServletEnvironment(servletContext);
Reader rulesReader = TestUtils.getResourceReader("services/oozie/4.0.0/rewrite.xml", StandardCharsets.UTF_8);
UrlRewriteRulesDescriptor rewriteRules = UrlRewriteRulesDescriptorFactory.load("xml", rulesReader);
rulesReader.close();
rewriteProcessor.initialize(rewriteEnvironment, rewriteRules);
UrlRewriteRequest rewriteRequest = new UrlRewriteRequest(filterConfig, servletRequest);
InputStream stream = rewriteRequest.getInputStream();
Document document = XmlUtils.readXml(stream);
assertThat(document, hasXPath("/configuration/property[name='oozie.wf.application.path']/value", equalTo("${appPath}/workflow.xml")));
LOG_EXIT();
}
Aggregations