Search in sources :

Example 6 with Template

use of org.apache.knox.gateway.util.urltemplate.Template in project knox by apache.

the class ServicePathFunctionProcessor method resolve.

@Override
public List<String> resolve(UrlRewriteContext context, List<String> parameters) throws Exception {
    List<String> results = null;
    if (parameters != null) {
        results = new ArrayList<String>(parameters.size());
        for (String parameter : parameters) {
            String url = lookupServiceUrl(parameter);
            if (url != null) {
                Template template = Parser.parseLiteral(url);
                List<Path> path = template.getPath();
                if (path != null) {
                    parameter = toString(path);
                }
            }
            results.add(parameter);
        }
    }
    return results;
}
Also used : Path(org.apache.knox.gateway.util.urltemplate.Path) Template(org.apache.knox.gateway.util.urltemplate.Template)

Example 7 with Template

use of org.apache.knox.gateway.util.urltemplate.Template in project knox by apache.

the class ServiceSchemeFunctionProcessor method resolve.

@Override
public List<String> resolve(UrlRewriteContext context, List<String> parameters) throws Exception {
    List<String> results = null;
    if (parameters != null) {
        results = new ArrayList<String>(parameters.size());
        for (String parameter : parameters) {
            String url = lookupServiceUrl(parameter);
            if (url != null && !url.equals(parameter)) {
                Template template = Parser.parseLiteral(url);
                Scheme scheme = template.getScheme();
                if (scheme != null) {
                    parameter = scheme.getFirstValue().getPattern();
                }
            }
            results.add(parameter);
        }
    }
    return results;
}
Also used : Scheme(org.apache.knox.gateway.util.urltemplate.Scheme) Template(org.apache.knox.gateway.util.urltemplate.Template)

Example 8 with Template

use of org.apache.knox.gateway.util.urltemplate.Template in project knox by apache.

the class UrlRewriteActionRewriteProcessorExt method process.

@Override
public UrlRewriteStepStatus process(UrlRewriteContext context) throws Exception {
    Template rewritten = expander.expandToTemplate(template, context.getParameters(), context.getEvaluator());
    context.setCurrentUrl(rewritten);
    return UrlRewriteStepStatus.SUCCESS;
}
Also used : Template(org.apache.knox.gateway.util.urltemplate.Template)

Example 9 with Template

use of org.apache.knox.gateway.util.urltemplate.Template in project knox by apache.

the class JavaScriptUrlRewriteFilterReader method filterValueString.

@Override
public String filterValueString(String name, String value, String rule) {
    try {
        Template input = Parser.parseLiteral(value);
        Template output = rewriter.rewrite(resolver, input, direction, rule);
        if (output != null) {
            value = output.getPattern();
        }
    } catch (URISyntaxException e) {
        LOG.failedToParseValueForUrlRewrite(value);
    }
    return value;
}
Also used : URISyntaxException(java.net.URISyntaxException) Template(org.apache.knox.gateway.util.urltemplate.Template)

Example 10 with Template

use of org.apache.knox.gateway.util.urltemplate.Template in project knox by apache.

the class JsonUrlRewriteFilterReader method filterValueString.

protected String filterValueString(String name, String value, String rule) {
    try {
        Template input = Parser.parseLiteral(value);
        Template output = rewriter.rewrite(resolver, input, direction, rule);
        value = output.getPattern();
    } catch (URISyntaxException e) {
        LOG.failedToParseValueForUrlRewrite(value);
    }
    return value;
}
Also used : URISyntaxException(java.net.URISyntaxException) Template(org.apache.knox.gateway.util.urltemplate.Template)

Aggregations

Template (org.apache.knox.gateway.util.urltemplate.Template)50 Test (org.junit.Test)23 UrlRewriteEnvironment (org.apache.knox.gateway.filter.rewrite.api.UrlRewriteEnvironment)15 Resolver (org.apache.knox.gateway.util.urltemplate.Resolver)10 URISyntaxException (java.net.URISyntaxException)9 URL (java.net.URL)8 UrlRewriteProcessor (org.apache.knox.gateway.filter.rewrite.api.UrlRewriteProcessor)8 UrlRewriteRuleDescriptor (org.apache.knox.gateway.filter.rewrite.api.UrlRewriteRuleDescriptor)8 UrlRewriteRulesDescriptor (org.apache.knox.gateway.filter.rewrite.api.UrlRewriteRulesDescriptor)8 UrlRewriteActionRewriteDescriptorExt (org.apache.knox.gateway.filter.rewrite.ext.UrlRewriteActionRewriteDescriptorExt)8 HttpServletRequest (javax.servlet.http.HttpServletRequest)7 HttpServletResponse (javax.servlet.http.HttpServletResponse)7 UrlRewriteContext (org.apache.knox.gateway.filter.rewrite.spi.UrlRewriteContext)6 GatewayServices (org.apache.knox.gateway.services.GatewayServices)5 Capture (org.easymock.Capture)5 Host (org.apache.knox.gateway.util.urltemplate.Host)4 Matcher (org.apache.knox.gateway.util.urltemplate.Matcher)4 Query (org.apache.knox.gateway.util.urltemplate.Query)4 URI (java.net.URI)3 UrlRewriteStepStatus (org.apache.knox.gateway.filter.rewrite.spi.UrlRewriteStepStatus)3