本文整理汇总了Java中com.squareup.okhttp.mockwebserver.RecordedRequest.getPath方法的典型用法代码示例。如果您正苦于以下问题:Java RecordedRequest.getPath方法的具体用法?Java RecordedRequest.getPath怎么用?Java RecordedRequest.getPath使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.squareup.okhttp.mockwebserver.RecordedRequest
的用法示例。
在下文中一共展示了RecordedRequest.getPath方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: assertSent
import com.squareup.okhttp.mockwebserver.RecordedRequest; //导入方法依赖的package包/类
protected RecordedRequest assertSent(final MockWebServer server,
final String method,
final String expectedPath,
final Map<String, ?> queryParams) throws InterruptedException {
final RecordedRequest request = server.takeRequest();
assertThat(request.getMethod()).isEqualTo(method);
assertThat(request.getHeader(HttpHeaders.ACCEPT)).isEqualTo(APPLICATION_JSON);
final String path = request.getPath();
final String rawPath = path.contains("?") ? path.substring(0, path.indexOf('?')) : path;
assertThat(rawPath).isEqualTo(expectedPath);
final Map<String, String> normalizedParams = Maps.transformValues(queryParams, Functions.toStringFunction());
assertThat(normalizedParams).isEqualTo(extractParams(path));
return request;
}
示例2: handle
import com.squareup.okhttp.mockwebserver.RecordedRequest; //导入方法依赖的package包/类
@Override
public MockResponse handle(RecordedRequest request, String root) {
String path = request.getPath();
RequestInfo requestInfo = new RequestInfo();
int index = path.indexOf("?");
if (index > -1) {
String queryString = path.substring(index + 1);
path = path.substring(0, index);
requestInfo.params = HttpUtil.getParamsMap(queryString, Util.UTF_8.name());
}
if(path.startsWith("/download/")){
MockResponse mr = handleDownload(request, root);
mr.addHeader("RequestHeaders",request.getHeaders().toString());
mr.addHeader("RequestParams",requestInfo.params);
return mr;
}
requestInfo.method = request.getMethod();
requestInfo.path = path;
requestInfo.headers = request.getHeaders().toMultimap();
String methodUp = requestInfo.method.toUpperCase();
if(methodUp.equals("POST")||methodUp.equals("PUT")){
requestInfo.bodyInfo = createBodyInfo(request);
}
BaseResult<RequestInfo> result = new BaseResult<>();
result.requestMethod = requestInfo.method;
result.requestPath = requestInfo.path;
result.data = requestInfo;
return new MockResponse().setStatus("HTTP/1.1 200").addHeader("content-type: application/json; charset=utf-8")
.setBody(JSON.toJSONString(result));
}
示例3: dispatch
import com.squareup.okhttp.mockwebserver.RecordedRequest; //导入方法依赖的package包/类
/**
* 处理请求的结果。
* @param recordedRequest
* @return
*/
private MockResponse dispatch(RecordedRequest recordedRequest) {
String path = recordedRequest.getPath();
String url = urlMap.get(path);
for (Entry<Matcher, MockResponse> entry : responseMap.entrySet()) {
Matcher m = entry.getKey();
if (m.methodMatcher.matching(recordedRequest) && m.urlMatcher.matching(url)) {
return entry.getValue();
}
}
return new MockResponse().setResponseCode(404);
}