Search in sources :

Example 66 with RequestBody

use of com.reprezen.kaizen.oasparser.model3.RequestBody in project micronaut-kubernetes by micronaut-projects.

the class OkHttpClientLogging method intercept.

@NonNull
@Override
public Response intercept(@NonNull Chain chain) throws IOException {
    Request request = chain.request();
    Connection connection = chain.connection();
    if (LOG.isTraceEnabled()) {
        try {
            String method = request.method();
            RequestBody requestBody = request.body();
            Headers headers = request.headers();
            LOG.trace("--> {} {} {} {}-byte body", method, request.url(), (connection != null ? connection.protocol() : ""), (requestBody != null ? requestBody.contentLength() : "0"));
            // log headers for trace
            for (int i = 0; i < headers.size(); i++) {
                LOG.trace("{}: {}", headers.name(i), headers.value(i));
            }
        } catch (Exception e) {
            LOG.warn("Failed to generate OkHttpClient request log: " + e.getMessage(), e);
        }
    }
    Response response = null;
    try {
        response = chain.proceed(request);
    } catch (Exception e) {
        if (LOG.isErrorEnabled()) {
            LOG.error("HTTP FAILED: " + e.getMessage(), e);
        }
        throw e;
    }
    if (LOG.isDebugEnabled()) {
        try {
            ResponseBody responseBody = response.body();
            long contentLength = responseBody.contentLength();
            String contentLengthString = contentLength == -1L ? "unknown-length" : String.format("%s-byte", contentLength);
            Headers headers = response.headers();
            if (LOG.isTraceEnabled()) {
                LOG.trace("<-- {} {} {} {}", response.code(), response.message(), response.request().url(), contentLengthString);
                for (int i = 0; i < headers.size(); i++) {
                    LOG.trace("{}: {}", headers.name(i), headers.value(i));
                }
            } else {
                String method = request.method();
                RequestBody requestBody = request.body();
                LOG.debug("KubeApi {} {} {} OUT<{}-byte> IN <{}> {}", method, request.url(), (connection != null ? connection.protocol() : ""), (requestBody != null ? requestBody.contentLength() : "0"), contentLengthString, response.code());
            }
        } catch (Exception e) {
            if (LOG.isWarnEnabled()) {
                LOG.warn("Failed to generate OkHttpClient Response log: " + e.getMessage(), e);
            }
        }
    }
    return response;
}
Also used : Response(okhttp3.Response) Headers(okhttp3.Headers) Request(okhttp3.Request) Connection(okhttp3.Connection) IOException(java.io.IOException) RequestBody(okhttp3.RequestBody) ResponseBody(okhttp3.ResponseBody) NonNull(io.micronaut.core.annotation.NonNull)

Example 67 with RequestBody

use of com.reprezen.kaizen.oasparser.model3.RequestBody in project C3 by Hi5App.

the class HttpUtilsSoma method getPotentialLocationWithOkHttp.

public static void getPotentialLocationWithOkHttp(JSONObject userInfo, Callback callback) {
    try {
        RequestBody body = RequestBody.create(JSON, String.valueOf(new JSONObject().put("user", userInfo)));
        asyncPostRequest(URL_GET_POTENTIAL_LOCATION, body, callback);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : JSONObject(org.json.JSONObject) RequestBody(okhttp3.RequestBody)

Example 68 with RequestBody

use of com.reprezen.kaizen.oasparser.model3.RequestBody in project C3 by Hi5App.

the class HttpUtilsUser method loginWithOkHttp.

/* 登录 异步方法 */
public static void loginWithOkHttp(JSONObject userInfo, Callback callback) {
    try {
        RequestBody body = RequestBody.create(JSON, String.valueOf(new JSONObject().put("user", userInfo)));
        asyncPostRequest(URL_LOGIN, body, callback);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : JSONObject(org.json.JSONObject) RequestBody(okhttp3.RequestBody)

Example 69 with RequestBody

use of com.reprezen.kaizen.oasparser.model3.RequestBody in project C3 by Hi5App.

the class HttpUtilsUserPerformance method getUserPerformance.

public static void getUserPerformance(JSONObject userInfo, Callback callback) {
    try {
        RequestBody body = RequestBody.create(JSON, String.valueOf(new JSONObject().put("user", userInfo)));
        asyncPostRequest(URL_SOMA_COUNT, body, callback);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : JSONObject(org.json.JSONObject) RequestBody(okhttp3.RequestBody)

Example 70 with RequestBody

use of com.reprezen.kaizen.oasparser.model3.RequestBody in project C3 by Hi5App.

the class HttpUtilsCheck method checkWithOkHttp.

public static void checkWithOkHttp(String arborname, String username, String password, String owner, int result, Callback callback) {
    try {
        RequestBody body = RequestBody.create(JSON, String.valueOf(new JSONObject().put("arborname", arborname).put("name", username).put("password", password).put("owner", owner).put("result", result)));
        asyncPostRequest(URL_CHECK, body, callback);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : JSONObject(org.json.JSONObject) RequestBody(okhttp3.RequestBody)

Aggregations

RequestBody (okhttp3.RequestBody)1358 Request (okhttp3.Request)785 Response (okhttp3.Response)598 IOException (java.io.IOException)420 Test (org.junit.Test)235 OkHttpClient (okhttp3.OkHttpClient)216 MultipartBody (okhttp3.MultipartBody)213 MediaType (okhttp3.MediaType)204 Call (okhttp3.Call)198 JSONObject (org.json.JSONObject)183 ResponseBody (okhttp3.ResponseBody)177 Callback (okhttp3.Callback)115 FormBody (okhttp3.FormBody)106 Buffer (okio.Buffer)98 File (java.io.File)92 Map (java.util.Map)90 JsonObject (io.vertx.core.json.JsonObject)89 Headers (okhttp3.Headers)88 HashMap (java.util.HashMap)83 HttpUrl (okhttp3.HttpUrl)80