All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.dreamhead.moco.handler.ProxyResponseHandler Maven / Gradle / Ivy

Go to download

Moco is an easy setup stub framework, mainly focusing on testing and integration.

There is a newer version: 1.5.0
Show newest version
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();
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy