Commit 074261f1 authored by Administrator's avatar Administrator

链接新服务器

parent 9c7db5a6
package com.virjar.echo.adr.bean;
import lombok.Data;
@Data
public class CommonRes<T> {
private int status = statusOK;
private String message;
private T data;
private String token;
public static final int statusOK = 0;
public static final int statusError = -1;
public static final int statusNeedLogin = -2;
public static final int statusLoginExpire = -3;
public boolean isOk() {
return status == statusOK;
}
}
package com.virjar.echo.adr.bean;
import lombok.Data;
@Data
public class Result<O> {
public static final int OK = 200;
public static final int SERVER_ERROR = 500;
public static final int CLIENT_ERROR = 400;
public static final int NOT_FOUND = 404;
public static final int AUTH_FAIL = 403;
private O data;
private int code;
private String errorMessage;
public boolean isOk() {
return code == OK;
}
}
......@@ -24,6 +24,8 @@ public class APIServices {
private static OkHttpClient createInterceptedOkHttp() {
OkHttpClient.Builder builder = new OkHttpClient.Builder();
// builder.proxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("192.168.0.2", 8888)));
builder.addInterceptor(new Interceptor() {
@Override
public Response intercept(Chain chain) throws IOException {
......
......@@ -17,7 +17,7 @@ public class EchoConfig {
private static String defaultServerHost;
private static int defaultServerPort;
private static final String defaultApiURL = "http://echo.virjar.com/";
private static final String defaultApiURL = "http://echonew.virjar.com/";
private static final String loginTokenKey = "loginToken";
private static final String userNameKey = "userName";
private static final String userPasswordKey = "password";
......
package com.virjar.echo.adr.repo;
import com.virjar.echo.adr.bean.Result;
import com.virjar.echo.adr.bean.CommonRes;
import com.virjar.echo.adr.bean.UserInfo;
import retrofit2.Call;
......@@ -11,16 +11,16 @@ import retrofit2.http.POST;
import retrofit2.http.Query;
public interface UserApi {
@GET("api/user/userInfo")
Call<Result<UserInfo>> loginWithToken();
@GET("api/user-info/userMode")
Call<CommonRes<UserInfo>> loginWithToken();
@FormUrlEncoded
@POST("api/user/login")
Call<Result<UserInfo>> loginWithUsername(@Field("userName") String userName,
@Field("password") String password);
@POST("api/user-info/login")
Call<CommonRes<UserInfo>> loginWithUsername(@Field("userName") String userName,
@Field("password") String password);
@GET("api/user/queryClientMapping")
Call<Result<Integer>> getClientMappingPort(@Query("clientId") String clientId);
@GET("api/user-info/queryClientMapping")
Call<CommonRes<Integer>> getClientMappingPort(@Query("clientId") String clientId);
}
......@@ -13,7 +13,7 @@ import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import com.virjar.echo.adr.R;
import com.virjar.echo.adr.bean.Result;
import com.virjar.echo.adr.bean.CommonRes;
import com.virjar.echo.adr.component.LogServices;
import com.virjar.echo.adr.repo.APIServices;
import com.virjar.echo.adr.repo.EchoConfig;
......@@ -52,11 +52,11 @@ public class LogFragment extends Fragment {
private void updateClientId() {
APIServices.userApi.getClientMappingPort(
EchoConfig.getClientId()
).enqueue(new Callback<Result<Integer>>() {
).enqueue(new Callback<CommonRes<Integer>>() {
@Override
public void onResponse(Call<Result<Integer>> call, Response<Result<Integer>> response) {
final Result<Integer> result = response.body();
if (!result.isOk()) {
public void onResponse(Call<CommonRes<Integer>> call, Response<CommonRes<Integer>> response) {
final CommonRes<Integer> commonRes = response.body();
if (!commonRes.isOk()) {
new Handler(Looper.getMainLooper())
.postDelayed(new Runnable() {
@Override
......@@ -71,13 +71,13 @@ public class LogFragment extends Fragment {
new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public void run() {
mappingView.setText(EchoConfig.getEchoServer() + ":" + result.getData());
mappingView.setText(EchoConfig.getEchoServer() + ":" + commonRes.getData());
}
});
}
@Override
public void onFailure(Call<Result<Integer>> call, Throwable t) {
public void onFailure(Call<CommonRes<Integer>> call, Throwable t) {
EchoLogger.getLogger().error("can not get mapping info", t);
new Handler(Looper.getMainLooper())
.postDelayed(new Runnable() {
......
......@@ -14,7 +14,7 @@ import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import com.virjar.echo.adr.R;
import com.virjar.echo.adr.bean.Result;
import com.virjar.echo.adr.bean.CommonRes;
import com.virjar.echo.adr.bean.UserInfo;
import com.virjar.echo.adr.repo.APIServices;
import com.virjar.echo.adr.repo.EchoConfig;
......@@ -83,13 +83,13 @@ public class LoginActivity extends AppCompatActivity {
autoLoginWithUserName();
return;
}
Call<Result<UserInfo>> loginResponse = APIServices.userApi.loginWithToken();
loginResponse.enqueue(new Callback<Result<UserInfo>>() {
Call<CommonRes<UserInfo>> loginResponse = APIServices.userApi.loginWithToken();
loginResponse.enqueue(new Callback<CommonRes<UserInfo>>() {
@Override
public void onResponse(Call<Result<UserInfo>> call, Response<Result<UserInfo>> response) {
Result<UserInfo> body = response.body();
public void onResponse(Call<CommonRes<UserInfo>> call, Response<CommonRes<UserInfo>> response) {
CommonRes<UserInfo> body = response.body();
if (!body.isOk()) {
EchoLogger.getLogger().info("auto login with token failed: " + body.getErrorMessage());
EchoLogger.getLogger().info("auto login with token failed: " + body.getMessage());
autoLoginWithUserName();
} else {
EchoLogger.getLogger().info("auto login with token success");
......@@ -98,7 +98,7 @@ public class LoginActivity extends AppCompatActivity {
}
@Override
public void onFailure(Call<Result<UserInfo>> call, Throwable t) {
public void onFailure(Call<CommonRes<UserInfo>> call, Throwable t) {
EchoLogger.getLogger().error("auto login with token failed", t);
autoLoginWithUserName();
}
......@@ -120,26 +120,26 @@ public class LoginActivity extends AppCompatActivity {
buttonLogin.setClickable(false);
APIServices.userApi
.loginWithUsername(username, password)
.enqueue(new Callback<Result<UserInfo>>() {
.enqueue(new Callback<CommonRes<UserInfo>>() {
@Override
public void onResponse(Call<Result<UserInfo>> call, Response<Result<UserInfo>> response) {
public void onResponse(Call<CommonRes<UserInfo>> call, Response<CommonRes<UserInfo>> response) {
buttonLogin.setClickable(true);
final Result<UserInfo> result = response.body();
if (!result.isOk()) {
EchoLogger.getLogger().error("login failed:" + result.getErrorMessage());
final CommonRes<UserInfo> commonRes = response.body();
if (!commonRes.isOk()) {
EchoLogger.getLogger().error("login failed:" + commonRes.getMessage());
LoginActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(LoginActivity.this, result.getErrorMessage(), Toast.LENGTH_SHORT).show();
Toast.makeText(LoginActivity.this, commonRes.getMessage(), Toast.LENGTH_SHORT).show();
}
});
return;
}
onLoginSuccess(result.getData());
onLoginSuccess(commonRes.getData());
}
@Override
public void onFailure(Call<Result<UserInfo>> call, Throwable t) {
public void onFailure(Call<CommonRes<UserInfo>> call, Throwable t) {
buttonLogin.setClickable(true);
EchoLogger.getLogger().error("auto login with username failed", t);
}
......
......@@ -8,7 +8,7 @@
<!-- Messages Preferences -->
<string name="server_host_title">ServerHost</string>
<string name="default_server_host">echo.virjar.com</string>
<string name="default_server_host">echonew.virjar.com</string>
<string name="server_port_title">ServerPort</string>
<string name="default_server_port">5698</string>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment