连接拒绝我的WildFly服务器与resteasy

时间:2017-01-12 17:23:14

标签: java android wildfly resteasy

我将我的Android应用程序与我的WildFly 10x服务器连接有点问题,我搜索了一段时间,但没有解决方案来解决我的问题。 请注意我使用以下IP: 我的Localhost-Address:http://127.0.0.1:8080/(在此运行我的服务器) 我的本地IP地址 和我Mac上的IP地址

如果我立即使用Mac上的IP-Adress和应用崩溃的本地主机,但如果我使用本地IP地址,应用程序崩溃几次。

首先是我的WildFly服务器代码:

我的CrudAccessor

    @Path("/todos")
@Consumes({ "application/json" })
@Produces({ "application/json" })
public interface TodoModelCrudAccessor {

    @GET
    @Produces({ "application/json" })
    public ArrayList<TodoModel> readAllTodos();

    @POST
    public TodoModel createTodo(TodoModel todo);

    @DELETE
    @Path("/{todoId}")
    public boolean deleteTodo(@PathParam("todoId") Integer todoId);

    @PUT
    public TodoModel updateTodo(TodoModel todo);

    @POST
    @Path("/login")
    public  boolean checkLoginData(Login loginData);

我只实现了readAllTodos函数来测试服务器

@Override
    public ArrayList<TodoModel> readAllTodos() {
        todolist.add(new TodoModel(1, "Ernie", "MeineBeschreibung", 0, 0, 0, 123));
        todolist.add(new TodoModel(2, "Bert", "sdfg", 1, 1,0 , 123124));
        return todolist;    
    }

我的RestService

@ApplicationPath(value="/rest/*")
public class RemoteDataAccessRESTService extends javax.ws.rs.core.Application {

    protected static Logger logger = Logger.getLogger(RemoteDataAccessRESTService.class);

    public RemoteDataAccessRESTService() {
        logger.info("<Constructor>()");
    }

}

我的Android应用程序:

ServerRemoteAccessor接口

    @Path("/todos")
@Consumes({ "application/json" })
@Produces({"application/json"})
public interface IServerRemoteAccessor {


    @GET
    @Produces({"application/json"})
    public ArrayList<TodoModel> readAllTodos();

    @POST
    public TodoModel createTodo(TodoModel todo);

    @DELETE
    @Path("/{todoId}")
    public boolean deleteTodo(@PathParam("todoId") long itemId);

    @PUT
    public TodoModel updateTodo(TodoModel todo);
}

ServerRemoteAccessor Class

public class ServerRemoteAccessor implements IServerRemoteAccessor {

    private static final String LOG_TAG = ServerRemoteAccessor.class.getName();
    private IServerRemoteAccessor client;
    private String baseURL;
    private BasicHttpParams params;

    public ServerRemoteAccessor(String baseURL){
        if (baseURL != null) {
            this.baseURL = baseURL;

            params = new BasicHttpParams();
            HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
            HttpProtocolParams.setContentCharset(params, HTTP.DEFAULT_CONTENT_CHARSET);
            HttpProtocolParams.setUseExpectContinue(params, false);
            this.client = ProxyFactory.create(IServerRemoteAccessor.class, baseURL, new ApacheHttpClient4Executor());

        }
      //  createClient();
    }

    public IServerRemoteAccessor createClient(){
        this.client = ProxyFactory.create(IServerRemoteAccessor.class, baseURL, new ApacheHttpClient4Executor());
        return  client;
    }
    //Implementierung der CRUD-Operationen
    @Override
    public ArrayList<TodoModel> readAllTodos(){
        Log.i(LOG_TAG, "readAllTodos");

        ArrayList<TodoModel> todoList = client.readAllTodos();

        Log.i(LOG_TAG, "readAllTodos: " + todoList);
        return todoList;
    }

这就是我连接到我的服务器并希望阅读所有待办事项的方式

