com.github.dreamhead.moco.Moco Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of moco-core Show documentation
Show all versions of moco-core Show documentation
Moco is an easy setup stub framework, mainly focusing on testing and integration.
package com.github.dreamhead.moco;
import com.github.dreamhead.moco.action.MocoAsyncAction;
import com.github.dreamhead.moco.action.MocoGetRequestAction;
import com.github.dreamhead.moco.action.MocoPostRequestAction;
import com.github.dreamhead.moco.config.MocoContextConfig;
import com.github.dreamhead.moco.config.MocoFileRootConfig;
import com.github.dreamhead.moco.config.MocoRequestConfig;
import com.github.dreamhead.moco.config.MocoResponseConfig;
import com.github.dreamhead.moco.extractor.CookieRequestExtractor;
import com.github.dreamhead.moco.extractor.FormRequestExtractor;
import com.github.dreamhead.moco.extractor.HeaderRequestExtractor;
import com.github.dreamhead.moco.extractor.JsonPathRequestExtractor;
import com.github.dreamhead.moco.extractor.ParamRequestExtractor;
import com.github.dreamhead.moco.extractor.PlainExtractor;
import com.github.dreamhead.moco.extractor.XPathRequestExtractor;
import com.github.dreamhead.moco.handler.AndResponseHandler;
import com.github.dreamhead.moco.handler.HeaderResponseHandler;
import com.github.dreamhead.moco.handler.ProcedureResponseHandler;
import com.github.dreamhead.moco.handler.ProxyBatchResponseHandler;
import com.github.dreamhead.moco.handler.ProxyResponseHandler;
import com.github.dreamhead.moco.handler.StatusCodeResponseHandler;
import com.github.dreamhead.moco.handler.failover.Failover;
import com.github.dreamhead.moco.handler.failover.FailoverStrategy;
import com.github.dreamhead.moco.handler.proxy.ProxyConfig;
import com.github.dreamhead.moco.internal.ActualHttpServer;
import com.github.dreamhead.moco.internal.ActualSocketServer;
import com.github.dreamhead.moco.internal.ApiUtils;
import com.github.dreamhead.moco.matcher.AndRequestMatcher;
import com.github.dreamhead.moco.matcher.EqRequestMatcher;
import com.github.dreamhead.moco.matcher.ExistMatcher;
import com.github.dreamhead.moco.matcher.NotRequestMatcher;
import com.github.dreamhead.moco.matcher.OrRequestMatcher;
import com.github.dreamhead.moco.matcher.XmlRequestMatcher;
import com.github.dreamhead.moco.monitor.StdLogWriter;
import com.github.dreamhead.moco.procedure.LatencyProcedure;
import com.github.dreamhead.moco.resource.ContentResource;
import com.github.dreamhead.moco.resource.Resource;
import com.github.dreamhead.moco.resource.reader.ExtractorVariable;
import com.github.dreamhead.moco.util.Jsons;
import com.google.common.base.Optional;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableMap;
import com.google.common.net.HttpHeaders;
import java.nio.charset.Charset;
import java.util.concurrent.TimeUnit;
import static com.github.dreamhead.moco.extractor.Extractors.extractor;
import static com.github.dreamhead.moco.handler.ResponseHandlers.responseHandler;
import static com.github.dreamhead.moco.handler.SequenceHandler.newSeq;
import static com.github.dreamhead.moco.internal.ApiUtils.resourceToResourceHandler;
import static com.github.dreamhead.moco.internal.ApiUtils.textToResource;
import static com.github.dreamhead.moco.resource.ResourceFactory.classpathFileResource;
import static com.github.dreamhead.moco.resource.ResourceFactory.cookieResource;
import static com.github.dreamhead.moco.resource.ResourceFactory.fileResource;
import static com.github.dreamhead.moco.resource.ResourceFactory.jsonResource;
import static com.github.dreamhead.moco.resource.ResourceFactory.methodResource;
import static com.github.dreamhead.moco.resource.ResourceFactory.templateResource;
import static com.github.dreamhead.moco.resource.ResourceFactory.textResource;
import static com.github.dreamhead.moco.resource.ResourceFactory.uriResource;
import static com.github.dreamhead.moco.resource.ResourceFactory.versionResource;
import static com.github.dreamhead.moco.util.Iterables.asIterable;
import static com.github.dreamhead.moco.util.Preconditions.checkNotNullOrEmpty;
import static com.github.dreamhead.moco.util.URLs.toUrlFunction;
import static com.google.common.base.Optional.of;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.ImmutableList.copyOf;
import static com.google.common.net.HttpHeaders.SET_COOKIE;
import static java.lang.String.format;
public final class Moco {
public static HttpServer httpServer(final int port, final MocoConfig... configs) {
checkArgument(port > 0, "Port must be greater than zero");
return ActualHttpServer.createQuietServer(of(port), configs);
}
public static HttpServer httpServer(final int port, final MocoMonitor monitor, final MocoConfig... configs) {
checkArgument(port > 0, "Port must be greater than zero");
return ActualHttpServer.createHttpServerWithMonitor(of(port),
checkNotNull(monitor, "Monitor should not be null"),
checkNotNull(configs, "Configuration should not be null"));
}
public static HttpServer httpServer(final int port, final MocoMonitor monitor, final MocoMonitor monitor2,
final MocoMonitor... monitors) {
checkArgument(port > 0, "Port must be greater than zero");
return ActualHttpServer.createHttpServerWithMonitor(of(port),
ApiUtils.mergeMonitor(checkNotNull(monitor, "Monitor should not be null"),
checkNotNull(monitor2, "Monitor should not be null"),
checkNotNull(monitors, "Monitors should not be null")));
}
public static HttpServer httpServer(final MocoConfig... configs) {
return ActualHttpServer.createQuietServer(Optional.absent(),
checkNotNull(configs, "Configuration should not be null"));
}
public static HttpServer httpServer(final MocoMonitor monitor, final MocoConfig... configs) {
return ActualHttpServer.createHttpServerWithMonitor(Optional.absent(), checkNotNull(monitor, "Monitor should not be null"), configs);
}
public static HttpsServer httpsServer(final int port, final HttpsCertificate certificate, final MocoConfig... configs) {
checkArgument(port > 0, "Port must be greater than zero");
return ActualHttpServer.createHttpsQuietServer(of(port), checkNotNull(certificate, "Certificate should not be null"), configs);
}
public static HttpsServer httpsServer(final int port, final HttpsCertificate certificate, final MocoMonitor monitor, final MocoConfig... configs) {
checkArgument(port > 0, "Port must be greater than zero");
return ActualHttpServer.createHttpsServerWithMonitor(of(port),
checkNotNull(certificate, "Certificate should not be null"),
checkNotNull(monitor, "Monitor should not be null"), configs);
}
public static HttpsServer httpsServer(final HttpsCertificate certificate, final MocoConfig... configs) {
return ActualHttpServer.createHttpsQuietServer(Optional.absent(), checkNotNull(certificate, "Certificate should not be null"), configs);
}
public static HttpsServer httpsServer(final HttpsCertificate certificate, final MocoMonitor monitor, final MocoConfig... configs) {
return ActualHttpServer.createHttpsServerWithMonitor(Optional.absent(),
checkNotNull(certificate, "Certificate should not be null"),
checkNotNull(monitor, "Monitor should not be null"), configs);
}
public static HttpServer httpsServer(final int port, final HttpsCertificate certificate, final MocoMonitor monitor, final MocoMonitor monitor2, final MocoMonitor... monitors) {
checkArgument(port > 0, "Port must be greater than zero");
return ActualHttpServer.createHttpsServerWithMonitor(of(port), checkNotNull(certificate, "Certificate should not be null"),
ApiUtils.mergeMonitor(checkNotNull(monitor, "Monitor should not be null"),
checkNotNull(monitor2, "Monitor should not be null"), monitors));
}
public static SocketServer socketServer() {
return ActualSocketServer.createQuietServer(Optional.absent());
}
public static SocketServer socketServer(final int port) {
return ActualSocketServer.createQuietServer(of(port));
}
public static SocketServer socketServer(final int port, final MocoMonitor monitor) {
checkArgument(port > 0, "Port must be greater than zero");
return ActualSocketServer.createServerWithMonitor(of(port),
checkNotNull(monitor, "Monitor should not be null"));
}
public static SocketServer socketServer(final int port, final MocoMonitor monitor, final MocoMonitor monitor2, final MocoMonitor... monitors) {
checkArgument(port > 0, "Port must be greater than zero");
return ActualSocketServer.createServerWithMonitor(of(port),
ApiUtils.mergeMonitor(checkNotNull(monitor, "Monitor should not be null"),
checkNotNull(monitor2, "Monitor should not be null"), monitors));
}
public static MocoConfig context(final String context) {
return new MocoContextConfig(checkNotNullOrEmpty(context, "Context should not be null"));
}
public static MocoConfig request(final RequestMatcher matcher) {
return new MocoRequestConfig(checkNotNull(matcher, "Request matcher should not be null"));
}
public static MocoConfig response(final ResponseHandler handler) {
return new MocoResponseConfig(checkNotNull(handler, "Response handler should not be null"));
}
public static MocoConfig fileRoot(final String fileRoot) {
return new MocoFileRootConfig(checkNotNullOrEmpty(fileRoot, "File root should not be null"));
}
public static MocoMonitor log() {
return ApiUtils.log(new StdLogWriter());
}
public static MocoMonitor log(final String filename) {
return ApiUtils.log(ApiUtils.fileLogWriter(checkNotNullOrEmpty(filename, "Filename should not be null or empty"), Optional.absent()));
}
public static MocoMonitor log(final String filename, final Charset charset) {
return ApiUtils.log(ApiUtils.fileLogWriter(checkNotNullOrEmpty(filename, "Filename should not be null or empty"), of(checkNotNull(charset, "Charset should not be null"))));
}
public static RequestMatcher by(final String content) {
return by(text(checkNotNullOrEmpty(content, "Content should not be null")));
}
public static RequestMatcher by(final Resource resource) {
checkNotNull(resource, "Resource should not be null");
return ApiUtils.by(extractor(resource.id()), resource);
}
public static RequestMatcher eq(final RequestExtractor extractor, final String expected) {
return eq(checkNotNull(extractor, "Extractor should not be null"), text(checkNotNull(expected, "Expected content should not be null")));
}
public static RequestMatcher eq(final RequestExtractor extractor, final Resource expected) {
return new EqRequestMatcher<>(checkNotNull(extractor, "Extractor should not be null"), checkNotNull(expected, "Expected content should not be null"));
}
public static RequestMatcher match(final Resource resource) {
return ApiUtils.match(extractor(resource.id()), checkNotNull(resource, "Resource should not be null"));
}
public static RequestMatcher match(final RequestExtractor extractor, final String expected) {
return ApiUtils.match(checkNotNull(extractor, "Extractor should not be null"), text(checkNotNullOrEmpty(expected, "Expected content should not be null")));
}
public static RequestMatcher exist(final RequestExtractor extractor) {
return new ExistMatcher<>(checkNotNull(extractor, "Extractor should not be null"));
}
public static RequestMatcher startsWith(final Resource resource) {
return ApiUtils.startsWith(extractor(resource.id()), checkNotNull(resource, "Resource should not be null"));
}
public static RequestMatcher startsWith(final RequestExtractor extractor, final String expected) {
return ApiUtils.startsWith(checkNotNull(extractor, "Extractor should not be null"),
text(checkNotNullOrEmpty(expected, "Expected resource should not be null")));
}
public static RequestMatcher endsWith(final Resource resource) {
return ApiUtils.endsWith(extractor(resource.id()), checkNotNull(resource, "Resource should not be null"));
}
public static RequestMatcher endsWith(final RequestExtractor extractor, final String expected) {
return ApiUtils.endsWith(checkNotNull(extractor, "Extractor should not be null"),
text(checkNotNullOrEmpty(expected, "Expected resource should not be null")));
}
public static RequestMatcher contain(final Resource resource) {
return ApiUtils.contain(extractor(resource.id()), checkNotNull(resource, "Resource should not be null"));
}
public static RequestMatcher contain(final RequestExtractor extractor, final String expected) {
return ApiUtils.contain(checkNotNull(extractor, "Extractor should not be null"),
text(checkNotNullOrEmpty(expected, "Expected resource should not be null")));
}
public static RequestMatcher and(final RequestMatcher matcher, final RequestMatcher... matchers) {
return new AndRequestMatcher(asIterable(
checkNotNull(matcher, "Matcher should not be null"),
checkNotNull(matchers, "Matcher should not be null")));
}
public static ResponseHandler and(final ResponseHandler handler, final ResponseHandler... handlers) {
return AndResponseHandler.and(
checkNotNull(handler, "Handlers should not be null"),
checkNotNull(handlers, "Handlers should not be null"));
}
public static RequestMatcher or(final RequestMatcher matcher, final RequestMatcher... matchers) {
return new OrRequestMatcher(asIterable(
checkNotNull(matcher, "Matcher should not be null"),
checkNotNull(matchers, "Matcher should not be null")));
}
public static RequestMatcher not(final RequestMatcher matcher) {
return new NotRequestMatcher(checkNotNull(matcher, "Expected matcher should not be null"));
}
public static ContentResource text(final String text) {
return textResource(checkNotNull(text, "Text should not be null"));
}
public static ResponseHandler with(final String text) {
return with(text(checkNotNullOrEmpty(text, "Text should not be null")));
}
public static ResponseHandler with(final Resource resource) {
return responseHandler(checkNotNull(resource, "Resource should not be null"));
}
public static ResponseHandler with(final MocoProcedure procedure) {
return new ProcedureResponseHandler(checkNotNull(procedure, "Procedure should not be null"));
}
public static Resource uri(final String uri) {
return uriResource(checkNotNullOrEmpty(uri, "URI should not be null"));
}
public static Resource method(final String httpMethod) {
return methodResource(checkNotNullOrEmpty(httpMethod, "HTTP method should not be null"));
}
public static Resource method(final HttpMethod httpMethod) {
return methodResource(checkNotNull(httpMethod, "HTTP method should not be null").toString());
}
public static RequestExtractor header(final String header) {
return new HeaderRequestExtractor(checkNotNullOrEmpty(header, "Header name should not be null"));
}
public static ResponseHandler header(final String name, final String value) {
return header(checkNotNullOrEmpty(name, "Header name should not be null"), text(checkNotNullOrEmpty(value, "Header value should not be null")));
}
public static ResponseHandler header(final String name, final Resource value) {
return new HeaderResponseHandler(checkNotNullOrEmpty(name, "Header name should not be null"),
checkNotNull(value, "Header value should not be null"));
}
public static RequestExtractor cookie(final String key) {
return new CookieRequestExtractor(checkNotNullOrEmpty(key, "Cookie key should not be null"));
}
public static ResponseHandler cookie(final String key, final String value, final CookieAttribute... attributes) {
return cookie(checkNotNullOrEmpty(key, "Cookie key should not be null"),
text(checkNotNullOrEmpty(value, "Cookie value should not be null")),
checkNotNull(attributes, "Cookie options should not be null"));
}
public static ResponseHandler cookie(final String key, final Resource resource, final CookieAttribute... attributes) {
return header(SET_COOKIE, cookieResource(
checkNotNullOrEmpty(key, "Cookie key should not be null"),
checkNotNull(resource, "Cookie value should not be null"),
checkNotNull(attributes, "Cookie options should not be null")));
}
public static RequestExtractor form(final String key) {
return new FormRequestExtractor(checkNotNullOrEmpty(key, "Form key should not be null"));
}
public static LatencyProcedure latency(final long duration, final TimeUnit unit) {
checkArgument(duration > 0, "Latency must be greater than zero");
return new LatencyProcedure(duration, checkNotNull(unit, "Time unit should not be null"));
}
public static RequestExtractor query(final String param) {
return new ParamRequestExtractor(checkNotNullOrEmpty(param, "Query parameter should not be null"));
}
public static XPathRequestExtractor xpath(final String xpath) {
return new XPathRequestExtractor(checkNotNullOrEmpty(xpath, "XPath should not be null"));
}
public static RequestMatcher xml(final String resource) {
return xml(text(checkNotNullOrEmpty(resource, "Resource should not be null")));
}
public static RequestMatcher xml(final Resource resource) {
checkNotNull(resource, "Resource should not be null");
return new XmlRequestMatcher(resource);
}
public static ContentResource json(final String jsonText) {
return json(text(checkNotNullOrEmpty(jsonText, "Json should not be null")));
}
public static ContentResource json(final Resource resource) {
return jsonResource(checkNotNull(resource, "Json should not be null"));
}
public static ContentResource json(final Object pojo) {
return jsonResource(checkNotNull(pojo, "Json object should not be null"));
}
public static JsonPathRequestExtractor jsonPath(final String jsonPath) {
return new JsonPathRequestExtractor(checkNotNullOrEmpty(jsonPath, "JsonPath should not be null"));
}
public static ResponseHandler seq(final String content, final String... contents) {
checkNotNull(content, "Sequence content should not be null");
checkArgument(contents.length > 0, "Sequence content should not be null");
return newSeq(FluentIterable.from(asIterable(content, contents)).transform(textToResource()));
}
public static ResponseHandler seq(final Resource content, final Resource... contents) {
checkNotNull(content, "Sequence content should not be null");
checkArgument(contents.length > 0, "Sequence contents should not be null");
return newSeq(FluentIterable.from(asIterable(content, contents)).transform(resourceToResourceHandler()));
}
public static ResponseHandler seq(final ResponseHandler handler, final ResponseHandler... handlers) {
checkNotNull(handler, "Sequence handler should not be null");
checkArgument(handlers.length > 0, "Sequence handlers should not be null");
return newSeq(asIterable(handler, handlers));
}
public static ContentResource file(final String filename) {
return file(text(checkNotNullOrEmpty(filename, "Filename should not be null")));
}
public static ContentResource file(final Resource filename) {
return file(checkNotNull(filename, "Filename should not be null"), Optional.absent());
}
public static ContentResource file(final String filename, final Charset charset) {
return file(text(checkNotNullOrEmpty(filename, "Filename should not be null")), of(checkNotNull(charset, "Charset should not be null")));
}
public static ContentResource file(final Resource filename, final Charset charset) {
return file(checkNotNull(filename, "Filename should not be null"), of(checkNotNull(charset, "Charset should not be null")));
}
private static ContentResource file(final Resource filename, final Optional charset) {
return fileResource(checkNotNull(filename, "Filename should not be null"), charset, Optional.absent());
}
public static ContentResource pathResource(final String filename) {
return pathResource(text(checkNotNullOrEmpty(filename, "Filename should not be null")));
}
public static ContentResource pathResource(final Resource filename) {
return pathResource(checkNotNull(filename, "Filename should not be null"), Optional.absent());
}
public static ContentResource pathResource(final String filename, final Charset charset) {
return pathResource(text(checkNotNullOrEmpty(filename, "Filename should not be null")), of(checkNotNull(charset, "Charset should not be null")));
}
public static ContentResource pathResource(final Resource filename, final Charset charset) {
return pathResource(checkNotNull(filename, "Filename should not be null"), of(checkNotNull(charset, "Charset should not be null")));
}
private static ContentResource pathResource(final Resource filename, final Optional charset) {
return classpathFileResource(checkNotNull(filename, "Filename should not be null"), charset);
}
public static Resource version(final String version) {
return version(HttpProtocolVersion.versionOf(checkNotNullOrEmpty(version, "Version should not be null")));
}
public static Resource version(final Resource resource) {
return versionResource(checkNotNull(resource, "Version should not be null"));
}
public static Resource version(final HttpProtocolVersion version) {
return versionResource(checkNotNull(version, "Version should not be null"));
}
public static ResponseHandler status(final int code) {
checkArgument(code > 0, "Status code must be greater than zero");
return new StatusCodeResponseHandler(code);
}
public static ResponseHandler proxy(final String url) {
return proxy(checkNotNullOrEmpty(url, "URL should not be null"), Failover.DEFAULT_FAILOVER);
}
public static ResponseHandler proxy(final ContentResource url) {
return proxy(checkNotNull(url, "URL should not be null"), Failover.DEFAULT_FAILOVER);
}
public static ResponseHandler proxy(final String url, final Failover failover) {
return proxy(text(checkNotNullOrEmpty(url, "URL should not be null")),
checkNotNull(failover, "Failover should not be null"));
}
public static ResponseHandler proxy(final ContentResource url, final Failover failover) {
return new ProxyResponseHandler(toUrlFunction(checkNotNull(url, "URL should not be null")),
checkNotNull(failover, "Failover should not be null"));
}
public static ResponseHandler proxy(final ProxyConfig proxyConfig) {
return proxy(checkNotNull(proxyConfig), Failover.DEFAULT_FAILOVER);
}
public static ResponseHandler proxy(final ProxyConfig proxyConfig, final Failover failover) {
return new ProxyBatchResponseHandler(checkNotNull(proxyConfig), checkNotNull(failover));
}
public static ProxyConfig.Builder from(final String localBase) {
return ProxyConfig.builder(checkNotNullOrEmpty(localBase, "Local base should not be null"));
}
public static ContentResource template(final String template) {
return template(text(checkNotNullOrEmpty(template, "Template should not be null")));
}
public static ContentResource template(final String template, final String name, final String value) {
return template(text(checkNotNullOrEmpty(template, "Template should not be null")),
checkNotNullOrEmpty(name, "Template variable name should not be null"),
checkNotNullOrEmpty(value, "Template variable value should not be null"));
}
public static ContentResource template(final String template, final String name1, final String value1, final String name2, final String value2) {
return template(text(checkNotNullOrEmpty(template, "Template should not be null")),
checkNotNullOrEmpty(name1, "Template variable name should not be null"),
checkNotNullOrEmpty(value1, "Template variable value should not be null"),
checkNotNullOrEmpty(name2, "Template variable name should not be null"),
checkNotNullOrEmpty(value2, "Template variable value should not be null"));
}
public static ContentResource template(final ContentResource resource) {
return template(checkNotNull(resource, "Template should not be null"), ImmutableMap.>of());
}
public static ContentResource template(final ContentResource template, final String name, final String value) {
return template(checkNotNull(template, "Template should not be null"),
checkNotNullOrEmpty(name, "Template variable name should not be null"),
var(checkNotNullOrEmpty(value, "Template variable value should not be null")));
}
public static ContentResource template(final ContentResource template, final String name1, final String value1, final String name2, final String value2) {
return template(checkNotNull(template, "Template should not be null"),
checkNotNullOrEmpty(name1, "Template variable name should not be null"),
var(checkNotNullOrEmpty(value1, "Template variable value should not be null")),
checkNotNullOrEmpty(name2, "Template variable name should not be null"),
var(checkNotNullOrEmpty(value2, "Template variable value should not be null")));
}
public static ContentResource template(final String template, final String name, final RequestExtractor extractor) {
return template(text(checkNotNullOrEmpty(template, "Template should not be null")),
checkNotNullOrEmpty(name, "Template variable name should not be null"),
checkNotNull(extractor, "Template variable extractor should not be null"));
}
public static ContentResource template(final String template, final String name1, final RequestExtractor extractor1,
final String name2, final RequestExtractor extractor2) {
return template(text(checkNotNullOrEmpty(template, "Template should not be null")),
checkNotNullOrEmpty(name1, "Template variable name should not be null"),
checkNotNull(extractor1, "Template variable extractor should not be null"),
checkNotNullOrEmpty(name2, "Template variable name should not be null"),
checkNotNull(extractor2, "Template variable extractor should not be null"));
}
public static ContentResource template(final ContentResource template, final String name, final RequestExtractor extractor) {
return templateResource(checkNotNull(template, "Template should not be null"),
ImmutableMap.of(checkNotNullOrEmpty(name, "Template variable name should not be null"),
new ExtractorVariable(checkNotNull(extractor, "Template variable extractor should not be null")))
);
}
public static ContentResource template(final ContentResource template, final String name1, final RequestExtractor extractor1,
final String name2, final RequestExtractor extractor2) {
return templateResource(checkNotNull(template, "Template should not be null"),
ImmutableMap.of(checkNotNullOrEmpty(name1, "Template variable name should not be null"),
new ExtractorVariable(checkNotNull(extractor1, "Template variable extractor should not be null")),
checkNotNullOrEmpty(name2, "Template variable name should not be null"),
new ExtractorVariable(checkNotNull(extractor2, "Template variable extractor should not be null")))
);
}
public static ContentResource template(final String template,
final ImmutableMap> variables) {
return template(text(checkNotNull(template, "Template should not be null")),
checkNotNull(variables, "Template variable should not be null"));
}
public static ContentResource template(final ContentResource template,
final ImmutableMap> variables) {
return templateResource(checkNotNull(template, "Template should not be null"),
ApiUtils.toVariables(checkNotNull(variables, "Template variable should not be null")));
}
public static RequestExtractor