In my app, I want to use Retrofit2 to connect to the server and get some data.
For this, I've written the code as shown below but it doesn't show the data. And for some reason, no (detailed) error is outputted.
private void getDetailData(String auctionID, final String jwtToken) {
showLoading(true);
Call<DetailResponse> call = apis.getDetainAuctions(auctionID, jwtToken, agent);
call.enqueue(new Callback<DetailResponse>() {
#Override
public void onResponse(Call<DetailResponse> call, final Response<DetailResponse> response) {
Log.e("detailLog", "OK");
Log.e("detailLog", response.message() + " --- " + response.errorBody());
if (response.isSuccessful()) {
}
}
#Override
public void onFailure(Call<DetailResponse> call, Throwable t) {
Log.e("detailLog", "Err : " + t.getMessage());
}
});
}
Logcat error:
E/detailLog: --- okhttp3.ResponseBody$1#cbf85bc
What does the error mean?
Related
I have an issue similar to this post : Pulling image from Amazon ECR using docker-java. Although, even by adding the "withAuthConfig" and "withRepository", I still have the "unauthorized: incorrect username or password". Any idea why ?
My code :
public void pullImage() {
GetAuthorizationTokenRequest request = new GetAuthorizationTokenRequest();
// Get Authorization Token
GetAuthorizationTokenResult response = client.getAuthorizationToken(request);
AuthorizationData authData = response.getAuthorizationData().get(0);
String userPassword = StringUtils.newStringUtf8(Base64.decodeBase64(authData.getAuthorizationToken()));
String user = userPassword.substring(0, userPassword.indexOf(":"));
String password = userPassword.substring(userPassword.indexOf(":") + 1);
DockerClientConfig config = DefaultDockerClientConfig.createDefaultConfigBuilder()
.withDockerTlsVerify(false)
.withRegistryUsername(user)
.withRegistryPassword(password)
.withRegistryUrl(authData.getProxyEndpoint().replace("https://", ""))
.build();
DockerHttpClient httpClient = new ApacheDockerHttpClient.Builder()
.dockerHost(config.getDockerHost())
.sslConfig(config.getSSLConfig())
.maxConnections(100)
.connectionTimeout(Duration.ofSeconds(30))
.responseTimeout(Duration.ofSeconds(45))
.build();
//Docker client
DockerClient dockerClient = DockerClientImpl.getInstance(config, httpClient);
// Response
AuthResponse authResponse = dockerClient.authCmd().exec();
System.out.println(authResponse.getStatus());
// Pull image
PullImageCmd pullImageCmd = dockerClient
.pullImageCmd(respositoryname)
.withAuthConfig(dockerClient.authConfig())
.withRepository(respositoryname);
pullImageCmd.exec(new ResultCallback<PullResponseItem>() {
#Override
public void onStart(Closeable closeable) {
System.out.println("Pull started : " + closeable);
}
#Override
public void onNext(PullResponseItem object) {
System.out.println("Pull on next : " + object);
}
#Override
public void onError(Throwable throwable) {
System.out.println("Pull error : " + throwable);
}
#Override
public void onComplete() {
System.out.println("Pull finished");
}
#Override
public void close() throws IOException {
System.out.println("Pull closed");
}
});
}
Result :
Login Succeeded
Pull error : com.github.dockerjava.api.exception.InternalServerErrorException: Status 500: {"message":"Get \"https://registry-1.docker.io/v2/library/pleiade3tierserver/tags/list\": unauthorized: incorrect username or password"}
I try to connect to the server using a web socket, but this error occurs.
java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
Here's my code for the connection.
private final class EchoWebSocketListener extends WebSocketListener {
#Override
public void onOpen(WebSocket webSocket, Response response) {
webSocket.send("text");
}
#Override
public void onMessage(WebSocket webSocket, String text) {
output("Receiving : " + text);
}
#Override
public void onMessage(WebSocket webSocket, ByteString bytes) {
output("Receiving bytes : " + bytes.hex());
}
#Override
public void onClosing(WebSocket webSocket, int code, String reason) {
webSocket.close(NORMAL_CLOSURE_STATUS, null);
output("Closing : " + code + " / " + reason);
}
#Override
public void onFailure(WebSocket webSocket, Throwable t, Response response) {
output("Error : " + t.getMessage());
}
}
private void start() {
Request request = new Request.Builder().url("wss://xxx.xxx.xxx.xxx:8443/one2many").build();
EchoWebSocketListener listener = new EchoWebSocketListener();
WebSocket ws = client.newWebSocket(request, listener);
client.dispatcher().executorService().shutdown();
}
}
I am staying in this problem and I want you to help me!
The error happened when i upload a 115KB image file to server.(the most answer of stackoverflow is about download the file.I do not know if it is the same to those)
the error information is below:
onFailure : java.net.ProtocolException: unexpected end of stream
Relevant Code:
public void upLoadImageFile(String uploadUrl, File file, Map<String, String> maps, final HWUploadListener listener) {
final CallbackHandler handler = new CallbackHandler(listener);
try {
MultipartBody.Builder builder = new MultipartBody.Builder().setType(MultipartBody.FORM);
if (maps == null) {
builder.addPart(Headers.of("Content-Disposition", "form-data; name=\"image\";filename=\"file.jpg\""),
RequestBody.create(MediaType.parse("image/jpeg"), file)).build();
} else {
for (String key : maps.keySet()) {
builder.addFormDataPart(key, maps.get(key));
}
builder.addPart(Headers.of("Content-Disposition", "form-data; name=\"image\";filename=" + file.getName()), RequestBody.create(MediaType.parse("image/jpeg"), file)
);
}
RequestBody body = builder.build();
final Request request = new Request.Builder().url(uploadUrl).post(body).build();
final Call call = mOkHttpClient.newBuilder().writeTimeout(50, TimeUnit.SECONDS).build().newCall(request);
call.enqueue(new Callback() {
#Override
public void onFailure(Call call, IOException e) {
UtilUtils1.log("HuowuSdk", "onFailure :" + e.toString());
handler.uploadFailure(e.toString());
}
#Override
public void onResponse(Call call, Response response) throws IOException {
if (response.isSuccessful()) {
String result = response.body().string();
handler.uploadSuccess(result);
} else {
handler.uploadFailure(response.message());
}
}
});
} catch (Exception e) {
UtilUtils1.log("HuowuSdk", e.toString());
handler.uploadError(e.toString());
}
}
Appreciate your answer!!
Here in this line below you have to increase write timeout because while uploading your write timeout expires that may be the reason so in below line increase writeTimeout limit:
final Call call = mOkHttpClient.newBuilder().writeTimeout(50, TimeUnit.SECONDS).build().newCall(request);
How to get the value by name of a websocket response(string),I have tried convert response into jsonArray but it didn't work.
So how can I get the value(mop floor) by key(task)? I am using android studio to develop app. The problem occurs at output ("Task to do: " +text.get("task"));
private final class EchoWebsocketListener extends WebSocketListener{
#Override
public void onOpen(WebSocket webSocket, okhttp3.Response response) {
webSocket.send("{\n" +
" \"task\": \"Mop floor\",\n" +
" \"time_limit\": \"1\"\n" +
"}");
}
#Override
public void onMessage(WebSocket webSocket, String text) {
output("Task to do: " +text.get("task"));
}
#Override
public void onClosed(WebSocket webSocket, int code, String reason) {
webSocket.close(1000,"Goodbye!");
}
#Override
public void onFailure(WebSocket webSocket, Throwable t, okhttp3.Response response) {
output("Error in websocket : " + t.getMessage());
}
}
i have included the retrofit dependency in my project but still i m getting error on response object.
here is my code:
public void jsontesting() {
RestAdapter restAdapter = (RestAdapter) new RestAdapter.Builder().setEndpoint("http://app-development.in/doctor_app_cms/doctor_rest/v1/doctors_listing?id=10").build();
final LatlngAPI get = restAdapter.create(LatlngAPI.class);
get.get_doctor(new retrofit.Callback<CustomeAdapter>()) {
#Override
public void success(CustomeAdapter res, Response response) {
if (!res.getError()) {
// dismiss_dialog();
} else {
/*Toast.makeText(LoginActivity.this, R.string.retrofit_error,
Toast.LENGTH_SHORT).show();*/
}
}
#Override
public void failure(RetrofitError error) {
// dismiss_dialog();
Log.d("Error", error.toString());
/*Toast.makeText(LoginActivity.this, R.string.retrofit_error,
Toast.LENGTH_SHORT).show();*/
}
});
}
I have solved my error. The problem was I am importing wrong response.