2017-01-30 6 views
0

私はいくつかの異なるリソースタイプをキャッシュするJWSアプリケーションを持っています。しかし、私は.svgイメージをキャッシュしたくありません。フレームワークは、私が設定したサーバー側のキャッシュ制御HTTPヘッダーを尊重していないようです。アプリケーションサーバー上の.svgイメージのキャッシュを防止します。

キャッシングせずに.svgイメージを読み込むことができる他の方法があるかどうか疑問に思っていました。 loadSVGDocument()メソッドで解決策を公開していますが、私のコードは現在.svgファイルをロードするためのApache Batikを中心に構築されています。どのようなDocumentBuilderFactoryが提供するのと同様のBatikライブラリ内のnoCacheフラグを持つInputStreamを渡すソリューションはありますか?私はsetUseCachesとバティックの

DocumentLoader.loadDocument(URL url, InputStream is)

を呼び出すことができることを発見し、興味がある人々のために

public void loadSVGDocument(final String url) 
{ 
    System.out.println("THE SVG URL: " + url); 
    String oldURI = null; 
    if (svgDocument != null) 
    { 
     oldURI = svgDocument.getURL(); 
    } 

    final ParsedURL newURI = new ParsedURL(oldURI, url); 
    String theUrl = newURI.toString(); 
    fragmentIdentifier = newURI.getRef(); 

    loader = new DocumentLoader(userAgent); 
    nextDocumentLoader = new SVGDocumentLoader(theUrl, loader); 
    nextDocumentLoader.setPriority(Thread.NORM_PRIORITY); 

    Iterator it = svgDocumentLoaderListeners.iterator(); 
    while (it.hasNext()) 
    { 
     nextDocumentLoader 
      .addSVGDocumentLoaderListener((SVGDocumentLoaderListener) it.next()); 
    } 

    documentLoader = nextDocumentLoader; 
    nextDocumentLoader = null; 
    documentLoader.run(); 
} 

答えて

0

URL url = new URL(fileLocation); 
URLConnection connection = url.openConnection(); 
// Prevent JavaWebStart from returning cached copy. 
connection.setUseCaches(false); 

// Now fetch the content, e.g. 
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); 
DocumentBuilder db = dbf.newDocumentBuilder(); 
Document doc = db.parse(connection.getInputStream()); 

は、ここでいくつかのApacheのバティックフィールドを使用して私の現在のloadSVGDocument()方法であり、フラグをfalseに設定します。これは画像をロードするだけでなく、それに従ってキャッシュからも削除します。 JWSがHTTPヘッダーを尊重するのがいいという意味では最良の解決策ではありませんが、この回避策は十分です。

関連する問題