2011-12-01 97 views
2

打開輸入流,我設計使用iReport的碧玉報告,從給定的URL需要一個參數,獲取的圖像:碧玉:錯誤的URL

的參數是在Twitter上用戶的網名和網址它是個人資料圖片。

<image> 
     <reportElement x="4" y="51" width="73" height="64"/> 
      <imageExpression><![CDATA["https://api.twitter.com/1/users/profile_image?screen_name="+$F{user_screen_name}+"&size=bigger"]]></imageExpression> 
    </image> 

它在圖像存在時效果很好。如果它不拋出以下異常:

Error filling print... net.sf.jasperreports.engine.JRException: Error opening input stream from URL : 
    https://api.twitter.com/1/users/profile_image?screen_name=CPTCurtisHervey&size=bigger 
    Setting up the file resolver... net.sf.jasperreports.engine.JRRuntimeException: 
    net.sf.jasperreports.engine.JRException: Error opening input stream from URL : 
    https://api.twitter.com/1/users/profile_image?screen_name=CPTCurtisHervey&size=bigger 
    at net.sf.jasperreports.repo.DefaultRepositoryService.getInputStream(DefaultRepositoryService.java:138) 
    at net.sf.jasperreports.repo.RepositoryUtil.findInputStream(RepositoryUtil.java:186)  
    at net.sf.jasperreports.repo.RepositoryUtil.getBytes(RepositoryUtil.java:202) 
    at net.sf.jasperreports.engine.JRImageRenderer.getInstance(JRImageRenderer.java:141)  
    at net.sf.jasperreports.engine.fill.JRFillImage.evaluateImage(JRFillImage.java:498) 
    at net.sf.jasperreports.engine.fill.JRFillImage.evaluate(JRFillImage.java:441) 
    at net.sf.jasperreports.engine.fill.JRFillElementContainer.evaluate(JRFillElementContainer.java:257) 
    at net.sf.jasperreports.engine.fill.JRFillBand.evaluate(JRFillBand.java:468) 
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillColumnBand(JRVerticalFiller.java:2037)  
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillDetail(JRVerticalFiller.java:761)  
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReportContent(JRVerticalFiller.java:291) 
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:133)  
    at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:903) 
    at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:813) 
    at net.sf.jasperreports.engine.fill.JRFiller.fillReport(JRFiller.java:58) 
    at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:417) 
    at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:247) 
    at com.jaspersoft.ireport.designer.compiler.IReportCompiler.run(IReportCompiler.java:878) 
    at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:572) 
    at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:997) Caused by: 
    net.sf.jasperreports.engine.JRException: Error opening input stream from URL : 
    https://api.twitter.com/1/users/profile_image?screen_name=CPTCurtisHervey&size=bigger  
    at net.sf.jasperreports.engine.util.JRLoader.getInputStream(JRLoader.java:314) 
    at net.sf.jasperreports.repo.DefaultRepositoryService.getInputStream(DefaultRepositoryService.java:121) 
    ... 19 more Caused by: java.io.FileNotFoundException: 
    https://api.twitter.com/1/users/profile_image?screen_name=CPTCurtisHervey&size=bigger  
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1401)  
    at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:254) 
    at java.net.URL.openStream(URL.java:1029)  
    at net.sf.jasperreports.engine.util.JRLoader.getInputStream(JRLoader.java:310)... 20 more 
    Print not filled. Try to use an EmptyDataSource... 

我該如何處理jrxml文件中的這種情況?

我想簡單地添加一個固定的URL地址,以防萬一找不到。

任何人有什麼建議嗎?

謝謝!

回答

2

我認爲你需要添加一個輔助類來處理這個問題。你需要一個靜態方法boolean urlExists(String url),它會讓你把這個在imageExpression:

MyClass.urlExists($F{image_url}) ? $F{image_url} : $P{fallback_image} 

這將是一個簡單的類來寫......但顯然在另一個.jar文件增加的額外的複雜性。如果沒有這種方法,我看不到在.jrxml中進行處理的任何方法。

在JRXML文件
+0

謝謝! 幫了很多! – Etay

0

, 以顯示URL資源,利用圖像表達URL()

像下面的圖片,例如$F{ADPN_NO}是從報表參數

<imageExpression><![CDATA[new URL("http://anyserver:7001/images/"+$F{ADPN_NO}+".jpg")]]></imageExpression> 

onError發生,它會顯示空白項,圖標或在jrxml上設置的錯誤。

的其他方式,JRXML文件外,你可以使用Java地圖對象包含IMG的網址是URL()File() Exception檢查..

0

在我來說,我有一個報告,說明我「注入」了圖像的網址,它是導致證書錯誤(我注射的網址是IP,它必須是證書的名稱)。我改變了它的網址後,