use of com.reprezen.kaizen.oasparser.model3.MediaType in project okhttp by square.
the class HttpOverHttp2Test method userSuppliedContentLengthHeader.
@Test
public void userSuppliedContentLengthHeader() throws Exception {
final byte[] postBytes = "FGHIJ".getBytes(Util.UTF_8);
server.enqueue(new MockResponse().setBody("ABCDE"));
Call call = client.newCall(new Request.Builder().url(server.url("/foo")).post(new RequestBody() {
@Override
public MediaType contentType() {
return MediaType.parse("text/plain; charset=utf-8");
}
@Override
public long contentLength() throws IOException {
return postBytes.length;
}
@Override
public void writeTo(BufferedSink sink) throws IOException {
sink.write(postBytes);
}
}).build());
Response response = call.execute();
assertEquals("ABCDE", response.body().string());
RecordedRequest request = server.takeRequest();
assertEquals("POST /foo HTTP/1.1", request.getRequestLine());
assertArrayEquals(postBytes, request.getBody().readByteArray());
assertEquals(postBytes.length, Integer.parseInt(request.getHeader("Content-Length")));
}
use of com.reprezen.kaizen.oasparser.model3.MediaType in project camel by apache.
the class MultiPartFormOkHttpTest method createMultipartRequest.
private Request createMultipartRequest() throws Exception {
MediaType mediaType = MediaType.parse("multipart/form-data; boundary=---011000010111000001101001");
RequestBody body = RequestBody.create(mediaType, "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"test\"\r\n\r\nsome data here\r\n-----011000010111000001101001--");
Request request = new Request.Builder().url("http://localhost:" + getPort() + "/test").post(body).addHeader("content-type", "multipart/form-data; boundary=---011000010111000001101001").addHeader("cache-control", "no-cache").addHeader("postman-token", "a9fd95b6-04b9-ea7a-687e-ff828ea00774").build();
return request;
}
use of com.reprezen.kaizen.oasparser.model3.MediaType in project WeexErosFramework by bmfe.
the class WeexOkhttp3Interceptor method intercept.
@Override
public Response intercept(Chain chain) throws IOException {
String requestId = String.valueOf(mNextRequestId.getAndIncrement());
Request request = chain.request();
mEventReporter = NetworkEventReporterManager.get();
RequestBodyHelper requestBodyHelper = null;
if (mEventReporter != null) {
requestBodyHelper = new RequestBodyHelper(mEventReporter, requestId);
OkHttpInspectorRequest inspectorRequest = new OkHttpInspectorRequest(requestId, request, requestBodyHelper);
mEventReporter.requestWillBeSent(inspectorRequest);
}
Response response;
try {
response = chain.proceed(request);
} catch (IOException e) {
if (mEventReporter != null) {
mEventReporter.httpExchangeFailed(requestId, e.toString());
}
throw e;
}
if (mEventReporter != null) {
if (requestBodyHelper.hasBody()) {
requestBodyHelper.reportDataSent();
}
Connection connection = chain.connection();
mEventReporter.responseHeadersReceived(new OkHttpInspectorResponse(requestId, request, response));
ResponseBody body = response.body();
MediaType contentType = null;
InputStream responseStream = null;
if (body != null) {
contentType = body.contentType();
responseStream = body.byteStream();
}
responseStream = mEventReporter.interpretResponseStream(requestId, contentType != null ? contentType.toString() : null, response.header("Content-Encoding"), responseStream, new DefaultResponseHandler(mEventReporter, requestId));
if (responseStream != null) {
response = response.newBuilder().body(new ForwardingResponseBody(body, responseStream)).build();
}
}
return response;
}
use of com.reprezen.kaizen.oasparser.model3.MediaType in project WeexErosFramework by bmfe.
the class AxiosManager method createRequestBodyByMediaType.
private RequestBody createRequestBodyByMediaType(Map<String, String> header, String content) {
if (header != null && !TextUtils.isEmpty(header.get("Content-Type"))) {
String s = header.get("Content-Type");
MediaType mediaType = null;
try {
mediaType = MediaType.parse(s);
} catch (Exception e) {
e.printStackTrace();
}
if (mediaType == null) {
mediaType = MediaType.parse(DEFAULT_MEDIATYPE);
}
return RequestBody.create(mediaType, content);
}
return RequestBody.create(MediaType.parse(DEFAULT_MEDIATYPE), content);
}
use of com.reprezen.kaizen.oasparser.model3.MediaType in project couchbase-lite-android by couchbase.
the class ReplicatorWithSyncGatewayTest method getSessionAuthenticatorFromSG.
SessionAuthenticator getSessionAuthenticatorFromSG() throws Exception {
// Obtain Sync-Gateway Session ID
final MediaType JSON = MediaType.parse("application/json; charset=utf-8");
OkHttpClient client = new OkHttpClient();
String url = String.format(Locale.ENGLISH, "http://%s:4985/seekrit/_session", config.remoteHost());
RequestBody body = RequestBody.create(JSON, "{\"name\": \"pupshaw\"}");
Request request = new Request.Builder().url(url).post(body).build();
Response response = client.newCall(request).execute();
String respBody = response.body().string();
Log.e(TAG, "json string -> " + respBody);
JSONObject json = new JSONObject(respBody);
return new SessionAuthenticator(json.getString("session_id"), json.getString("cookie_name"));
}
Aggregations