本文整理汇总了Java中retrofit.mime.TypedString类的典型用法代码示例。如果您正苦于以下问题:Java TypedString类的具体用法?Java TypedString怎么用?Java TypedString使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TypedString类属于retrofit.mime包,在下文中一共展示了TypedString类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: performAction
import retrofit.mime.TypedString; //导入依赖的package包/类
@Override
public void performAction(CmdLineParser parser) throws CommandException {
if (!definitionStdIn && null == definitionFile) {
throw new ExitWithCodeException(1, "API definition must be provided", true);
}
// read definition from STDIN or file
String definition;
try (InputStream is = (definitionStdIn ? System.in : Files.newInputStream(definitionFile))) {
definition = CharStreams.toString(new InputStreamReader(is));
} catch (IOException e) {
throw new CommandException(e);
}
LOGGER.debug("Adding definition to API '{}' with contents: {}", this::getModelName, () -> definition);
ManagementApiUtil.invokeAndCheckResponse(() ->
buildServerApiClient(VersionAgnosticApi.class, serverVersion).setDefinition(orgName, name, version, definitionType, new TypedString(definition)));
}
示例2: testInvokeAndCheckResponse_StatusMismatch
import retrofit.mime.TypedString; //导入依赖的package包/类
@Test
public void testInvokeAndCheckResponse_StatusMismatch() throws Exception {
// test data
response = new Response(URL, HttpURLConnection.HTTP_NOT_FOUND, "Not Found",
newArrayList(), new TypedString(""));
// mock behaviour
when(request.get()).thenReturn(response);
// test
try {
ManagementApiUtil.invokeAndCheckResponse(HttpURLConnection.HTTP_OK, request);
fail(CommandException.class + " expected");
} catch (CommandException ignored) {
// verify behaviour
verify(request).get();
}
}
示例3: testInvokeAndCheckResponse_RetrofitError
import retrofit.mime.TypedString; //导入依赖的package包/类
@Test
public void testInvokeAndCheckResponse_RetrofitError() throws Exception {
// test data
response = new Response(URL, HttpURLConnection.HTTP_NOT_FOUND, "Not Found",
newArrayList(), new TypedString(""));
// mock behaviour
when(request.get()).thenThrow(RetrofitError.httpError(URL, response, null, null));
// test
try {
ManagementApiUtil.invokeAndCheckResponse(HttpURLConnection.HTTP_OK, request);
fail(CommandException.class + " expected");
} catch (CommandException ignored) {
// verify behaviour
verify(request).get();
}
}
示例4: post
import retrofit.mime.TypedString; //导入依赖的package包/类
@Test public void post() throws IOException {
TypedString body = new TypedString("hi");
Request request = new Request("POST", HOST + "/foo/bar/", null, body);
okhttp3.Request okRequest = Ok3Client.createRequest(request);
assertThat(okRequest.method()).isEqualTo("POST");
assertThat(okRequest.url().toString()).isEqualTo(HOST + "/foo/bar/");
assertThat(okRequest.headers().size()).isEqualTo(0);
RequestBody okBody = okRequest.body();
assertThat(okBody).isNotNull();
Buffer buffer = new Buffer();
okBody.writeTo(buffer);
assertThat(buffer.readUtf8()).isEqualTo("hi");
}
示例5: post
import retrofit.mime.TypedString; //导入依赖的package包/类
@Test public void post() throws IOException, InterruptedException {
server.enqueue(new MockResponse()
.addHeader("Hello", "World")
.setBody("Hello!"));
Response response = service.post(new TypedString("Hello?"));
assertThat(response.getStatus()).isEqualTo(200);
assertThat(response.getReason()).isEqualTo("OK");
assertThat(response.getUrl()).isEqualTo(server.url("/").toString());
assertThat(response.getHeaders()).contains(new Header("Hello", "World"));
assertThat(buffer(source(response.getBody().in())).readUtf8()).isEqualTo("Hello!");
RecordedRequest request = server.takeRequest();
assertThat(request.getMethod()).isEqualTo("POST");
assertThat(request.getPath()).isEqualTo("/");
assertThat(request.getBody().readUtf8()).isEqualTo("Hello?");
}
示例6: toBody
import retrofit.mime.TypedString; //导入依赖的package包/类
@SuppressWarnings("unchecked") @Override public TypedOutput toBody(Object object) {
try {
// Check if the type contains a parametrized list
if (List.class.isAssignableFrom(object.getClass())) {
// Convert the input to a list first, access the first element and serialize the list
List<Object> list = (List<Object>) object;
if (list.isEmpty()) {
return new TypedString("[]");
} else {
Object firstElement = list.get(0);
return new TypedString(LoganSquare.serialize(list, (Class<Object>) firstElement.getClass()));
}
} else {
// Serialize single elements immediately
return new TypedString(LoganSquare.serialize(object));
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例7: putInterpretationComment
import retrofit.mime.TypedString; //导入依赖的package包/类
public void putInterpretationComment(InterpretationComment comment) throws APIException {
Interpretation interpretation = comment.getInterpretation();
if (interpretation != null && interpretation.getState() != null) {
boolean isInterpretationSynced = (interpretation.getState().equals(State.SYNCED) ||
interpretation.getState().equals(State.TO_UPDATE));
if (!isInterpretationSynced) {
return;
}
try {
mDhisApi.putInterpretationComment(interpretation.getUId(),
comment.getUId(), new TypedString(comment.getText()));
comment.setState(State.SYNCED);
comment.save();
updateInterpretationTimeStamp(comment.getInterpretation());
} catch (APIException apiException) {
handleApiException(apiException);
}
}
}
示例8: toBody
import retrofit.mime.TypedString; //导入依赖的package包/类
@SuppressWarnings("unchecked") @Override public TypedOutput toBody(Object object) {
try {
// Check if the type contains a parametrized list
if (List.class.isAssignableFrom(object.getClass())) {
// Convert the input to a list first, access the first element and serialize the list
List<Object> list = (List<Object>) object;
if (list.isEmpty()) {
return new TypedString("[]");
} else {
Object firstElement = list.get(0);
return new TypedString(
LoganSquare.serialize(list, (Class<Object>) firstElement.getClass()));
}
} else {
// Serialize single elements immediately
return new TypedString(LoganSquare.serialize(object));
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例9: toBody
import retrofit.mime.TypedString; //导入依赖的package包/类
@SuppressWarnings("unchecked") @Override public TypedOutput toBody(Object object) {
try {
// Check if the type contains a parametrized list
if (List.class.isAssignableFrom(object.getClass())) {
// Convert the input to a list first, access the first element and serialize the list
List<Object> list = (List<Object>) object;
if (list.isEmpty()) {
return new TypedString("[]");
} else {
Object firstElement = list.get(0);
return new TypedString(LoganSquare.serialize(list, (Class<Object>) firstElement.getClass()));
}
} else {
// Serialize single elements immediately
return new TypedString(LoganSquare.serialize(object));
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例10: toBody
import retrofit.mime.TypedString; //导入依赖的package包/类
@Override
public TypedOutput toBody(Object object) {
try {
// Check if the type contains a parametrized list
if (List.class.isAssignableFrom(object.getClass())) {
// Convert the input to a list first, access the first element and serialize the list
List<Object> list = (List<Object>) object;
if (list.isEmpty()) {
return new TypedString("[]");
}
else {
Object firstElement = list.get(0);
return new TypedString(LoganSquare.serialize(list, (Class<Object>) firstElement.getClass()));
}
}
else {
// Serialize single elements immediately
return new TypedString(LoganSquare.serialize(object));
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例11: testAvatar
import retrofit.mime.TypedString; //导入依赖的package包/类
@Ignore
@Test
public void testAvatar() {
File pictureFile = new File("ytsclient/src/integration/resources/logo.png");
TypedFile picture = new TypedFile("application/octet-stream", pictureFile);
TypedString appKey = new TypedString(APPLICATION_KEY);
TypedString userKey = new TypedString(USER_KEY);
YtsResponse<Profile> response = CLIENT
.user()
.picture(appKey, userKey, picture);
assertNotNull(response);
assertEquals(YtsStatus.OK, response.status);
assertNotNull(response.data);
assertNotNull(response.data.smallImageUrl);
}
示例12: execute
import retrofit.mime.TypedString; //导入依赖的package包/类
@Override
public Response execute(Request request) throws IOException {
List<Matcher<? super Request>> unmatchedRoutes = new LinkedList<>();
for (Route route : routes) {
if (route.requestMatcher.matches(request)) return route.response.createFrom(request);
unmatchedRoutes.add(route.requestMatcher);
}
StringDescription description = new StringDescription();
AnyOf.anyOf(unmatchedRoutes).describeTo(description);
return new Response(
request.getUrl(),
404,
"No route matched",
Collections.<Header>emptyList(),
new TypedString("No matching route found. expected:\n" + description.toString())
);
}
示例13: testPOSTDataEcho
import retrofit.mime.TypedString; //导入依赖的package包/类
@Test
public void testPOSTDataEcho() throws Exception {
// Given
final String postBodyString = "hello";
HttpRequestClient httpRequestClient = new HttpRequestClient();
TypedOutput postBody = new TypedString(postBodyString);
Request request = new Request("POST", HTTP_BIN_ROOT + "/post", null, postBody);
// When
final Response response = httpRequestClient.execute(request);
ObjectMapper objectMapper = new ObjectMapper();
Map<String, Object> jsonObj = objectMapper.readValue(response.getBody().in(), Map.class);
// Then
assertNotNull(response);
assertThat(response.getStatus(), is(200));
assertThat(jsonObj.get("data").toString(), is(postBodyString));
}
示例14: malformedResponseThrowsConversionException
import retrofit.mime.TypedString; //导入依赖的package包/类
@Test
public void malformedResponseThrowsConversionException() throws Exception
{
when(mockClient.execute(any(Request.class))) //
.thenReturn(new Response(200, "OK", NO_HEADERS, new TypedString("{")));
try
{
example.something();
fail("RetrofitError expected on malformed response body.");
}
catch (RetrofitError e)
{
assertThat(e.getResponse().getStatus()).isEqualTo(200);
assertThat(e.getCause()).isInstanceOf(ConversionException.class);
assertThat(e.getResponse().getBody()).isNull();
}
}
示例15: observableHandlesParams
import retrofit.mime.TypedString; //导入依赖的package包/类
@Test
public void observableHandlesParams() throws Exception
{
ArgumentCaptor<Request> requestCaptor = ArgumentCaptor.forClass(Request.class);
when(mockClient.execute(requestCaptor.capture())) //
.thenReturn(new Response(200, "OK", NO_HEADERS, new TypedString("hello")));
ArgumentCaptor<Response> responseCaptor = ArgumentCaptor.forClass(Response.class);
Action1<Response> action = mock(Action1.class);
example.observable("X", "Y").subscribe(action);
Request request = requestCaptor.getValue();
assertThat(request.getUrl()).contains("/X/Y");
verify(action).call(responseCaptor.capture());
Response response = responseCaptor.getValue();
assertThat(response.getStatus()).isEqualTo(200);
}