Square에서 MockWebServer를 구현하려고하는데 프록시가 필요합니다. 문제는 매번 MoodWebServer에 대한 모든 요청에 대해 407을 얻고 있기 때문에 계측 테스트가 실패 할 때마다 실패한다는 것입니다.프록시와 함께 작동하도록 MockWebServer를 구현하는 방법
debug.level.titleD/OkHttp: <-- 407 Proxy Authentication Required http://localhost:12345/user/login (767ms)
나는 내 로컬 호스트를 가리키며 나는 왜 이것을 얻고 있는지 모른다.
여기 내 MockWebServer 구현입니다!
public class MockedTestServer {
private final int PORT = 12345;
private final MockWebServer server;
private int lastResponseCode;
private String lastRequestPath;
/**
* Creates and starts a new server, with a non-default dispatcher
*
* @throws Exception
*/
public MockedTestServer() throws Exception {
server = new MockWebServer();
server.start(PORT);
setDispatcher();
}
private void setDispatcher() {
final Dispatcher dispatcher = new Dispatcher() {
@Override
public MockResponse dispatch(final RecordedRequest request) throws InterruptedException {
try {
final String requestPath = request.getPath();
final MockResponse response = new MockResponse().setResponseCode(200);
String filename;
// response for alerts
if (requestPath.equals(Constantes.ACTION_LOGIN)) {
filename = ConstantesJSON.LOGIN_OK;
} else {
// no response
lastResponseCode = 404;
return new MockResponse().setResponseCode(404);
}
lastResponseCode = 200;
response.setBody(RestServiceTestHelper.getStringFromFile(filename));
lastRequestPath = requestPath;
return response;
} catch (final Exception e) {
throw new InterruptedException(e.getMessage());
}
}
};
server.setDispatcher(dispatcher);
}
public String getLastRequestPath() {
return lastRequestPath;
}
public String getUrl() {
return server.url("/").toString();
}
public int getLastResponseCode() {
return lastResponseCode;
}
public void setDefaultDispatcher() {
server.setDispatcher(new QueueDispatcher());
}
public void enqueueResponse(final MockResponse response) {
server.enqueue(response);
}
public void shutdownServer() throws IOException {
server.shutdown();
}
계측 테스트를 수행 할 때 나의 엔드 포인트는 "/"입니다.
이 문제는 프록시 네트워크 뒤에있을 때만 발생합니다. 모바일 장치에서 프록시가 아닌 다른 네트워크로 전환하면 모의 서버가 제대로 작동합니다. 어떤 생각이 내가 뭘 잘못하고 있니?
편집 : 내가 프록시 뒤에 생각하면라는 결코 극복 디스패처