use of okio.ByteString in project okhttp by square.
the class Http2Reader method readGoAway.
private void readGoAway(Handler handler, int length, byte flags, int streamId) throws IOException {
if (length < 8)
throw ioException("TYPE_GOAWAY length < 8: %s", length);
if (streamId != 0)
throw ioException("TYPE_GOAWAY streamId != 0");
int lastStreamId = source.readInt();
int errorCodeInt = source.readInt();
int opaqueDataLength = length - 8;
ErrorCode errorCode = ErrorCode.fromHttp2(errorCodeInt);
if (errorCode == null) {
throw ioException("TYPE_GOAWAY unexpected error code: %d", errorCodeInt);
}
ByteString debugData = EMPTY;
if (opaqueDataLength > 0) {
// Must read debug data in order to not corrupt the connection.
debugData = source.readByteString(opaqueDataLength);
}
handler.goAway(lastStreamId, errorCode, debugData);
}
use of okio.ByteString in project retrofit by square.
the class ProtoConverterFactoryTest method deserializeWrongClass.
@Test
public void deserializeWrongClass() throws IOException {
ByteString encoded = ByteString.decodeBase64("Cg4oNTE5KSA4NjctNTMwOQ==");
server.enqueue(new MockResponse().setBody(new Buffer().write(encoded)));
try {
service.wrongClass();
fail();
} catch (IllegalArgumentException e) {
assertThat(e).hasMessage("" + "Unable to create converter for class java.lang.String\n" + " for method Service.wrongClass");
assertThat(e.getCause()).hasMessage("" + "Could not locate ResponseBody converter for class java.lang.String.\n" + " Tried:\n" + " * retrofit2.BuiltInConverters\n" + " * retrofit2.converter.protobuf.ProtoConverterFactory");
}
}
use of okio.ByteString in project retrofit by square.
the class ProtoConverterFactoryTest method serializeAndDeserialize.
@Test
public void serializeAndDeserialize() throws IOException, InterruptedException {
ByteString encoded = ByteString.decodeBase64("Cg4oNTE5KSA4NjctNTMwOQ==");
server.enqueue(new MockResponse().setBody(new Buffer().write(encoded)));
Call<Phone> call = service.post(Phone.newBuilder().setNumber("(519) 867-5309").build());
Response<Phone> response = call.execute();
Phone body = response.body();
assertThat(body.getNumber()).isEqualTo("(519) 867-5309");
RecordedRequest request = server.takeRequest();
assertThat(request.getBody().readByteString()).isEqualTo(encoded);
assertThat(request.getHeader("Content-Type")).isEqualTo("application/x-protobuf");
}
use of okio.ByteString in project retrofit by square.
the class WireConverterFactoryTest method deserializeWrongValue.
@Test
public void deserializeWrongValue() throws IOException {
ByteString encoded = ByteString.decodeBase64("////");
server.enqueue(new MockResponse().setBody(new Buffer().write(encoded)));
Call<?> call = service.get();
try {
call.execute();
fail();
} catch (EOFException ignored) {
}
}
use of okio.ByteString in project retrofit by square.
the class WireConverterFactoryTest method deserializeWrongClass.
@Test
public void deserializeWrongClass() throws IOException {
ByteString encoded = ByteString.decodeBase64("Cg4oNTE5KSA4NjctNTMwOQ==");
server.enqueue(new MockResponse().setBody(new Buffer().write(encoded)));
try {
service.wrongClass();
fail();
} catch (IllegalArgumentException e) {
assertThat(e).hasMessage("" + "Unable to create converter for class java.lang.String\n" + " for method Service.wrongClass");
assertThat(e.getCause()).hasMessage("" + "Could not locate ResponseBody converter for class java.lang.String.\n" + " Tried:\n" + " * retrofit2.BuiltInConverters\n" + " * retrofit2.converter.wire.WireConverterFactory");
}
}
Aggregations