Search in sources :

Example 6 with HttpProxyRule

use of io.fabric8.gateway.model.HttpProxyRule in project fabric8 by jboss-fuse.

the class JsonRuleBaseReaderTest method parseJson.

@Test
public void parseJson() throws Exception {
    final InputStream in = JsonRuleBaseBuilder.newRuleBase().rule("/foo/{path}", "https://foo.com/cheese/{path}").rule("/cust/{id}/address/{addressId}", "http://at.com/addresses/{addressId}/cust/id}").inputStream();
    Map<String, HttpProxyRule> rules = JsonRuleBaseReader.parseJson(in);
    assertEquals("https://foo.com/cheese/{path}", asString(rules.get("/foo/{path}")));
    assertEquals("http://at.com/addresses/{addressId}/cust/id}", asString(rules.get("/cust/{id}/address/{addressId}")));
    assertClosed(in);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) HttpProxyRule(io.fabric8.gateway.model.HttpProxyRule) Test(org.junit.Test)

Example 7 with HttpProxyRule

use of io.fabric8.gateway.model.HttpProxyRule in project fabric8 by jboss-fuse.

the class JsonRuleBaseReaderTest method parseWithGlobalDomainPath.

@Test
public void parseWithGlobalDomainPath() throws Exception {
    final InputStream in = JsonRuleBaseBuilder.newRuleBase().globalCookieDomain(".global.com").rule("/foo/{path}", "https://foo.com/cheese/{path}").rule("/foo2/{path}", "https://foo2.com/cheese/{path}", null, "overriddenDomain").inputStream();
    final Map<String, HttpProxyRule> rules = JsonRuleBaseReader.parseJson(in);
    assertThat(rules.get("/foo/{path}").getCookieDomain(), equalTo(".global.com"));
    assertThat(rules.get("/foo2/{path}").getCookieDomain(), equalTo("overriddenDomain"));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) HttpProxyRule(io.fabric8.gateway.model.HttpProxyRule) Test(org.junit.Test)

Example 8 with HttpProxyRule

use of io.fabric8.gateway.model.HttpProxyRule in project fabric8 by jboss-fuse.

the class JsonRuleBaseReaderTest method parseWithCookiePathAndCookieDomain.

@Test
public void parseWithCookiePathAndCookieDomain() throws Exception {
    final InputStream in = JsonRuleBaseBuilder.newRuleBase().rule("/foo/{path}", "https://foo.com/cheese/{path}", "/cookiePath", ".domain.com").inputStream();
    final Map<String, HttpProxyRule> rules = JsonRuleBaseReader.parseJson(in);
    final HttpProxyRule httpProxyRule = rules.get("/foo/{path}");
    assertThat(httpProxyRule.getCookiePath(), equalTo("/cookiePath"));
    assertThat(httpProxyRule.getCookieDomain(), equalTo(".domain.com"));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) HttpProxyRule(io.fabric8.gateway.model.HttpProxyRule) Test(org.junit.Test)

Example 9 with HttpProxyRule

use of io.fabric8.gateway.model.HttpProxyRule in project fabric8 by jboss-fuse.

the class ProxyServlet method createProxyDetails.

protected ProxyDetails createProxyDetails(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
    HttpMappingResult mappingRule = getResolver().findMappingRule(httpServletRequest, httpServletResponse);
    final HttpProxyRule proxyRule = mappingRule.getProxyRule();
    if (mappingRule != null) {
        String destinationUrl = mappingRule.getDestinationUrl(new HttpClientRequestFacade(httpServletRequest, httpServletResponse));
        if (destinationUrl != null) {
            return new ProxyDetails(true, destinationUrl, proxyRule);
        }
    }
    return new ProxyDetails(false, null, proxyRule);
}
Also used : HttpProxyRule(io.fabric8.gateway.model.HttpProxyRule)

Aggregations

HttpProxyRule (io.fabric8.gateway.model.HttpProxyRule)9 InputStream (java.io.InputStream)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 Test (org.junit.Test)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 BufferedInputStream (java.io.BufferedInputStream)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 HashMap (java.util.HashMap)1 ServletException (javax.servlet.ServletException)1 Header (org.apache.commons.httpclient.Header)1 HttpClient (org.apache.commons.httpclient.HttpClient)1