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

io.contek.invoker.commons.actor.http.SimpleHttpClient Maven / Gradle / Ivy

There is a newer version: 3.8.0
Show newest version
package io.contek.invoker.commons.actor.http;

import okhttp3.*;

import javax.annotation.concurrent.ThreadSafe;
import java.io.IOException;
import java.io.InterruptedIOException;
import java.net.InetAddress;

@ThreadSafe
public final class SimpleHttpClient implements IHttpClient {

  private final OkHttpClient delegate;
  private final InetAddress boundLocalAddress;

  public SimpleHttpClient(OkHttpClient delegate, InetAddress boundLocalAddress) {
    this.delegate = delegate;
    this.boundLocalAddress = boundLocalAddress;
  }

  @Override
  public Response submit(Request request) throws HttpConnectionException {
    try {
      return delegate.newCall(request).execute();
    } catch (InterruptedIOException e) {
      throw new HttpInterruptedException(e);
    } catch (IOException e) {
      throw new HttpConnectionException(e);
    }
  }

  @Override
  public WebSocket submit(Request request, WebSocketListener listener) throws AnyHttpException {
    return delegate.newWebSocket(request, listener);
  }

  @Override
  public InetAddress getBoundLocalAddress() {
    return boundLocalAddress;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy