Java tutorial
/* * Copyright 2013-2014 Urs Wolfer * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.urswolfer.gerrit.client.rest.http; import com.squareup.okhttp.OkHttpClient; import com.squareup.okhttp.Request; import com.squareup.okhttp.Response; import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpRequestBase; import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.protocol.HttpContext; import java.io.IOException; /** * Allows custom handling when executing a http request (e.g. custom exception handling). * * @author Urs Wolfer */ public class HttpRequestExecutor { public HttpResponse execute(HttpClientBuilder client, HttpRequestBase method, HttpContext context) throws IOException { return client.build().execute(method, context); } public Response execute(OkHttpClient client, Request.Builder builder) throws IOException { return client.newCall(builder.build()).execute(); } }