        try {
        serverRemoteAccessor = new ServerRemoteAccessor("http://192.168.188.82:8080/DataAccessRemoteWebapp/rest");


        new AsyncTask<Void, Void, ArrayList<TodoModel>>() {
            @Override
            protected ArrayList<TodoModel> doInBackground(Void... voids) {
                return serverRemoteAccessor.readAllTodos();
            }

            @Override
            protected void onPostExecute(ArrayList<TodoModel> todoModels) {
                todoList.addAll(todoModels);
            }
        }.execute();
    } catch (Exception e){
        Log.e(LOG_TAG, "Error: " + e);
    }

这是我的错误讯息:

01-12 18:06:15.951 11857-11926/de.app.malchemie.wunderlist E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1
                                                                         Process: de.app.malchemie.wunderlist, PID: 11857
                                                                         java.lang.RuntimeException: An error occurred while executing doInBackground()
                                                                             at android.os.AsyncTask$3.done(AsyncTask.java:309)
                                                                             at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
                                                                             at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
                                                                             at java.util.concurrent.FutureTask.run(FutureTask.java:242)
                                                                             at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
                                                                             at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
                                                                             at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
                                                                             at java.lang.Thread.run(Thread.java:818)
                                                                          Caused by: java.lang.RuntimeException: org.apache.http.conn.HttpHostConnectException: Connection to http://192.168.188.82:8080 refused
                                                                             at org.jboss.resteasy.client.core.ClientInvoker.invoke(ClientInvoker.java:108)
                                                                             at org.jboss.resteasy.client.core.ClientProxy.invoke(ClientProxy.java:72)
                                                                             at java.lang.reflect.Proxy.invoke(Proxy.java:393)
                                                                             at $Proxy10.readAllTodos(Unknown Source)
                                                                             at de.app.malchemie.wunderlist.serveraccess.ServerRemoteAccessor.readAllTodos(ServerRemoteAccessor.java:50)
                                                                             at de.app.malchemie.wunderlist.activities.LoginActivity$1.doInBackground(LoginActivity.java:50)
                                                                             at de.app.malchemie.wunderlist.activities.LoginActivity$1.doInBackground(LoginActivity.java:47)
                                                                             at android.os.AsyncTask$2.call(AsyncTask.java:295)
                                                                             at java.util.concurrent.FutureTask.run(FutureTask.java:237)
                                                                             at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234) 
                                                                             at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) 
                                                                             at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588) 
                                                                             at java.lang.Thread.run(Thread.java:818) 
                                                                          Caused by: org.apache.http.conn.HttpHostConnectException: Connection to http://192.168.188.82:8080 refused
                                                                             at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:193)
                                                                             at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:169)
                                                                             at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:124)
                                                                             at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:366)
                                                                             at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:560)
                                                                             at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:492)
                                                                             at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:470)
                                                                             at org.jboss.resteasy.client.core.executors.ApacheHttpClient4Executor.execute(ApacheHttpClient4Executor.java:94)
                                                                             at org.jboss.resteasy.client.ClientRequest.execute(ClientRequest.java:467)
                                                                             at org.jboss.resteasy.client.ClientRequest.httpMethod(ClientRequest.java:704)
                                                                             at org.jboss.resteasy.client.core.ClientInvoker.invoke(ClientInvoker.java:104)
                                                                             at org.jboss.resteasy.client.core.ClientProxy.invoke(ClientProxy.java:72) 
                                                                             at java.lang.reflect.Proxy.invoke(Proxy.java:393) 
                                                                             at $Proxy10.readAllTodos(Unknown Source) 
                                                                             at de.app.malchemie.wunderlist.serveraccess.ServerRemoteAccessor.readAllTodos(ServerRemoteAccessor.java:50) 
                                                                             at de.app.malchemie.wunderlist.activities.LoginActivity$1.doInBackground(LoginActivity.java:50) 
                                                                             at de.app.malchemie.wunderlist.activities.LoginActivity$1.doInBackground(LoginActivity.java:47) 
                                                                             at android.os.AsyncTask$2.call(AsyncTask.java:295) 
                                                                             at java.util.concurrent.FutureTask.run(FutureTask.java:237) 
                                                                             at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234) 
                                                                             at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) 
                                                                             at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588) 
                                                                             at java.lang.Thread.run(Thread.java:818) 
                                                                          Caused by: java.net.ConnectException: failed to connect to /192.168.188.82 (port 8080): connect failed: ECONNREFUSED (Connection refused)
                                                                             at libcore.io.IoBridge.connect(IoBridge.java:124)
                                                                             at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:183)
                                                                             at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:452)
                                                                             at java.net.Socket.connect(Socket.java:884)
                                                                             at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:124)
                                                                             at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:149)
                                                                             at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:169) 
                                                                             at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:124) 
                                                                             at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:366) 
                                                                             at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:560) 
                                                                             at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:492) 
                                                                             at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:470) 
                                                                             at org.jboss.resteasy.client.core.executors.ApacheHttpClient4Executor.execute(ApacheHttpClient4Executor.java:94) 
                                                                             at org.jboss.resteasy.client.ClientRequest.execute(ClientRequest.java:467) 
                                                                             at org.jboss.resteasy.client.ClientRequest.httpMethod(ClientRequest.java:704) 
                                                                             at org.jboss.resteasy.client.core.ClientInvoker.invoke(ClientInvoker.java:104) 
                                                                             at org.jboss.resteasy.client.core.ClientProxy.invoke(ClientProxy.java:72) 
                                                                             at java.lang.reflect.Proxy.invoke(Proxy.java:393) 
                                                                             at $Proxy10.readAllTodos(Unknown Source) 
                                                                             at de.app.malchemie.wunderlist.serveraccess.ServerRemoteAccessor.readAllTodos(ServerRemoteAccessor.java:50) 
                                                                             at de.app.malchemie.wunderlist.activities.LoginActivity$1.doInBackground(LoginActivity.java:50) 
                                                                             at de.app.malchemie.wunderlist.activities.LoginActivity$1.doInBackground(LoginActivity.java:47) 
                                                                             at android.os.AsyncTask$2.call(AsyncTask.java:295) 
                                                                             at java.util.concurrent.FutureTask.run(FutureTask.java:237) 
                                                                             at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234) 
                                                                             at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) 
                                                                             at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588) 
                                                                             at java.lang.Thread.run(Thread.java:818) 
                                                                          Caused by: android.system.ErrnoException: connect failed: ECONNREFUSED (Connection refused)
                                                                             at libcore.io.Posix.connect(Native Method)
                                                                             at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:111)
                                                                             at libcore.io.IoBridge.connectErrno(IoBridge.java:137)
                                                                             at libcore.io.IoBridge.connect(IoBridge.java:122)
                                                                             at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:183) 
                                                                             at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:452) 
                                                                             at java.net.Socket.connect(Socket.java:884) 
                                                                             at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:124) 
                                                                             at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:149) 
                                                                             at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:169) 
                                                                             at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:124) 
                                                                             at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:366) 
                                                                             at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:560) 
                                                                             at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:492) 
                                                                             at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:470) 
                                                                             at org.jboss.resteasy.client.core.executors.ApacheHttpClient4Executor.execute(ApacheHttpClient4Executor.java:94) 
                                                                             at org.jboss.resteasy.client.ClientRequest.execute(ClientRequest.java:467) 
                                                                             at org.jboss.resteasy.client.ClientRequest.httpMethod(ClientRequest.java:704) 
                                                                             at org.jboss.resteasy.client.core.ClientInvoker.invoke(ClientInvoker.java:104) 
                                                                             at org.jboss.resteasy.client.core.ClientProxy.invoke(ClientProxy.java:72) 
                                                                             at java.lang.reflect.Proxy.invoke(Proxy.java:393) 
                                                                             at $Proxy10.readAllTodos(Unknown Source) 
                                                                             at de.app.malchemie.wunderlist.serveraccess.ServerRemoteAccessor.readAllTodos(ServerRemoteAccessor.java:50) 
                                                                             at de.app.malchemie.wunderlist.activities.LoginActivity$1.doInBackground(LoginActivity.java:50) 
                                                                             at de.app.malchemie.wunderlist.activities.LoginActivity$1.doInBackground(LoginActivity.java:47) 
                                                                             at android.os.AsyncTask$2.call(AsyncTask.java:295) 
                                                                             at java.util.concurrent.FutureTask.run(FutureTask.java:237) 
                                                                             at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234) 
                                                                             at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) 
                                                                             at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588) 
                                                                             at java.lang.Thread.run(Thread.java:818) 

0 个答案:

没有答案