2014-09-24 92 views
1

我創建了一個將SOAP請求發送到我的Tomcat Web服務器的Android應用程序。 Web服務器有一個調用另一個類(DataLayer.java)的Web服務(MongoService.wsdl),該類有一個嘗試初始化MongClient類(新的MongoClient)的靜態方法(getConnection),但失敗時不會拋出異常。無法從webservice連接到mongodb

當我從一個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:服務器。 W or System.err(18551):userException'faultstring: 'java.lang.reflect.InvocationTargetException'faultactor:'null' detail:[email protected] 09-24 23:23:14.223: W/System.err在 org.ksoap2.serialization.SoapSerializationEnvelope.p arseBody(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。運行(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) ):日新:從4096調整JitTable到8192 09-24 23:23:55.967:d/dalvikvm(18551):GC_FOR_ALLOC釋放3538K,19%的遊離 16265K/20064K,暫停49ms,共49ms

回答

0

我解決了這個問題,將mongo-driver.jar添加到WEB-INF/lib文件夾中。如果使用eclipse和maven,可以通過在項目屬性中添加Maven依賴關係到「部署程序集」來解決。