Я пытаюсь использовать свой веб-сервис через API-интерфейс клиента.
Это мой веб-сервис:
@Path("/myresource")
@Component
@Scope("request")
public class MyResource {
@GET
@Produces(MediaType.TEXT_PLAIN)
@Path("test")
public String test(){
return "test";
}
}
Это мой клиент:
public class MyClient {
public static void main(String[] args) {
System.out.println(Client.create().resource( "http://testwebservice.de:8080/CompetenceNetwork/api/myresource/test" ).get( String.class ) );
}
}
Все работает отлично. Теперь я пытаюсь это сделать в классе Android:
TextView tv;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
tv = new TextView(this);
Client c = Client.create();
WebResource r = c.resource("http://testwebservice.de:8080/CompetenceNetwork/api/myresource/test");
String s = r.get(String.class);
tv.setText(s);
setContentView(tv);
}
Ничего не происходит, и через несколько минут я получаю следующее исключение:
11-04 17:13:27.382: ERROR/AndroidRuntime(231): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.tablayout/com.example.tablayout.MyLogin}: com.sun.jersey.api.client.ClientHandlerException: java.net.SocketException: The operation timed out
11-04 17:13:27.382: ERROR/AndroidRuntime(231): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
11-04 17:13:27.382: ERROR/AndroidRuntime(231): at android.app.ActivityThread.startActivityNow(ActivityThread.java:2335)
11-04 17:13:27.382: ERROR/AndroidRuntime(231): at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:127)
11-04 17:13:27.382: ERROR/AndroidRuntime(231): at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:339)
11-04 17:13:27.382: ERROR/AndroidRuntime(231): at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:648)
11-04 17:13:27.382: ERROR/AndroidRuntime(231): at android.widget.TabHost.setCurrentTab(TabHost.java:320)
11-04 17:13:27.382: ERROR/AndroidRuntime(231): at android.widget.TabHost$2.onTabSelectionChanged(TabHost.java:129)
11-04 17:13:27.382: ERROR/AndroidRuntime(231): at android.widget.TabWidget$TabClickListener.onClick(TabWidget.java:379)
11-04 17:13:27.382: ERROR/AndroidRuntime(231): at android.view.View.performClick(View.java:2364)
11-04 17:13:27.382: ERROR/AndroidRuntime(231): at android.view.View.onTouchEvent(View.java:4179)
11-04 17:13:27.382: ERROR/AndroidRuntime(231): at android.view.View.dispatchTouchEvent(View.java:3709)
11-04 17:13:27.382: ERROR/AndroidRuntime(231): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:852)
11-04 17:13:27.382: ERROR/AndroidRuntime(231): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
11-04 17:13:27.382: ERROR/AndroidRuntime(231): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
11-04 17:13:27.382: ERROR/AndroidRuntime(231): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
11-04 17:13:27.382: ERROR/AndroidRuntime(231): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
11-04 17:13:27.382: ERROR/AndroidRuntime(231): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
11-04 17:13:27.382: ERROR/AndroidRuntime(231): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
11-04 17:13:27.382: ERROR/AndroidRuntime(231): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
11-04 17:13:27.382: ERROR/AndroidRuntime(231): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659)
11-04 17:13:27.382: ERROR/AndroidRuntime(231): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)
11-04 17:13:27.382: ERROR/AndroidRuntime(231): at android.app.Activity.dispatchTouchEvent(Activity.java:2061)
11-04 17:13:27.382: ERROR/AndroidRuntime(231): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)
11-04 17:13:27.382: ERROR/AndroidRuntime(231): at android.view.ViewRoot.handleMessage(ViewRoot.java:1691)
11-04 17:13:27.382: ERROR/AndroidRuntime(231): at android.os.Handler.dispatchMessage(Handler.java:99)
11-04 17:13:27.382: ERROR/AndroidRuntime(231): at android.os.Looper.loop(Looper.java:123)
11-04 17:13:27.382: ERROR/AndroidRuntime(231): at android.app.ActivityThread.main(ActivityThread.java:4363)
11-04 17:13:27.382: ERROR/AndroidRuntime(231): at java.lang.reflect.Method.invokeNative(Native Method)
11-04 17:13:27.382: ERROR/AndroidRuntime(231): at java.lang.reflect.Method.invoke(Method.java:521)
11-04 17:13:27.382: ERROR/AndroidRuntime(231): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
11-04 17:13:27.382: ERROR/AndroidRuntime(231): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
11-04 17:13:27.382: ERROR/AndroidRuntime(231): at dalvik.system.NativeStart.main(Native Method)
11-04 17:13:27.382: ERROR/AndroidRuntime(231): Caused by: com.sun.jersey.api.client.ClientHandlerException: java.net.SocketException: The operation timed out
11-04 17:13:27.382: ERROR/AndroidRuntime(231): at com.sun.jersey.client.urlconnection.URLConnectionClientHandler.handle(URLConnectionClientHandler.java:131)
11-04 17:13:27.382: ERROR/AndroidRuntime(231): at com.sun.jersey.api.client.Client.handle(Client.java:616)
11-04 17:13:27.382: ERROR/AndroidRuntime(231): at com.sun.jersey.api.client.WebResource.handle(WebResource.java:559)
11-04 17:13:27.382: ERROR/AndroidRuntime(231): at com.sun.jersey.api.client.WebResource.get(WebResource.java:182)
11-04 17:13:27.382: ERROR/AndroidRuntime(231): at com.example.tablayout.MyLogin.onCreate(MyLogin.java:94)
11-04 17:13:27.382: ERROR/AndroidRuntime(231): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
11-04 17:13:27.382: ERROR/AndroidRuntime(231): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
11-04 17:13:27.382: ERROR/AndroidRuntime(231): ... 31 more
11-04 17:13:27.382: ERROR/AndroidRuntime(231): Caused by: java.net.SocketException: The operation timed out
11-04 17:13:27.382: ERROR/AndroidRuntime(231): at org.apache.harmony.luni.platform.OSNetworkSystem.connectSocketImpl(Native Method)
11-04 17:13:27.382: ERROR/AndroidRuntime(231): at org.apache.harmony.luni.platform.OSNetworkSystem.connect(OSNetworkSystem.java:114)
11-04 17:13:27.382: ERROR/AndroidRuntime(231): at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:245)
11-04 17:13:27.382: ERROR/AndroidRuntime(231): at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:535)
11-04 17:13:27.382: ERROR/AndroidRuntime(231): at java.net.Socket.connect(Socket.java:1054)
11-04 17:13:27.382: ERROR/AndroidRuntime(231): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java:62)
11-04 17:13:27.382: ERROR/AndroidRuntime(231): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnectionManager$ConnectionPool.getHttpConnection(HttpConnectionManager.java:145)
11-04 17:13:27.382: ERROR/AndroidRuntime(231): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnectionManager.getConnection(HttpConnectionManager.java:67)
11-04 17:13:27.382: ERROR/AndroidRuntime(231): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection.getHTTPConnection(HttpURLConnection.java:821)
11-04 17:13:27.382: ERROR/AndroidRuntime(231): at org.apache.harmony.luni.internal.net.www.protocol.ht
Я использую целевой GoogleAPI 7 и следующие банки:
джерси-пачка 1.4.jar
jsr311-апи-1.1.jar
JUnit-4.5.jar
Есть ли у anybode идеи, чтобы это исправить?
Поздравления
Кристин Бауэрс