0

私たちのアプリケーションは、Java/Spring3/Spring MVC/Hibernate ベースのアプリです。

サーバーマシンのさまざまな場所に保存されているリソースがいくつかあります。場所はデータベースに保存されます。基本的に、/<our-app>/page/file.kmlこの呼び出しをインターセプトする必要がある場合のように、Web アプリケーションが uri からファイルを要求する場合、要求された uri を無視し、ファイルの実際の場所を検索して、それを応答として返します。

私たちservlet-context.xmlにはいくつかのインターセプターがあります。

<interceptors>
    <interceptor>
        <mapping path="/page/**" />
        <beans:bean class="com.ourapp.AuthenticationInterceptor" />
    </interceptor>
    <interceptor>
        <mapping path="/page/*.kml" />
        <beans:bean class="com.ourapp.KmlInterceptor" />
    </interceptor>
</interceptors>

最初のインターセプトは認証用で、うまく機能します。基本的に、ユーザーがすべてのリクエストに対してログインしていることを確認します。

2 番目のインターセプターは、geoXML3 から KML ファイルへのリクエストをインターセプトしようとするためにセットアップしたものです。インターセプターが発砲していないようですか?(つまり、KmlInterceptor.preHandle は呼び出されませんか?)。

そこで正しいマッピングを行っていますか?

これは、特定のファイル タイプの要求を傍受し、別の場所から取得した実際のファイルを返す方法ですか?

4

1 に答える 1

0

実際には、インターセプターの使用をやめ、@RequestMapping代わりに通常のアノテーションを使用しました。

@RequestMapping(value = "/page/location/*.kml", method = RequestMethod.GET)
public void getKMLFile(HttpServletRequest httpRequest, HttpServletResponse httpResponse) {
    try {
        // Getting the filename (ie splitting off the /page/location/ part)
        String uri = httpRequest.getRequestURI();
        String[] parts = uri.split("/");
        String alais = parts[parts.length - 1];

        // Our app specific code finding the file from the db location 
        Resource resource = resourceService.getResourceByAlias(alais);
        File file = resource.getAbsFile();

        // Putting the file onto the httpResponse 
        InputStream is = new FileInputStream(file);
        IOUtils.copy(is, httpResponse.getOutputStream());
        httpResponse.flushBuffer();

    } catch (IOException e) {
        throw new RuntimeException("IOError writing file to output stream");
    }
}
于 2013-02-28T17:34:45.873 に答える