2014-06-25 64 views
1

我正在努力弄清楚問題所在。在春天提供匿名訪問請求映射/控制器

我正在研究一個也有移動應用程序的彈簧web應用程序。移動應用需要與我們的服務器通話以刷新Web客戶端。

我認爲最簡單的方法是使用設置了請求映射的控制器。

移動應用程序擁有自己的身份驗證系統,因此訪問該網址需要打開/匿名。

我已經得到了以下設置:

@Controller 
public class UpdateService 
{ 
    @Autowired 
    private Config _appConfig; 

    @Autowired 
    private SubscriptionsHandler _subscriptionsHandler; 

    @RequestMapping(value = "/events/update") 
    @ResponseBody 
    public String UpdateEventList(String token) throws SQLException 
    { 
     ExternalUpdateHandler updateHandler = new ExternalUpdateHandler(_appConfig, _subscriptionsHandler); 
     updateHandler.MaybeUpdateBasedOn(token); 
     return ""; 
    } 
} 

在我的安全方面,我曾經嘗試都:

<http pattern="/events/update" security="none" /> 

<http auto-config="true" entry-point-ref="authenticationEntryPoint"> 
    <!-- Allow access to the login page by unauthenticated users --> 
    <intercept-url pattern="/login.jsp" access="IS_AUTHENTICATED_ANONYMOUSLY" /> 
    <intercept-url pattern="/events/update" access="IS_AUTHENTICATED_ANONYMOUSLY" /> 

    <intercept-url pattern="/**" access="ROLE_USER" /> 
    .... 
</http> 

如果我嘗試和捲曲它給了我一個404沒有找到。

在日誌中,當服務器運行我得到這個消息:

2014-06-25 17:23:40,693 [RMI TCP Connection(3)-127.0.0.1] INFO org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped "{[/events/update],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String ...UpdateService.UpdateEventList(java.lang.String) throws java.sql.SQLException

這似乎表明,請求映射工作正常。

在關閉該請求的安全性之前,我得到登錄表單作爲對捲曲的響應。所以這似乎表明安全關閉也起作用。

我有點出主意!幫助將不勝感激。乾杯

更新

我用下面捲曲:

curl -i http://localhost:8100/events/update 

調度員-servlet.xml中看起來是這樣的:

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
         http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> 

</beans> 

調度的servlet還引用在這裏:

w eb.xml

<?xml version="1.0" encoding="ISO-8859-1"?> 
<web-app id="compass" 
     xmlns="http://java.sun.com/xml/ns/j2ee" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" 
     version="2.4"> 

    <display-name>compass</display-name> 

    <context-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value>classpath:applicationContext.xml</param-value> 
    </context-param> 

    <servlet> 
     <servlet-name>dispatcher</servlet-name> 
     <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
     <load-on-startup>1</load-on-startup> 
     <async-supported>true</async-supported> 
    </servlet> 

    <servlet-mapping> 
     <servlet-name>dispatcher</servlet-name> 
     <url-pattern>/api/*</url-pattern> 
    </servlet-mapping> 

    <listener> 
     <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
    </listener> 

    <welcome-file-list> 
     <welcome-file>index.jsp</welcome-file> 
    </welcome-file-list> 

    <!-- Spring Security --> 
    <filter> 
     <filter-name>springSecurityFilterChain</filter-name> 
     <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> 
     <async-supported>true</async-supported> 
    </filter> 

    <filter-mapping> 
     <filter-name>springSecurityFilterChain</filter-name> 
     <url-pattern>/*</url-pattern> 
    </filter-mapping> 

    <!-- Default session timeout --> 
    <session-config> 
     <session-timeout>60</session-timeout> 
    </session-config> 

</web-app> 

林相當新的春天,但尚未在web.xml到目前爲止但伸出的東西有勾搭有:

<servlet-mapping> 
     <servlet-name>dispatcher</servlet-name> 
     <url-pattern>/api/*</url-pattern> 
    </servlet-mapping> 

那是什麼說法?

+1

什麼是完整的,你是在使用curl命令?你有可能在一定的路徑下部署你的應用程序嗎?那麼Spring的dispather servlet呢,是映射到'/ *'以外的路徑嗎? – geoand

+0

@geoand我更新了帖子。認爲你正在那裏 –

+1

感謝您的更新!檢查並查看「http:// localhost:8100/api/events/update」是否有效,並讓我知道 – geoand

回答

1

既然您已經在/api/*下部署了Spring Dispatcher Servlet,那麼您的所有Spring控制器URL都將在此之下。因此,在你的測試用例只是做:

http://localhost:8100/api/events/update

+0

謝謝!這是另一個神祕的配置,不那麼神祕! –

+0

@JonnyLeeds很高興它爲你工作! – geoand