2012-03-16 80 views
3

我們的目標是通過使用Java的SOAP服務從Liferay Portal獲取一些內容。我們正在使用JournalArticleServiceSoap成功加載文章。問題是該方法需要組ID和條目ID,我們想要的是從特定組中獲取所有文章。因此,我們首先嚐試使用AssetEntryServiceSoap獲取ID,但它失敗。Liferay門戶獲取文章

AssetEntryServiceSoapServiceLocator aesssLocator = new AssetEntryServiceSoapServiceLocator(); 
    com.liferay.client.soap.portlet.asset.service.http.AssetEntryServiceSoap assetEntryServiceSoap = null; 

    URL url = null; 
    try { 
     url = new URL(
       "http://127.0.0.1:8080/tunnel-web/secure/axis/Portlet_Asset_AssetEntryService"); 
    } catch (MalformedURLException e) { 
     e.printStackTrace(); 
    } 

    try { 
     assetEntryServiceSoap = aesssLocator 
       .getPortlet_Asset_AssetEntryService(url); 
    } catch (ServiceException e) { 
     e.printStackTrace(); 
    } 
    if (assetEntryServiceSoap == null) { 
     return; 
    } 

    Portlet_Asset_AssetEntryServiceSoapBindingStub assetEntryServiceSoapBindingStub = (Portlet_Asset_AssetEntryServiceSoapBindingStub) assetEntryServiceSoap; 
    assetEntryServiceSoapBindingStub.setUsername("[email protected]"); 
    assetEntryServiceSoapBindingStub.setPassword("bruno"); 

    AssetEntrySoap[] entries; 
    AssetEntryQuery query = new AssetEntryQuery(); 

    try { 
     int count = assetEntryServiceSoap.getEntriesCount(query); 
     System.out.println("Entries count: " + Integer.toString(count)); 
     entries = assetEntryServiceSoap.getEntries(query); 
     if (entries != null) { 
      System.out.println(Integer.toString(entries.length)); 
     } 
     for (AssetEntrySoap aes : assetEntryServiceSoap.getEntries(query)) { 
      System.out.println(aes.getEntryId()); 
     } 
    } catch (RemoteException e1) { 
     e1.printStackTrace(); 
    } 

雖然getEntriesCount()返回像83這樣的正值,但getEnries()總是返回一個空數組。我對Liferay門戶很陌生,但對我來說看起來很奇怪。

順便說一句,我們顯然不是在這裏尋找性能,關鍵只是從門戶遠程獲取一些特定的內容。如果你知道任何工作解決方案,你的幫助將不勝感激。

+0

嗨,我追溯了代碼,發現通過發送AssetEntryQuery()的普通對象,您可能沒有準確的查詢。看看com.liferay.portlet.asset.service.persistence.AssetEntryFinderImpl的方法findEntries(AssetEntryQuery entryQuery)條目 – 2012-06-06 13:17:06

回答

0

正常情況下,AssetEntryQuery將不得不多一點信息,例如:

AssetEntryQuery assetEntryQuery = new AssetEntryQuery(); 
assetEntryQuery.setClassNameIds(new long[] { ClassNameLocalServiceUtil.getClassNameId("com.liferay.portlet.journal.model.JournalArticle") }); 
assetEntryQuery.setGroupIds(new long[] { groupId }); 

所以這將返回爲您的groupId指定所有AssetEntries,這也是JournalArticles。

試試這個,看看,雖然如你所說,Count方法返回一個正數,所以它可能沒有什麼差別,但給它一個去! :)