type();
/* configuration key associated with this target. For example, {@code route53}. */
String name();
/* base HTTP URL of the target. For example, {@code https://api/v2}. */
String url();
/**
* Targets a template to this target, adding the {@link #url() base url} and
* any target-specific headers or query parameters.
*
*
* For example:
*
*
* public Request apply(RequestTemplate input) {
* input.insert(0, url());
* input.replaceHeader("X-Auth", currentToken);
* return input.asRequest();
* }
*
*
*
relationship to JAXRS 2.0
*
* This call is similar to {@code javax.ws.rs.client.WebTarget.request()},
* except that we expect transient, but necessary decoration to be applied
* on invocation.
*/
public Request apply(RequestTemplate input);
public static class HardCodedTarget implements Target {
private final Class type;
private final String name;
private final String url;
public HardCodedTarget(Class type, String url) {
this(type, url, url);
}
public HardCodedTarget(Class type, String name, String url) {
this.type = checkNotNull(type, "type");
this.name = checkNotNull(emptyToNull(name), "name");
this.url = checkNotNull(emptyToNull(url), "url");
}
@Override public Class type() {
return type;
}
@Override public String name() {
return name;
}
@Override public String url() {
return url;
}
/* no authentication or other special activity. just insert the url. */
@Override public Request apply(RequestTemplate input) {
if (input.url().indexOf("http") != 0)
input.insert(0, url());
return input.request();
}
@Override public int hashCode() {
return Arrays.hashCode(new Object[]{type, name, url});
}
@Override public boolean equals(Object obj) {
if (obj == null)
return false;
if (this == obj)
return true;
if (HardCodedTarget.class != obj.getClass())
return false;
HardCodedTarget> that = HardCodedTarget.class.cast(obj);
return this.type.equals(that.type) && this.name.equals(that.name) && this.url.equals(that.url);
}
}
}