String requestBody = requestFormatter.getRequestBody(getRequest()); JsonHttpContent jsonHttpContent = null; if (!Strings.isNullOrEmpty(requestBody)) { GenericUrl url = new GenericUrl(getEndpoint() + requestFormatter.getPath(getRequest())); Map<String, List<String>> queryParams = requestFormatter.getQueryParamNames(getRequest()); for (Entry<String, List<String>> queryParam : queryParams.entrySet()) { if (queryParam.getValue() != null) {
@Override public MockLowLevelHttpResponse getHttpResponse(String httpMethod, String fullTargetUrl) { MockLowLevelHttpResponse httpResponse = new MockLowLevelHttpResponse(); Preconditions.checkArgument( serviceMethodDescriptors != null, "MockHttpService has null serviceMethodDescriptors."); String relativePath = getRelativePath(fullTargetUrl); for (ApiMethodDescriptor methodDescriptor : serviceMethodDescriptors) { if (!httpMethod.equals(methodDescriptor.getHttpMethod())) { continue; } PathTemplate pathTemplate = methodDescriptor.getRequestFormatter().getPathTemplate(); // Server figures out which RPC method is called based on the endpoint path pattern. if (!pathTemplate.matches(relativePath)) { continue; } // Emulate the server's creation of an HttpResponse from the response message instance. String httpContent = methodDescriptor.getResponseParser().serialize(response); httpResponse.setContent(httpContent.getBytes()); httpResponse.setStatusCode(200); return httpResponse; } // Return 404 when none of this server's endpoint templates match the given URL. httpResponse.setContent( String.format("Method not found for path '%s'", relativePath).getBytes()); httpResponse.setStatusCode(404); return httpResponse; } });
String requestBody = requestFormatter.getRequestBody(getRequest()); HttpContent jsonHttpContent; if (!Strings.isNullOrEmpty(requestBody)) { GenericUrl url = new GenericUrl(getEndpoint() + requestFormatter.getPath(getRequest())); Map<String, List<String>> queryParams = requestFormatter.getQueryParamNames(getRequest()); for (Entry<String, List<String>> queryParam : queryParams.entrySet()) { if (queryParam.getValue() != null) {