2012-11-27 21 views
0

我想在基於Spring框架的WEB應用程序中使用Openlayer。我需要在tomcat上使用cgi代理。我按照這裏的指示installing-a-cgi-on-tomcat。它適用於一個簡單的Web應用程序。但是當我試圖用Spring MVC實現它時,我遇到了訪問cgi文件的問題。我收到了警告信息。如何訪問Spring MVC中的proxy.cgi文件

WARN org.springframework.web.servlet.PageNotFound:962 - No mapping found for HTTP request with URI [/pcms/app/cgi-bin/proxy.cgi] in DispatcherServlet with name 'Spring MVC Dispatcher Servlet' 

我嘗試過很多辦法,但我並沒有弄清楚如何訪問WEB-INF \ CGI目錄下的文件proxy.cgi。請幫忙。謝謝。 附加的是web.xml的內容。

<?xml version="1.0" encoding="UTF-8"?> 
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> 
    <display-name>Property &amp; Configuration Management System</display-name> 
    <context-param> 
    <param-name>webAppRootKey</param-name> 
    <param-value>pcms.root</param-value> 
    </context-param> 
    <context-param> 
    <param-name>log4jConfigLocation</param-name> 
    <param-value>/WEB-INF/log4j.properties</param-value> 
    </context-param> 
    <listener> 
    <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class> 
    </listener> 
    <listener> 
    <listener-class> 
      org.springframework.web.context.ContextLoaderListener 
     </listener-class> 
    </listener> 
    <listener> 
    <listener-class>com.pb.redline.listener.MTAServletContextListener</listener-class> 
    </listener> 
    <context-param> 
    <param-name>contextConfigLocation</param-name> 
    <param-value> 
      /WEB-INF/spring/web-application-context.xml 
     </param-value> 
    </context-param> 
    <filter> 
    <filter-name>openEntityManagerInViewFilter</filter-name> 
    <filter-class>org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter</filter-class> 
    </filter> 
    <filter-mapping> 
    <filter-name>openEntityManagerInViewFilter</filter-name> 
    <url-pattern>/*</url-pattern> 
    </filter-mapping> 
    <filter> 
    <filter-name>springSecurityFilterChain</filter-name> 
    <filter-class> 
      org.springframework.web.filter.DelegatingFilterProxy 
     </filter-class> 
    </filter> 
    <filter-mapping> 
    <filter-name>springSecurityFilterChain</filter-name> 
    <url-pattern>/*</url-pattern> 
    </filter-mapping> 
    <filter> 
    <filter-name>encoding-filter</filter-name> 
    <filter-class> 
      org.springframework.web.filter.CharacterEncodingFilter 
     </filter-class> 
    <init-param> 
     <param-name>encoding</param-name> 
     <param-value>UTF-8</param-value> 
    </init-param> 
    </filter> 
    <filter-mapping> 
    <filter-name>encoding-filter</filter-name> 
    <url-pattern>/*</url-pattern> 
    </filter-mapping> 
    <filter> 
    <filter-name>UrlRewriteFilter</filter-name> 
    <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class> 
    </filter> 
    <filter-mapping> 
    <filter-name>UrlRewriteFilter</filter-name> 
    <url-pattern>/*</url-pattern> 
    </filter-mapping> 
    <servlet> 
    <servlet-name>Spring MVC Dispatcher Servlet</servlet-name> 
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
    <init-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value> 
      </param-value> 
    </init-param> 
    <load-on-startup>1</load-on-startup> 
    </servlet> 
    <servlet-mapping> 
    <servlet-name>Spring MVC Dispatcher Servlet</servlet-name> 
    <url-pattern>/app/*</url-pattern> 
    </servlet-mapping> 

    <!-- proxy.cgi for openlayers --> 
    <servlet> 
     <servlet-name>cgi</servlet-name> 
     <servlet-class>org.apache.catalina.servlets.CGIServlet</servlet-class> 
     <init-param> 
      <param-name>debug</param-name> 
      <param-value>0</param-value> 
     </init-param> 
     <init-param> 
      <param-name>cgiPathPrefix</param-name> 
      <param-value>WEB-INF/cgi</param-value> 
     </init-param> 
     <init-param> 
      <param-name>executable</param-name> 
      <param-value>C:/Python26/ArcGIS10.0/python.exe</param-value> 
     </init-param> 
     <init-param> 
      <param-name>passShellEnvironment</param-name> 
      <param-value>true</param-value> 
     </init-param> 
     <load-on-startup>5</load-on-startup> 
    </servlet> 
     <servlet-mapping> 
      <servlet-name>default</servlet-name> 
      <url-pattern>/</url-pattern> 
    </servlet-mapping> 
    <servlet-mapping> 
      <servlet-name>cgi</servlet-name> 
      <url-pattern>/cgi-bin/*</url-pattern> 
    </servlet-mapping> 

</web-app>' 

回答

1

你映射CGIServlet/cgi-bin/*DispatcherServlet/app/* - 毫無疑問,請求<contextPath>/app/cgi-bin/proxy.cgi由春而不是CGI處理。

嘗試用/pcms/cgi-bin/proxy.cgi代替。

+0

我用這一個'OpenLayers.ProxyHost = 「/pcms/cgi-bin/proxy.cgi?url=」';它會自動映射到'/ pcms/app/cgi-bin/proxy.cgi'。那麼應用程序無法訪問cgi文件 – Alex

+1

@Alex:我看到你使用'UrlRewriteFilter'。您需要爲其配置添加'/ cgi-bin/*'的排除項。 – axtavt

+0

謝謝。我在urlrewrite.xml中添加了排除規則。有用。 – Alex

0

答案是:您不要在Tomcat上安裝或使用cgi代理。

cgi是用於作爲前端服務器的apache服務器或IIS。 Tomcat可能會坐在它後面。 Apache的配置詳述如下:http://tomcat.apache.org/tomcat-6.0-doc/proxy-howto.html

被警告,OpenLayers警告說,它的proxy.cgi只是一個例子,可能沒有足夠的檢查來阻止它被利用,即它可能運行一些惡意腳本。

如果您服務您的OpenLayers客戶端頁面上單獨的Tomcat,它包含其他的GeoServer或Mapserver的層,可以使用代理servlet並將其指定爲:

OpenLayers.ProxyHost =「sevlet服務器上的網址送達此頁面「;

http://wiki.apache.org/tomcat/ServletProxy

https://svn.openxdata.org/Experimental/openXmapper/trunk/gwt-openlayers-server/src/main/java/org/gwtopenmaps/openlayers/server/GwtOpenLayersProxyServlet.java

相關問題