나는 내 발가락을 안드로이드 개발에 집중시키고있다. RESTful 리소스와 인터페이스 할 프로젝트가 있고 HTTP를 통해 params를 사용하여 기본 GET을 수행하는 방법을 파악하려고합니다. 내가 읽은 모든 것에서, 합의는 HttpURLConnection보다 HTTPClient를 선호하는 것으로 보인다.Apache DefaultHttpClient 호출의 결과는 "java.lang.RuntimeException : Stub!"입니다.
내가 키 객체를 인스턴스화을 담당하는 방법으로 래퍼 클래스를 작성했습니다는 HttpClient를 사용하여 요청을 만들려면 :
public String get() {
String responseString = null;
HttpClient client = new DefaultHttpClient();
HttpGet get = new HttpGet();
try {
get.setURI(new URI(this.baseURL()));
} catch (URISyntaxException e1) {
e1.printStackTrace();
}
HttpResponse response;
try {
response = client.execute(get);
responseString = readResponse(response.getEntity());
if(response != null) {
System.out.println(responseString);
}
} catch(ClientProtocolException e) {
e.printStackTrace();
} catch(IOException e) {
e.printStackTrace();
}
return responseString;
을}
HttpClient client = new DefaultHttpClient();
는 다음과 같은 예외를 throw 라인 :
java.lang.RuntimeException: Stub!
at org.apache.http.impl.client.AbstractHttpClient.<init>(AbstractHttpClient.java:5)
at org.apache.http.impl.client.DefaultHttpClient.<init>(DefaultHttpClient.java:7)
at org.rcindustries.appmap.RestClient.get(RestClient.java:54)
at org.rcindustries.appmap.test.functional.RestClientTest.shouldReturnSomeJSon(RestClientTest.java:26)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
HttpClient에서 본 모든 예에서는 GET 및 POST와 유사한 구조를 사용합니다. 아파치 커먼즈 라이브러리는 안드로이드 SDK와 번들로 제공되는 것과 상당히 다른 표준 라이브러리입니까?
그래서 메소드를 스텁 아웃 한 서비스/라이브러리가 있습니까? dev.android.com에 이것에 대해 설명하는 내용이 있습니까? 저는 Android 생태계에 익숙하지 않아이 부분을 찾을 곳이 확실하지 않습니다. – manlycode
예외 메시지를 "검색"하고 스택 추적에서 추론을 그려서이 사실을 알았습니다. 나는 안드로이드 개발을 직접하지 않는다. –
일반적으로 Java에서 스텁 메서드 만있는 인터페이스를 노출하는 것이 일반적인 방법입니까? 대학 시절에 사용 했으므로 오래 동안이었습니다. 자바로 TDD를 처음 접했습니다. – manlycode