com.github.dreamhead.moco.handler.ProxyResponseHandler 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.handler;
import com.github.dreamhead.moco.HttpRequest;
import com.github.dreamhead.moco.ResponseHandler;
import com.github.dreamhead.moco.handler.failover.Failover;
import com.google.common.base.Function;
import com.google.common.base.Optional;
import java.net.URL;
import static com.google.common.base.Optional.absent;
import static com.google.common.base.Optional.of;
public class ProxyResponseHandler extends AbstractProxyResponseHandler implements ResponseHandler {
private final Function url;
public ProxyResponseHandler(final Function url, final Failover failover) {
super(failover);
this.url = url;
}
@Override
protected Optional doRemoteUrl(final HttpRequest request) {
try {
URL targetUrl = url.apply(request);
if (targetUrl != null) {
return of(targetUrl.toString());
}
return absent();
} catch (IllegalArgumentException e) {
return absent();
}
}
}