无法从webservice连接到mongodb

时间:2014-09-24 20:29:39

标签: java android web-services mongodb tomcat

我创建了一个Android应用程序,它将SOAP请求发送到我的Tomcat Web服务器。 Web服务器有一个Web服务(MongoService.wsdl),它调用另一个类(DataLayer.java),它有一个静态方法(getConnection),试图初始化MongClient类(新的MongoClient),但失败并没有抛出异常。< / p>

当我从java应用程序运行此函数时,它可以正常工作。

方法:

/**Utility to Get the Connection from the database*/
    public static DBCollection getConnection(String dbName, String collectionName)throws UnknownHostException {

        MongoClient mongo = null;
        try {
            mongo = new MongoClient( "localhost" , 27017 );
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
            /**Gets database, incase if the database is not existing
                 MongoDB Creates it for you*/
            DB db = mongo.getDB(dbName);

            /**Gets collection / table from database specified if
                 collection doesn't exists, MongoDB will create it for
                 you*/
            DBCollection table = db.getCollection(collectionName);
            return table;
        }

logcat的:

  

09-24 23:23:14.223:W / System.err(18551):SoapFault - faultcode:   'soapenv:Server.userException'faultstring:   'java.lang.reflect.InvocationTargetException'faultactor:'null'   详情:org.kxml2.kdom.Node@42d023c8 09-24 23:23:14.223:   W / System.err(18551):at   org.ksoap2.serialization.SoapSerializationEnvelope.parseBody(SoapSerializationEnvelope.java:112)   09-24 23:23:14.223:W / System.err(18551):at   org.ksoap2.SoapEnvelope.parse(SoapEnvelope.java:137)09-24   23:23:14.223:W / System.err(18551):at   org.ksoap2.transport.Transport.parseResponse(Transport.java:63)09-24   23:23:14.223:W / System.err(18551):at   org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:100)   09-24 23:23:14.223:W / System.err(18551):at   com.example.myfirstapp.WebService.invokeHelloWorldWS(WebService.java:51)   09-24 23:23:14.223:W / System.err(18551):at   com.example.myfirstapp.MainActivity $ AsyncCallWS.doInBackground(MainActivity.java:251)   09-24 23:23:14.223:W / System.err(18551):at   com.example.myfirstapp.MainActivity $ AsyncCallWS.doInBackground(MainActivity.java:1)   09-24 23:23:14.223:W / System.err(18551):at   android.os.AsyncTask $ 2.call(AsyncTask.java:288)09-24 23:23:14.223:   W / System.err(18551):at   java.util.concurrent.FutureTask.run(FutureTask.java:237)09-24   23:23:14.223:W / System.err(18551):at   android.os.AsyncTask $ SerialExecutor $ 1.run(AsyncTask.java:231)09-24   23:23:14.223:W / System.err(18551):at   java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)   09-24 23:23:14.223:W / System.err(18551):at   java.util.concurrent.ThreadPoolExecutor中的$ Worker.run(ThreadPoolExecutor.java:587)   09-24 23:23:14.223:W / System.err(18551):at   java.lang.Thread.run(Thread.java:841)09-24 23:23:14.233:   I / dalvikvm(18551):Jit:将JitTable从4096调整到8192 09-24   23:23:55.967:D / dalvikvm(18551):GC_FOR_ALLOC释放3538K,19%免费   16265K / 20064K,暂停49ms,总计49ms

1 个答案:

答案 0 :(得分:0)

我解决了这个问题,将mongo-driver.jar添加到WEB-INF / lib文件夹中。如果使用eclipse和maven,可以解决将maven依赖项添加到&#34;部署程序集&#34;在项目属性中。